proxylang 0.15.0 → 0.16.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/{build-H0uxqVRQ.js → build-Dlv1JO0_.js} +97 -103
- package/dist/cli.js +2 -3
- package/dist/index.d.ts +58 -39
- package/dist/index.js +9 -13
- package/package.json +5 -5
|
@@ -6,7 +6,7 @@ import { randomUUID } from "node:crypto";
|
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
7
|
import { stringify } from "yaml";
|
|
8
8
|
import { lstat, mkdir, readlink, rename, rm, symlink, writeFile } from "node:fs/promises";
|
|
9
|
-
|
|
9
|
+
// src/model/identity.ts
|
|
10
10
|
const kinds = /* @__PURE__ */ new WeakMap();
|
|
11
11
|
const origins = /* @__PURE__ */ new WeakMap();
|
|
12
12
|
function kindOf(value) {
|
|
@@ -34,8 +34,7 @@ function register(value, kind, origin = captureOrigin()) {
|
|
|
34
34
|
if (origin) origins.set(value, origin);
|
|
35
35
|
return Object.freeze(value);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
//#region src/model/definitions.ts
|
|
37
|
+
// src/model/definitions.ts
|
|
39
38
|
function validDiagnosticPath(path) {
|
|
40
39
|
return typeof path === "string" && path.length <= 512 && /^[a-zA-Z][a-zA-Z0-9_.[\]-]*$/.test(path);
|
|
41
40
|
}
|
|
@@ -175,8 +174,7 @@ function exactDefinition(value, keys) {
|
|
|
175
174
|
const unknown = Object.keys(value).filter((key) => !keys.includes(key));
|
|
176
175
|
if (unknown.length) throw new ProfileDefinitionError("UNKNOWN_FIELD", unknown);
|
|
177
176
|
}
|
|
178
|
-
|
|
179
|
-
//#region src/model/tun.ts
|
|
177
|
+
// src/model/tun.ts
|
|
180
178
|
function validTunAddresses(addresses) {
|
|
181
179
|
const families = /* @__PURE__ */ new Set();
|
|
182
180
|
try {
|
|
@@ -208,8 +206,7 @@ function unsafeTunResolvers(model) {
|
|
|
208
206
|
return ["loopback", "unspecified"].includes(address.range()) || networks.some(([network, prefix]) => address.kind() === network.kind() && address.match(network, prefix));
|
|
209
207
|
});
|
|
210
208
|
}
|
|
211
|
-
|
|
212
|
-
//#region src/model/schema.ts
|
|
209
|
+
// src/model/schema.ts
|
|
213
210
|
const idSchema = z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/).refine((x) => !x.startsWith("pl-"));
|
|
214
211
|
const domain$3 = z.string().max(253).regex(/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/);
|
|
215
212
|
const ip$2 = z.string().refine((x) => isIP(x) !== 0 && !x.includes("%"));
|
|
@@ -380,9 +377,16 @@ const nodeSchema = z.discriminatedUnion("type", [
|
|
|
380
377
|
portHopping: portHoppingSchema.optional(),
|
|
381
378
|
portHoppingInterval: z.number().int().positive().optional()
|
|
382
379
|
}).refine((node) => node.portHoppingInterval === void 0 || node.portHopping !== void 0),
|
|
380
|
+
z.strictObject({
|
|
381
|
+
...nodeBase,
|
|
382
|
+
type: z.literal("socks5"),
|
|
383
|
+
password: secretSchema,
|
|
384
|
+
username: secretSchema.optional()
|
|
385
|
+
}),
|
|
383
386
|
z.strictObject({
|
|
384
387
|
...nodeBase,
|
|
385
388
|
type: z.literal("http"),
|
|
389
|
+
surge: z.strictObject({ testUrl: remoteBase.url }).optional(),
|
|
386
390
|
serverName: z.undefined().optional(),
|
|
387
391
|
password: secretSchema,
|
|
388
392
|
username: secretSchema.optional()
|
|
@@ -488,8 +492,7 @@ const engineOptionsSchema = z.strictObject({
|
|
|
488
492
|
routeExcludeAddress: z.array(cidr$1).optional()
|
|
489
493
|
}).refine((t) => !t.strictRoute || t.autoRoute).optional()
|
|
490
494
|
});
|
|
491
|
-
|
|
492
|
-
//#region src/authoring/data.ts
|
|
495
|
+
// src/authoring/data.ts
|
|
493
496
|
function frozen(value) {
|
|
494
497
|
return deepFreeze(snapshotDefinition(value));
|
|
495
498
|
}
|
|
@@ -521,8 +524,7 @@ function inspectRecord(value) {
|
|
|
521
524
|
inspectDefinition(value);
|
|
522
525
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new ProfileDefinitionError("INVALID_FIELD");
|
|
523
526
|
}
|
|
524
|
-
|
|
525
|
-
//#region src/model/names.ts
|
|
527
|
+
// src/model/names.ts
|
|
526
528
|
const nativeNameSchema = z.string().min(1).max(256).refine((value) => value.trim() === value && !/[\p{C}\p{Zl}\p{Zp},=[\]()#;]/u.test(value) && !["DIRECT", "REJECT"].includes(value.toUpperCase()) && !value.toLowerCase().startsWith("pl-"));
|
|
527
529
|
function isReservedNativeName(name, engine) {
|
|
528
530
|
return (engine === "surge" ? [
|
|
@@ -542,8 +544,7 @@ function isReservedNativeName(name, engine) {
|
|
|
542
544
|
"REJECT-DROP"
|
|
543
545
|
] : []).includes(name.toUpperCase());
|
|
544
546
|
}
|
|
545
|
-
|
|
546
|
-
//#region src/model/surge-schema.ts
|
|
547
|
+
// src/model/surge-schema.ts
|
|
547
548
|
const builtin = z.enum([
|
|
548
549
|
"DIRECT",
|
|
549
550
|
"REJECT",
|
|
@@ -676,17 +677,25 @@ const tunnelSchema = z.discriminatedUnion("type", [z.strictObject({
|
|
|
676
677
|
})]);
|
|
677
678
|
const groupSchema = z.strictObject({
|
|
678
679
|
id: idSchema,
|
|
679
|
-
type: z.enum([
|
|
680
|
+
type: z.enum([
|
|
681
|
+
"select",
|
|
682
|
+
"smart",
|
|
683
|
+
"fallback"
|
|
684
|
+
]),
|
|
680
685
|
members: list(policy$2),
|
|
686
|
+
hidden: z.boolean().optional(),
|
|
687
|
+
category: z.string().min(1).regex(/^[^,=\r\n]+$/).optional(),
|
|
681
688
|
url: url.optional(),
|
|
682
689
|
intervalSeconds: z.number().int().positive().max(2147483647).optional(),
|
|
683
690
|
timeoutSeconds: z.number().int().positive().max(3600).optional()
|
|
684
691
|
});
|
|
685
692
|
const groupTestSchema = groupSchema.pick({
|
|
693
|
+
hidden: true,
|
|
694
|
+
category: true,
|
|
686
695
|
url: true,
|
|
687
696
|
intervalSeconds: true,
|
|
688
697
|
timeoutSeconds: true
|
|
689
|
-
}).
|
|
698
|
+
}).refine((g) => g.url !== void 0 || g.intervalSeconds === void 0 && g.timeoutSeconds === void 0);
|
|
690
699
|
const options = { noResolve: z.boolean().optional() };
|
|
691
700
|
const domainOptions = {
|
|
692
701
|
...options,
|
|
@@ -765,8 +774,7 @@ const inputSchema = z.strictObject({
|
|
|
765
774
|
fallback: policy$2,
|
|
766
775
|
names: z.record(idSchema, nativeNameSchema).optional()
|
|
767
776
|
});
|
|
768
|
-
|
|
769
|
-
//#region src/model/dns.ts
|
|
777
|
+
// src/model/dns.ts
|
|
770
778
|
const domain$1 = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
771
779
|
function dohUrl(value) {
|
|
772
780
|
const url = new URL(value);
|
|
@@ -819,8 +827,7 @@ function dnsCondition(rule) {
|
|
|
819
827
|
const pattern = rule.pattern.toLowerCase();
|
|
820
828
|
return pattern.startsWith("*.") ? { domain_regex: [`^.+\\.${pattern.slice(2).replaceAll(".", "\\.")}$`] } : { domain: [pattern] };
|
|
821
829
|
}
|
|
822
|
-
|
|
823
|
-
//#region src/authoring/profile.ts
|
|
830
|
+
// src/authoring/profile.ts
|
|
824
831
|
const fail$2 = (code) => {
|
|
825
832
|
throw new ProfileDefinitionError(code);
|
|
826
833
|
};
|
|
@@ -995,14 +1002,12 @@ function defineProfile(input) {
|
|
|
995
1002
|
...surge === void 0 ? {} : { surge }
|
|
996
1003
|
}, "profile");
|
|
997
1004
|
}
|
|
998
|
-
|
|
999
|
-
//#region src/model/secret-store.ts
|
|
1005
|
+
// src/model/secret-store.ts
|
|
1000
1006
|
const secretSources = /* @__PURE__ */ new WeakMap();
|
|
1001
1007
|
function sourceFor(secrets, ref) {
|
|
1002
1008
|
return secrets ? secretSources.get(secrets)?.get(ref) : void 0;
|
|
1003
1009
|
}
|
|
1004
|
-
|
|
1005
|
-
//#region src/authoring/build.ts
|
|
1010
|
+
// src/authoring/build.ts
|
|
1006
1011
|
function record(value, keys) {
|
|
1007
1012
|
if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
|
|
1008
1013
|
for (const key of Reflect.ownKeys(value)) {
|
|
@@ -1034,8 +1039,7 @@ function defineBuild(input) {
|
|
|
1034
1039
|
throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
|
|
1035
1040
|
}
|
|
1036
1041
|
}
|
|
1037
|
-
|
|
1038
|
-
//#region src/model/routing-model.ts
|
|
1042
|
+
// src/model/routing-model.ts
|
|
1039
1043
|
const exitId = (exit) => "builtin" in exit ? exit.builtin : exit.id;
|
|
1040
1044
|
function normalizeRouting(profile, inspected) {
|
|
1041
1045
|
const sets = /* @__PURE__ */ new Map();
|
|
@@ -1086,8 +1090,7 @@ function normalizeRouting(profile, inspected) {
|
|
|
1086
1090
|
ruleSets: sets
|
|
1087
1091
|
});
|
|
1088
1092
|
}
|
|
1089
|
-
|
|
1090
|
-
//#region src/routing/request.ts
|
|
1093
|
+
// src/routing/request.ts
|
|
1091
1094
|
const domain = z.string().max(253).regex(/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/);
|
|
1092
1095
|
const ip = z.string().refine((v) => isIP(v) !== 0 && !v.includes("%"));
|
|
1093
1096
|
const port = z.number().int().min(1).max(65535);
|
|
@@ -1118,8 +1121,7 @@ function parseRequest(input) {
|
|
|
1118
1121
|
network: parsed.data.network ?? "tcp"
|
|
1119
1122
|
});
|
|
1120
1123
|
}
|
|
1121
|
-
|
|
1122
|
-
//#region src/routing/assumptions.ts
|
|
1124
|
+
// src/routing/assumptions.ts
|
|
1123
1125
|
function prepareAssumptions(model, input = {}) {
|
|
1124
1126
|
const values = /* @__PURE__ */ new Map();
|
|
1125
1127
|
const errors = [];
|
|
@@ -1174,8 +1176,7 @@ function prepareAssumptions(model, input = {}) {
|
|
|
1174
1176
|
errors
|
|
1175
1177
|
};
|
|
1176
1178
|
}
|
|
1177
|
-
|
|
1178
|
-
//#region src/routing/evaluate.ts
|
|
1179
|
+
// src/routing/evaluate.ts
|
|
1179
1180
|
const yes = { matched: true };
|
|
1180
1181
|
const no = { matched: false };
|
|
1181
1182
|
const unknown = (needs) => ({
|
|
@@ -1262,8 +1263,7 @@ function evaluate(model, request, assumptions) {
|
|
|
1262
1263
|
trace
|
|
1263
1264
|
};
|
|
1264
1265
|
}
|
|
1265
|
-
|
|
1266
|
-
//#region src/build/cases.ts
|
|
1266
|
+
// src/build/cases.ts
|
|
1267
1267
|
function checkCases(profile, key, prepared, valid) {
|
|
1268
1268
|
const diagnostics = [];
|
|
1269
1269
|
const cases = [];
|
|
@@ -1324,8 +1324,7 @@ function checkCases(profile, key, prepared, valid) {
|
|
|
1324
1324
|
cases
|
|
1325
1325
|
};
|
|
1326
1326
|
}
|
|
1327
|
-
|
|
1328
|
-
//#region src/model/diagnostic-view.ts
|
|
1327
|
+
// src/model/diagnostic-view.ts
|
|
1329
1328
|
function diagnosticView(profile, inspected) {
|
|
1330
1329
|
const diagnosticSecret = register({
|
|
1331
1330
|
type: "env",
|
|
@@ -1344,13 +1343,13 @@ function diagnosticView(profile, inspected) {
|
|
|
1344
1343
|
return resource;
|
|
1345
1344
|
});
|
|
1346
1345
|
const groups = profile.groups.map((resource) => {
|
|
1347
|
-
const algorithm = (surge ? resource.algorithm.type === "urltest" : resource.algorithm.type
|
|
1346
|
+
const algorithm = (surge ? resource.algorithm.type === "urltest" : ["surge-smart", "surge-fallback"].includes(resource.algorithm.type) || profile.target.engine === "stash" && resource.algorithm.type !== "select") ? { type: "select" } : resource.algorithm;
|
|
1348
1347
|
const { surge: options, ...rest } = resource;
|
|
1349
1348
|
return {
|
|
1350
1349
|
...rest,
|
|
1351
1350
|
algorithm,
|
|
1352
1351
|
members: resource.members.map(destination),
|
|
1353
|
-
...surge &&
|
|
1352
|
+
...surge && options ? { surge: options } : {}
|
|
1354
1353
|
};
|
|
1355
1354
|
});
|
|
1356
1355
|
const stripName = (resource) => {
|
|
@@ -1368,13 +1367,11 @@ function diagnosticView(profile, inspected) {
|
|
|
1368
1367
|
fallback: destination(profile.fallback)
|
|
1369
1368
|
};
|
|
1370
1369
|
}
|
|
1371
|
-
|
|
1372
|
-
//#region src/model/protocols.ts
|
|
1370
|
+
// src/model/protocols.ts
|
|
1373
1371
|
function nodeIsTcpOnly(node, engine) {
|
|
1374
1372
|
return node.type === "http" || node.type === "anytls" && engine !== "surge" && engine !== "sing-box" || node.type === "vmess" || node.type === "vless" && !(engine === "sing-box" && node.packetEncoding) || engine === "surge" && node.type === "shadowsocks" && node.surge?.udpRelay === false;
|
|
1375
1373
|
}
|
|
1376
|
-
|
|
1377
|
-
//#region src/model/network.ts
|
|
1374
|
+
// src/model/network.ts
|
|
1378
1375
|
function truthPossibilities(condition, network) {
|
|
1379
1376
|
switch (condition.type) {
|
|
1380
1377
|
case "network": return [condition.value === network];
|
|
@@ -1390,8 +1387,7 @@ function truthPossibilities(condition, network) {
|
|
|
1390
1387
|
default: return [false, true];
|
|
1391
1388
|
}
|
|
1392
1389
|
}
|
|
1393
|
-
|
|
1394
|
-
//#region src/model/inspect-profile.ts
|
|
1390
|
+
// src/model/inspect-profile.ts
|
|
1395
1391
|
function inspectProfile(profile, key, secrets, checkSecrets = true) {
|
|
1396
1392
|
const diagnostics = [];
|
|
1397
1393
|
const selections = [];
|
|
@@ -1437,8 +1433,12 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
|
|
|
1437
1433
|
const path = resource.type === "proxy-group" ? `groups.${resource.id}` : `proxies.${resource.id}`;
|
|
1438
1434
|
if (kindOf(resource) === "tunnel" && profile.target.engine !== "surge" || kindOf(resource) === "endpoint" && profile.target.engine !== "sing-box") error("TUNNEL_UNSUPPORTED", path, resource);
|
|
1439
1435
|
if (resource.type === "proxy-group") {
|
|
1440
|
-
if (resource.surge !== void 0 && (profile.target.engine !== "surge" ||
|
|
1441
|
-
|
|
1436
|
+
if (resource.surge !== void 0 && (profile.target.engine !== "surge" || ![
|
|
1437
|
+
"select",
|
|
1438
|
+
"surge-smart",
|
|
1439
|
+
"surge-fallback"
|
|
1440
|
+
].includes(resource.algorithm.type))) error("GROUP_OPTION_UNSUPPORTED", path + ".surge", resource);
|
|
1441
|
+
if (["surge-smart", "surge-fallback"].includes(resource.algorithm.type) && profile.target.engine !== "surge") error("ALGORITHM_ENGINE_MISMATCH", path + ".algorithm", resource);
|
|
1442
1442
|
else if (resource.algorithm.type === "auto" && profile.target.engine === "stash" || resource.algorithm.type === "urltest" && ["surge", "stash"].includes(profile.target.engine)) error("GROUP_ALGORITHM_UNSUPPORTED", path + ".algorithm", resource);
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
@@ -1665,8 +1665,7 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
|
|
|
1665
1665
|
mapped
|
|
1666
1666
|
};
|
|
1667
1667
|
}
|
|
1668
|
-
|
|
1669
|
-
//#region src/model/normalize.ts
|
|
1668
|
+
// src/model/normalize.ts
|
|
1670
1669
|
const fail$1 = (code) => {
|
|
1671
1670
|
throw new ProfileDefinitionError(code);
|
|
1672
1671
|
};
|
|
@@ -1785,8 +1784,7 @@ function normalizeProfile(profile) {
|
|
|
1785
1784
|
...extension
|
|
1786
1785
|
}));
|
|
1787
1786
|
}
|
|
1788
|
-
|
|
1789
|
-
//#region src/model/errors.ts
|
|
1787
|
+
// src/model/errors.ts
|
|
1790
1788
|
var RenderError = class extends Error {
|
|
1791
1789
|
code;
|
|
1792
1790
|
constructor(code) {
|
|
@@ -1795,8 +1793,7 @@ var RenderError = class extends Error {
|
|
|
1795
1793
|
this.name = "RenderError";
|
|
1796
1794
|
}
|
|
1797
1795
|
};
|
|
1798
|
-
|
|
1799
|
-
//#region src/model/proxy-values.ts
|
|
1796
|
+
// src/model/proxy-values.ts
|
|
1800
1797
|
function uuid(token, secret) {
|
|
1801
1798
|
const value = secret(token);
|
|
1802
1799
|
if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(value)) throw new RenderError("INVALID_UUID_SECRET");
|
|
@@ -1815,8 +1812,7 @@ function aliasProxyServer(node, aliases) {
|
|
|
1815
1812
|
server
|
|
1816
1813
|
};
|
|
1817
1814
|
}
|
|
1818
|
-
|
|
1819
|
-
//#region src/engines/surge/proxies.ts
|
|
1815
|
+
// src/engines/surge/proxies.ts
|
|
1820
1816
|
function surgeProxy(node, secret, name = (id) => id) {
|
|
1821
1817
|
const atom = (value) => {
|
|
1822
1818
|
if (!/^[A-Za-z0-9_./:@+%-]+$/.test(value)) throw new RenderError("SURGE_VALUE_UNREPRESENTABLE");
|
|
@@ -1828,9 +1824,11 @@ function surgeProxy(node, secret, name = (id) => id) {
|
|
|
1828
1824
|
String(node.port)
|
|
1829
1825
|
];
|
|
1830
1826
|
switch (node.type) {
|
|
1827
|
+
case "socks5":
|
|
1831
1828
|
case "http":
|
|
1832
1829
|
if (node.username) params.push(`username=${atom(secret(node.username))}`);
|
|
1833
1830
|
params.push(`password=${atom(secret(node.password))}`);
|
|
1831
|
+
if (node.type === "http" && node.surge?.testUrl) params.push(`test-url=${node.surge.testUrl}`);
|
|
1834
1832
|
break;
|
|
1835
1833
|
case "hysteria2":
|
|
1836
1834
|
params.push(`password=${atom(secret(node.password))}`);
|
|
@@ -1862,12 +1860,11 @@ function surgeProxy(node, secret, name = (id) => id) {
|
|
|
1862
1860
|
if (node.tcpFastOpen !== void 0) params.push(`tfo=${node.tcpFastOpen}`);
|
|
1863
1861
|
if (node.type === "trojan" || node.type === "anytls" && node.surge?.udpRelay) params.push("udp-relay=true");
|
|
1864
1862
|
if (node.type === "shadowsocks") params.push(`udp-relay=${node.surge?.udpRelay ?? true}`, `block-quic=${node.surge?.blockQuic ?? "off"}`);
|
|
1865
|
-
if (node.type !== "shadowsocks" && "surge" in node && node.surge?.blockQuic !== void 0) params.push(`block-quic=${node.surge.blockQuic}`);
|
|
1863
|
+
if (node.type !== "shadowsocks" && node.type !== "http" && "surge" in node && node.surge?.blockQuic !== void 0) params.push(`block-quic=${node.surge.blockQuic}`);
|
|
1866
1864
|
if (node.via) params.push(`underlying-proxy=${name(node.via)}`);
|
|
1867
1865
|
return params.join(", ");
|
|
1868
1866
|
}
|
|
1869
|
-
|
|
1870
|
-
//#region src/targets/proxies.ts
|
|
1867
|
+
// src/targets/proxies.ts
|
|
1871
1868
|
function validateProxyOptions(node, target, diagnostics) {
|
|
1872
1869
|
if (node.type === "hysteria2") {
|
|
1873
1870
|
if (target.engine === "surge" && node.portHopping && node.via) diagnostics.push({
|
|
@@ -1912,8 +1909,7 @@ function validateProxyOptions(node, target, diagnostics) {
|
|
|
1912
1909
|
message: "Surge 编码不接受特殊 SNI off 或显式 ALPN;不会丢弃 TLS 选项"
|
|
1913
1910
|
});
|
|
1914
1911
|
}
|
|
1915
|
-
|
|
1916
|
-
//#region src/engines/surge/profile.ts
|
|
1912
|
+
// src/engines/surge/profile.ts
|
|
1917
1913
|
const plans = /* @__PURE__ */ new WeakMap();
|
|
1918
1914
|
function compileSurgeProfile(input) {
|
|
1919
1915
|
const diagnostics = [];
|
|
@@ -2137,6 +2133,8 @@ function renderProfile(compilation, read) {
|
|
|
2137
2133
|
for (const g of p.groups) lines.push(`${name(g.id)} = ${[
|
|
2138
2134
|
g.type,
|
|
2139
2135
|
...g.members.map(action),
|
|
2136
|
+
...g.hidden !== void 0 ? [`hidden=${g.hidden}`] : [],
|
|
2137
|
+
...g.category ? [`category=${g.category}`] : [],
|
|
2140
2138
|
...g.url ? [`url=${g.url}`] : [],
|
|
2141
2139
|
...g.intervalSeconds !== void 0 ? [`interval=${g.intervalSeconds}`] : [],
|
|
2142
2140
|
...g.timeoutSeconds !== void 0 ? [`timeout=${g.timeoutSeconds}`] : []
|
|
@@ -2158,8 +2156,7 @@ function renderSurgeProfiles(compilations, resolveSecret) {
|
|
|
2158
2156
|
const read = resolveSecret;
|
|
2159
2157
|
return deepFreeze(compilations.map((c) => renderProfile(c, read)));
|
|
2160
2158
|
}
|
|
2161
|
-
|
|
2162
|
-
//#region src/model/normalize-surge.ts
|
|
2159
|
+
// src/model/normalize-surge.ts
|
|
2163
2160
|
const outbound = {
|
|
2164
2161
|
direct: { builtin: "DIRECT" },
|
|
2165
2162
|
reject: { builtin: "REJECT" },
|
|
@@ -2225,6 +2222,7 @@ function lowerSurgeProfile(input) {
|
|
|
2225
2222
|
if (!definition.algorithm || ![
|
|
2226
2223
|
"select",
|
|
2227
2224
|
"surge-smart",
|
|
2225
|
+
"surge-fallback",
|
|
2228
2226
|
"auto"
|
|
2229
2227
|
].includes(definition.algorithm.type)) fail("UNSUPPORTED_GROUP_ALGORITHM");
|
|
2230
2228
|
exactDefinition(definition.algorithm, ["type"]);
|
|
@@ -2232,7 +2230,7 @@ function lowerSurgeProfile(input) {
|
|
|
2232
2230
|
const { id } = definition;
|
|
2233
2231
|
return {
|
|
2234
2232
|
id,
|
|
2235
|
-
type: definition.algorithm.type === "select" ? "select" : "smart",
|
|
2233
|
+
type: definition.algorithm.type === "surge-fallback" ? "fallback" : definition.algorithm.type === "select" ? "select" : "smart",
|
|
2236
2234
|
members: definition.members.map(lower),
|
|
2237
2235
|
...definition.surge
|
|
2238
2236
|
};
|
|
@@ -2325,15 +2323,13 @@ function normalizeSurgeProfile(p) {
|
|
|
2325
2323
|
fallback: p.fallback
|
|
2326
2324
|
});
|
|
2327
2325
|
}
|
|
2328
|
-
|
|
2329
|
-
//#region src/model/semantics.ts
|
|
2326
|
+
// src/model/semantics.ts
|
|
2330
2327
|
const singboxMemberTag = (id) => id === "DIRECT" ? "pl-direct" : id === "REJECT" ? "pl-reject" : id;
|
|
2331
2328
|
/** Only top-level atoms (or transparent named wrappers) can request ordered DNS. */
|
|
2332
2329
|
function needsResolve(condition) {
|
|
2333
2330
|
return condition.type === "ipCidr" && condition.noResolve !== true || condition.type === "nativeRuleSet" && condition.engine === "sing-box" && condition.resolve === true;
|
|
2334
2331
|
}
|
|
2335
|
-
|
|
2336
|
-
//#region src/engines/sing-box/groups.ts
|
|
2332
|
+
// src/engines/sing-box/groups.ts
|
|
2337
2333
|
function singboxGroup(group, name = (id) => id) {
|
|
2338
2334
|
if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
|
|
2339
2335
|
return group.type === "select" ? {
|
|
@@ -2353,11 +2349,10 @@ function singboxGroup(group, name = (id) => id) {
|
|
|
2353
2349
|
interrupt_exist_connections: false
|
|
2354
2350
|
};
|
|
2355
2351
|
}
|
|
2356
|
-
|
|
2357
|
-
//#region src/engines/sing-box/proxies.ts
|
|
2352
|
+
// src/engines/sing-box/proxies.ts
|
|
2358
2353
|
function singboxProxy(node, secret) {
|
|
2359
2354
|
const result = {
|
|
2360
|
-
type: node.type,
|
|
2355
|
+
type: node.type === "socks5" ? "socks" : node.type,
|
|
2361
2356
|
tag: node.id,
|
|
2362
2357
|
server: node.server,
|
|
2363
2358
|
server_port: node.port,
|
|
@@ -2378,6 +2373,7 @@ function singboxProxy(node, secret) {
|
|
|
2378
2373
|
}
|
|
2379
2374
|
if (node.portHoppingInterval !== void 0) result.hop_interval = `${node.portHoppingInterval}s`;
|
|
2380
2375
|
break;
|
|
2376
|
+
case "socks5":
|
|
2381
2377
|
case "http":
|
|
2382
2378
|
result.password = secret(node.password);
|
|
2383
2379
|
if (node.username) result.username = secret(node.username);
|
|
@@ -2433,8 +2429,7 @@ function singboxProxy(node, secret) {
|
|
|
2433
2429
|
}
|
|
2434
2430
|
return result;
|
|
2435
2431
|
}
|
|
2436
|
-
|
|
2437
|
-
//#region src/engines/sing-box/render.ts
|
|
2432
|
+
// src/engines/sing-box/render.ts
|
|
2438
2433
|
const DIRECT = "pl-direct";
|
|
2439
2434
|
const DNS = "pl-dns";
|
|
2440
2435
|
const actionTag = (a, name) => a.type === "route" ? name(a.to) : a.type === "direct" ? DIRECT : "pl-reject";
|
|
@@ -2665,8 +2660,7 @@ function singbox(plan, secret) {
|
|
|
2665
2660
|
}
|
|
2666
2661
|
return config;
|
|
2667
2662
|
}
|
|
2668
|
-
|
|
2669
|
-
//#region src/engines/mihomo/proxies.ts
|
|
2663
|
+
// src/engines/mihomo/proxies.ts
|
|
2670
2664
|
function clashProxy$1(node, secret, name = (id) => id) {
|
|
2671
2665
|
const result = {
|
|
2672
2666
|
name: name(node.id),
|
|
@@ -2683,6 +2677,7 @@ function clashProxy$1(node, secret, name = (id) => id) {
|
|
|
2683
2677
|
if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
|
|
2684
2678
|
if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
|
|
2685
2679
|
break;
|
|
2680
|
+
case "socks5":
|
|
2686
2681
|
case "http":
|
|
2687
2682
|
result.password = secret(node.password);
|
|
2688
2683
|
if (node.username) result.username = secret(node.username);
|
|
@@ -2721,8 +2716,7 @@ function clashProxy$1(node, secret, name = (id) => id) {
|
|
|
2721
2716
|
}
|
|
2722
2717
|
return result;
|
|
2723
2718
|
}
|
|
2724
|
-
|
|
2725
|
-
//#region src/engines/mihomo/render.ts
|
|
2719
|
+
// src/engines/mihomo/render.ts
|
|
2726
2720
|
function clashGroup$1(group, name = (id) => id) {
|
|
2727
2721
|
if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
|
|
2728
2722
|
return {
|
|
@@ -2794,8 +2788,7 @@ function clashConfig$1(plan, secret) {
|
|
|
2794
2788
|
}
|
|
2795
2789
|
return config;
|
|
2796
2790
|
}
|
|
2797
|
-
|
|
2798
|
-
//#region src/engines/stash/proxies.ts
|
|
2791
|
+
// src/engines/stash/proxies.ts
|
|
2799
2792
|
function clashProxy(node, secret, name = (id) => id) {
|
|
2800
2793
|
const result = {
|
|
2801
2794
|
name: name(node.id),
|
|
@@ -2813,6 +2806,7 @@ function clashProxy(node, secret, name = (id) => id) {
|
|
|
2813
2806
|
if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
|
|
2814
2807
|
if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
|
|
2815
2808
|
break;
|
|
2809
|
+
case "socks5":
|
|
2816
2810
|
case "http":
|
|
2817
2811
|
result.password = secret(node.password);
|
|
2818
2812
|
if (node.username) result.username = secret(node.username);
|
|
@@ -2851,8 +2845,7 @@ function clashProxy(node, secret, name = (id) => id) {
|
|
|
2851
2845
|
}
|
|
2852
2846
|
return result;
|
|
2853
2847
|
}
|
|
2854
|
-
|
|
2855
|
-
//#region src/engines/stash/render.ts
|
|
2848
|
+
// src/engines/stash/render.ts
|
|
2856
2849
|
function clashGroup(group, name = (id) => id) {
|
|
2857
2850
|
if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
|
|
2858
2851
|
return {
|
|
@@ -2924,8 +2917,7 @@ function clashConfig(plan, secret) {
|
|
|
2924
2917
|
}
|
|
2925
2918
|
return config;
|
|
2926
2919
|
}
|
|
2927
|
-
|
|
2928
|
-
//#region src/engines/sing-box/check.ts
|
|
2920
|
+
// src/engines/sing-box/check.ts
|
|
2929
2921
|
function engineChecks$2(model) {
|
|
2930
2922
|
const t = model.target;
|
|
2931
2923
|
return {
|
|
@@ -2948,8 +2940,7 @@ function engineChecks$2(model) {
|
|
|
2948
2940
|
}
|
|
2949
2941
|
};
|
|
2950
2942
|
}
|
|
2951
|
-
|
|
2952
|
-
//#region src/engines/mihomo/check.ts
|
|
2943
|
+
// src/engines/mihomo/check.ts
|
|
2953
2944
|
function engineChecks$1(model) {
|
|
2954
2945
|
const t = model.target;
|
|
2955
2946
|
return {
|
|
@@ -2970,8 +2961,7 @@ function engineChecks$1(model) {
|
|
|
2970
2961
|
}
|
|
2971
2962
|
};
|
|
2972
2963
|
}
|
|
2973
|
-
|
|
2974
|
-
//#region src/engines/stash/check.ts
|
|
2964
|
+
// src/engines/stash/check.ts
|
|
2975
2965
|
function engineChecks(model) {
|
|
2976
2966
|
const t = model.target;
|
|
2977
2967
|
return {
|
|
@@ -2994,8 +2984,7 @@ function engineChecks(model) {
|
|
|
2994
2984
|
}
|
|
2995
2985
|
};
|
|
2996
2986
|
}
|
|
2997
|
-
|
|
2998
|
-
//#region src/targets/catalog.ts
|
|
2987
|
+
// src/targets/catalog.ts
|
|
2999
2988
|
const targetCatalog = deepFreeze([
|
|
3000
2989
|
{
|
|
3001
2990
|
engine: "sing-box",
|
|
@@ -3006,6 +2995,7 @@ const targetCatalog = deepFreeze([
|
|
|
3006
2995
|
"hysteria2",
|
|
3007
2996
|
"trojan",
|
|
3008
2997
|
"http",
|
|
2998
|
+
"socks5",
|
|
3009
2999
|
"anytls",
|
|
3010
3000
|
"shadowsocks",
|
|
3011
3001
|
"vmess",
|
|
@@ -3025,12 +3015,17 @@ const targetCatalog = deepFreeze([
|
|
|
3025
3015
|
"hysteria2",
|
|
3026
3016
|
"trojan",
|
|
3027
3017
|
"http",
|
|
3018
|
+
"socks5",
|
|
3028
3019
|
"anytls",
|
|
3029
3020
|
"shadowsocks",
|
|
3030
3021
|
"vmess"
|
|
3031
3022
|
],
|
|
3032
3023
|
endpoints: [],
|
|
3033
|
-
groups: [
|
|
3024
|
+
groups: [
|
|
3025
|
+
"select",
|
|
3026
|
+
"surge-smart",
|
|
3027
|
+
"surge-fallback"
|
|
3028
|
+
],
|
|
3034
3029
|
nativeRuleSets: ["rule-set", "domain-set"],
|
|
3035
3030
|
dns: "general"
|
|
3036
3031
|
},
|
|
@@ -3043,12 +3038,17 @@ const targetCatalog = deepFreeze([
|
|
|
3043
3038
|
"hysteria2",
|
|
3044
3039
|
"trojan",
|
|
3045
3040
|
"http",
|
|
3041
|
+
"socks5",
|
|
3046
3042
|
"anytls",
|
|
3047
3043
|
"shadowsocks",
|
|
3048
3044
|
"vmess"
|
|
3049
3045
|
],
|
|
3050
3046
|
endpoints: [],
|
|
3051
|
-
groups: [
|
|
3047
|
+
groups: [
|
|
3048
|
+
"select",
|
|
3049
|
+
"surge-smart",
|
|
3050
|
+
"surge-fallback"
|
|
3051
|
+
],
|
|
3052
3052
|
nativeRuleSets: ["rule-set", "domain-set"],
|
|
3053
3053
|
dns: "general"
|
|
3054
3054
|
},
|
|
@@ -3061,6 +3061,7 @@ const targetCatalog = deepFreeze([
|
|
|
3061
3061
|
"hysteria2",
|
|
3062
3062
|
"trojan",
|
|
3063
3063
|
"http",
|
|
3064
|
+
"socks5",
|
|
3064
3065
|
"anytls",
|
|
3065
3066
|
"shadowsocks",
|
|
3066
3067
|
"vmess",
|
|
@@ -3080,6 +3081,7 @@ const targetCatalog = deepFreeze([
|
|
|
3080
3081
|
"hysteria2",
|
|
3081
3082
|
"trojan",
|
|
3082
3083
|
"http",
|
|
3084
|
+
"socks5",
|
|
3083
3085
|
"anytls",
|
|
3084
3086
|
"shadowsocks",
|
|
3085
3087
|
"vmess",
|
|
@@ -3091,14 +3093,12 @@ const targetCatalog = deepFreeze([
|
|
|
3091
3093
|
dns: "external"
|
|
3092
3094
|
}
|
|
3093
3095
|
]);
|
|
3094
|
-
|
|
3095
|
-
//#region src/model/paths.ts
|
|
3096
|
+
// src/model/paths.ts
|
|
3096
3097
|
function pathsOverlap(a, b) {
|
|
3097
3098
|
if (a.startsWith("/") !== b.startsWith("/")) return false;
|
|
3098
3099
|
return a === b || a.startsWith(b.endsWith("/") ? b : `${b}/`) || b.startsWith(a.endsWith("/") ? a : `${a}/`);
|
|
3099
3100
|
}
|
|
3100
|
-
|
|
3101
|
-
//#region src/targets/check.ts
|
|
3101
|
+
// src/targets/check.ts
|
|
3102
3102
|
function checkTarget(model, checks) {
|
|
3103
3103
|
const diagnostics = [];
|
|
3104
3104
|
const error = (code, path) => diagnostics.push({
|
|
@@ -3200,8 +3200,7 @@ function checkTarget(model, checks) {
|
|
|
3200
3200
|
}
|
|
3201
3201
|
};
|
|
3202
3202
|
}
|
|
3203
|
-
|
|
3204
|
-
//#region src/build/plans.ts
|
|
3203
|
+
// src/build/plans.ts
|
|
3205
3204
|
function prepareProfile(input, key, secrets, checkSecrets = true) {
|
|
3206
3205
|
let engine = "surge";
|
|
3207
3206
|
const collected = [];
|
|
@@ -3343,8 +3342,7 @@ function diagnosticOrigin(p, path) {
|
|
|
3343
3342
|
if (resource) return originOf([...p.proxies, ...p.groups].find((r) => r.id === resource[1])) ?? originOf(p);
|
|
3344
3343
|
return originOf(p);
|
|
3345
3344
|
}
|
|
3346
|
-
|
|
3347
|
-
//#region src/build/secrets.ts
|
|
3345
|
+
// src/build/secrets.ts
|
|
3348
3346
|
const failures = /* @__PURE__ */ new WeakMap();
|
|
3349
3347
|
function secretFailure(error) {
|
|
3350
3348
|
return error && typeof error === "object" ? failures.get(error) ?? {} : {};
|
|
@@ -3371,8 +3369,7 @@ function secretReader(secrets, validation) {
|
|
|
3371
3369
|
return value;
|
|
3372
3370
|
};
|
|
3373
3371
|
}
|
|
3374
|
-
|
|
3375
|
-
//#region src/build/publish.ts
|
|
3372
|
+
// src/build/publish.ts
|
|
3376
3373
|
var SurgePublishError = class extends Error {
|
|
3377
3374
|
published;
|
|
3378
3375
|
constructor(message, published) {
|
|
@@ -3467,8 +3464,7 @@ async function publishProfiles(files, surgeDirectory, io = { rename }) {
|
|
|
3467
3464
|
}
|
|
3468
3465
|
if (failure) throw new SurgePublishError(failure.message === "PROFILE_PUBLISH_CLEANUP_FAILED" ? committed ? "PUBLISHED_CLEANUP_FAILED" : "FAILED_CLEANUP_REQUIRED" : failure.message, committed);
|
|
3469
3466
|
}
|
|
3470
|
-
|
|
3471
|
-
//#region src/build/explain.ts
|
|
3467
|
+
// src/build/explain.ts
|
|
3472
3468
|
function explainProfile(profile, request, assume) {
|
|
3473
3469
|
if (kindOf(profile) !== "profile") return {
|
|
3474
3470
|
ok: false,
|
|
@@ -3506,8 +3502,7 @@ function explainProfile(profile, request, assume) {
|
|
|
3506
3502
|
explanation: evaluate(prepared.routing, parsed, assumptions.values)
|
|
3507
3503
|
};
|
|
3508
3504
|
}
|
|
3509
|
-
|
|
3510
|
-
//#region src/build/index.ts
|
|
3505
|
+
// src/build/index.ts
|
|
3511
3506
|
function compile(definition) {
|
|
3512
3507
|
if (kindOf(definition) !== "build") throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
|
|
3513
3508
|
const entries = Object.entries(definition.profiles);
|
|
@@ -3628,5 +3623,4 @@ async function runBuild(definition, options = {}) {
|
|
|
3628
3623
|
};
|
|
3629
3624
|
}
|
|
3630
3625
|
}
|
|
3631
|
-
//#endregion
|
|
3632
3626
|
export { definitionDiagnostic as C, ProfileDefinitionError as S, inspectDefinition as T, endpointSchema as _, defineBuild as a, nativeRuleSetSchema as b, dnsRulesSchema as c, tunnelSchema as d, created as f, requireKind as g, parsed as h, targetCatalog as i, conditionSchema as l, inspectRecord as m, runBuild as n, secretSources as o, flatten as p, explainProfile as r, defineProfile as s, checkBuild as t, groupTestSchema as u, idSchema as v, exactDefinition as w, nodeSchema as x, matchSchema as y };
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as definitionDiagnostic, i as targetCatalog } from "./build-
|
|
2
|
+
import { C as definitionDiagnostic, i as targetCatalog } from "./build-Dlv1JO0_.js";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { lstat, open, stat } from "node:fs/promises";
|
|
6
6
|
import { constants } from "node:fs";
|
|
7
7
|
import { register } from "tsx/esm/api";
|
|
8
8
|
import { register as register$1 } from "tsx/cjs/api";
|
|
9
|
-
|
|
9
|
+
// src/cli.ts
|
|
10
10
|
let json = false;
|
|
11
11
|
function print(value, text) {
|
|
12
12
|
process.stdout.write(json ? JSON.stringify(value, null, 2) + "\n" : (text ?? human(value)) + "\n");
|
|
@@ -268,5 +268,4 @@ try {
|
|
|
268
268
|
} catch {
|
|
269
269
|
process.exitCode = failure("UNEXPECTED_FAILURE");
|
|
270
270
|
}
|
|
271
|
-
//#endregion
|
|
272
271
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
//#region src/model/identity.d.ts
|
|
3
2
|
type Origin = {
|
|
4
3
|
readonly file: string;
|
|
5
4
|
readonly line: number;
|
|
@@ -9,8 +8,6 @@ declare const sdkIdentity: unique symbol;
|
|
|
9
8
|
type SDK<K extends string> = {
|
|
10
9
|
readonly [sdkIdentity]: K;
|
|
11
10
|
};
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/model/types.d.ts
|
|
14
11
|
type Network = "tcp" | "udp";
|
|
15
12
|
type NativeRuleSet = {
|
|
16
13
|
readonly type: "nativeRuleSet";
|
|
@@ -109,8 +106,17 @@ type Hysteria2Node$1 = Omit<ProxyBase, "tcpFastOpen"> & {
|
|
|
109
106
|
readonly portHopping?: string;
|
|
110
107
|
readonly portHoppingInterval?: number;
|
|
111
108
|
};
|
|
109
|
+
type Socks5Node$1 = ProxyBase & {
|
|
110
|
+
readonly type: "socks5";
|
|
111
|
+
readonly password: Secret;
|
|
112
|
+
readonly username?: Secret;
|
|
113
|
+
readonly serverName?: never;
|
|
114
|
+
};
|
|
112
115
|
type HttpNode$1 = ProxyBase & {
|
|
113
116
|
readonly type: "http";
|
|
117
|
+
readonly surge?: {
|
|
118
|
+
readonly testUrl: string;
|
|
119
|
+
};
|
|
114
120
|
readonly serverName?: never;
|
|
115
121
|
readonly password: Secret;
|
|
116
122
|
readonly username?: Secret;
|
|
@@ -141,7 +147,7 @@ type VLESSNode$1 = ProxyBase & {
|
|
|
141
147
|
};
|
|
142
148
|
readonly utlsFingerprint?: "chrome";
|
|
143
149
|
};
|
|
144
|
-
type ProxyNode$1 = TrojanNode$1 | AnyTLSNode$1 | Hysteria2Node$1 | HttpNode$1 | ShadowsocksNode$1 | VMessNode$1 | VLESSNode$1;
|
|
150
|
+
type ProxyNode$1 = TrojanNode$1 | AnyTLSNode$1 | Hysteria2Node$1 | Socks5Node$1 | HttpNode$1 | ShadowsocksNode$1 | VMessNode$1 | VLESSNode$1;
|
|
145
151
|
type TailscaleEndpoint = {
|
|
146
152
|
readonly type: "sing-box-tailscale";
|
|
147
153
|
readonly id: string;
|
|
@@ -157,6 +163,8 @@ type GroupAlgorithm = {
|
|
|
157
163
|
readonly type: "auto";
|
|
158
164
|
} | {
|
|
159
165
|
readonly type: "select";
|
|
166
|
+
} | {
|
|
167
|
+
readonly type: "surge-fallback";
|
|
160
168
|
} | {
|
|
161
169
|
readonly type: "surge-smart";
|
|
162
170
|
} | {
|
|
@@ -193,8 +201,6 @@ type Diagnostic = {
|
|
|
193
201
|
type ProfileDiagnostic = Omit<Diagnostic, "target" | "profile"> & {
|
|
194
202
|
readonly profile: string;
|
|
195
203
|
};
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region src/model/routing-types.d.ts
|
|
198
204
|
type RouteRequest = {
|
|
199
205
|
readonly network?: "tcp" | "udp";
|
|
200
206
|
readonly domain?: string;
|
|
@@ -257,8 +263,6 @@ type CaseResult = {
|
|
|
257
263
|
readonly needs?: Need;
|
|
258
264
|
readonly route?: Explanation["route"];
|
|
259
265
|
};
|
|
260
|
-
//#endregion
|
|
261
|
-
//#region src/model/surge-schema.d.ts
|
|
262
266
|
declare const policy: z.ZodUnion<readonly [z.ZodObject<{
|
|
263
267
|
ref: z.ZodString;
|
|
264
268
|
}, z.core.$strict>, z.ZodObject<{
|
|
@@ -352,6 +356,7 @@ type SurgeTunnel$1 = z.infer<typeof tunnelSchema>;
|
|
|
352
356
|
declare const groupSchema: z.ZodObject<{
|
|
353
357
|
id: z.ZodString;
|
|
354
358
|
type: z.ZodEnum<{
|
|
359
|
+
fallback: "fallback";
|
|
355
360
|
select: "select";
|
|
356
361
|
smart: "smart";
|
|
357
362
|
}>;
|
|
@@ -366,6 +371,8 @@ declare const groupSchema: z.ZodObject<{
|
|
|
366
371
|
"REJECT-TINYGIF": "REJECT-TINYGIF";
|
|
367
372
|
}>;
|
|
368
373
|
}, z.core.$strict>]>>;
|
|
374
|
+
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
375
|
+
category: z.ZodOptional<z.ZodString>;
|
|
369
376
|
url: z.ZodOptional<z.ZodString>;
|
|
370
377
|
intervalSeconds: z.ZodOptional<z.ZodNumber>;
|
|
371
378
|
timeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
@@ -433,8 +440,6 @@ type SurgeProfileInput = {
|
|
|
433
440
|
readonly fallback: SurgePolicy;
|
|
434
441
|
readonly names?: Readonly<Record<string, string>>;
|
|
435
442
|
};
|
|
436
|
-
//#endregion
|
|
437
|
-
//#region src/model/profile-types.d.ts
|
|
438
443
|
type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
|
|
439
444
|
type Fragments<T> = T | readonly Fragments<T>[];
|
|
440
445
|
type Target = {
|
|
@@ -473,7 +478,9 @@ type ProxyGroup<A extends GroupAlgorithm = GroupAlgorithm> = {
|
|
|
473
478
|
readonly algorithm: A;
|
|
474
479
|
readonly members: readonly Exit[];
|
|
475
480
|
readonly surge?: {
|
|
476
|
-
readonly
|
|
481
|
+
readonly hidden?: boolean;
|
|
482
|
+
readonly category?: string;
|
|
483
|
+
readonly url?: string;
|
|
477
484
|
readonly intervalSeconds?: number;
|
|
478
485
|
readonly timeoutSeconds?: number;
|
|
479
486
|
};
|
|
@@ -561,7 +568,7 @@ type Common = {
|
|
|
561
568
|
readonly fallback: Exit;
|
|
562
569
|
};
|
|
563
570
|
type Portable = Exclude<GroupAlgorithm, {
|
|
564
|
-
type: "surge-smart";
|
|
571
|
+
type: "surge-smart" | "surge-fallback";
|
|
565
572
|
}>;
|
|
566
573
|
type ProfileDefinition = Common & ({
|
|
567
574
|
readonly target: Extract<Target, {
|
|
@@ -618,11 +625,7 @@ type FlattenedProfile<D extends ProfileDefinition> = D extends ProfileDefinition
|
|
|
618
625
|
} ? ResolvedSurge : never;
|
|
619
626
|
} : never;
|
|
620
627
|
type Profile<D extends ProfileDefinition = ProfileDefinition> = FlattenedProfile<D> & SDK<"profile">;
|
|
621
|
-
//#endregion
|
|
622
|
-
//#region src/authoring/profile.d.ts
|
|
623
628
|
export declare function defineProfile<const D extends ProfileDefinition>(input: D): Profile<D>;
|
|
624
|
-
//#endregion
|
|
625
|
-
//#region src/authoring/resources.d.ts
|
|
626
629
|
export declare const outbound: {
|
|
627
630
|
direct: {
|
|
628
631
|
builtin: "DIRECT";
|
|
@@ -651,8 +654,6 @@ export declare function defineRoutes(input: {
|
|
|
651
654
|
readonly when: Fragments<Condition>;
|
|
652
655
|
readonly to: Exit;
|
|
653
656
|
}): Route[];
|
|
654
|
-
//#endregion
|
|
655
|
-
//#region src/authoring/proxy-builder.d.ts
|
|
656
657
|
type ProxyBuilder<N extends ProxyNode> = {
|
|
657
658
|
readonly via: (exit: ProxyNode | ProxyGroup) => ProxyBuilder<N>;
|
|
658
659
|
readonly name: (text: string) => ProxyBuilder<N>;
|
|
@@ -660,8 +661,6 @@ type ProxyBuilder<N extends ProxyNode> = {
|
|
|
660
661
|
readonly build: () => N;
|
|
661
662
|
};
|
|
662
663
|
declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<N>;
|
|
663
|
-
//#endregion
|
|
664
|
-
//#region src/authoring/constructors.d.ts
|
|
665
664
|
export declare function dnsRule(pattern: string, server: string): DnsRule;
|
|
666
665
|
export declare function dnsRule(pattern: readonly string[], server: string): DnsRule[];
|
|
667
666
|
export declare function dnsRule(pattern: string, server: TailscaleDnsOptions): DnsRule<TailscaleDnsOptions>;
|
|
@@ -765,6 +764,33 @@ export declare const group: {
|
|
|
765
764
|
type Input<T extends object> = Omit<T, "type" | keyof SDK<string>>;
|
|
766
765
|
export declare const proxy: {
|
|
767
766
|
builder: typeof proxyBuilder;
|
|
767
|
+
socks5: (input: Input<Omit<{
|
|
768
|
+
readonly id: string;
|
|
769
|
+
readonly server: string;
|
|
770
|
+
readonly port: number;
|
|
771
|
+
readonly via?: string;
|
|
772
|
+
readonly tcpFastOpen?: boolean;
|
|
773
|
+
readonly type: "socks5";
|
|
774
|
+
readonly password: SecretRef;
|
|
775
|
+
readonly username?: SecretRef | undefined;
|
|
776
|
+
readonly serverName?: never;
|
|
777
|
+
}, "label" | "via"> & {
|
|
778
|
+
readonly via?: ProxyNode | ProxyGroup;
|
|
779
|
+
readonly name?: string;
|
|
780
|
+
} & SDK<"node">>) => Omit<{
|
|
781
|
+
readonly id: string;
|
|
782
|
+
readonly server: string;
|
|
783
|
+
readonly port: number;
|
|
784
|
+
readonly via?: string;
|
|
785
|
+
readonly tcpFastOpen?: boolean;
|
|
786
|
+
readonly type: "socks5";
|
|
787
|
+
readonly password: SecretRef;
|
|
788
|
+
readonly username?: SecretRef | undefined;
|
|
789
|
+
readonly serverName?: never;
|
|
790
|
+
}, "label" | "via"> & {
|
|
791
|
+
readonly via?: ProxyNode | ProxyGroup;
|
|
792
|
+
readonly name?: string;
|
|
793
|
+
} & SDK<"node">;
|
|
768
794
|
http: (input: Input<Omit<{
|
|
769
795
|
readonly id: string;
|
|
770
796
|
readonly server: string;
|
|
@@ -772,6 +798,9 @@ export declare const proxy: {
|
|
|
772
798
|
readonly via?: string;
|
|
773
799
|
readonly tcpFastOpen?: boolean;
|
|
774
800
|
readonly type: "http";
|
|
801
|
+
readonly surge?: {
|
|
802
|
+
readonly testUrl: string;
|
|
803
|
+
} | undefined;
|
|
775
804
|
readonly serverName?: never;
|
|
776
805
|
readonly password: SecretRef;
|
|
777
806
|
readonly username?: SecretRef | undefined;
|
|
@@ -785,6 +814,9 @@ export declare const proxy: {
|
|
|
785
814
|
readonly via?: string;
|
|
786
815
|
readonly tcpFastOpen?: boolean;
|
|
787
816
|
readonly type: "http";
|
|
817
|
+
readonly surge?: {
|
|
818
|
+
readonly testUrl: string;
|
|
819
|
+
} | undefined;
|
|
788
820
|
readonly serverName?: never;
|
|
789
821
|
readonly password: SecretRef;
|
|
790
822
|
readonly username?: SecretRef | undefined;
|
|
@@ -1072,6 +1104,9 @@ export declare const surge: {
|
|
|
1072
1104
|
builtin: "SYSTEM";
|
|
1073
1105
|
} & SDK<"ruleSet">;
|
|
1074
1106
|
};
|
|
1107
|
+
fallback: () => {
|
|
1108
|
+
type: "surge-fallback";
|
|
1109
|
+
} & SDK<"algorithm">;
|
|
1075
1110
|
smart: () => {
|
|
1076
1111
|
type: "surge-smart";
|
|
1077
1112
|
} & SDK<"algorithm">;
|
|
@@ -1137,8 +1172,6 @@ export declare const surge: {
|
|
|
1137
1172
|
export declare const singbox: {
|
|
1138
1173
|
tailscale: (input: Input<SingBoxEndpoint>) => SingBoxEndpoint;
|
|
1139
1174
|
};
|
|
1140
|
-
//#endregion
|
|
1141
|
-
//#region src/authoring/secret-inputs.d.ts
|
|
1142
1175
|
type Source = ({
|
|
1143
1176
|
readonly env: string;
|
|
1144
1177
|
readonly value?: never;
|
|
@@ -1149,31 +1182,24 @@ type Source = ({
|
|
|
1149
1182
|
readonly validation?: string;
|
|
1150
1183
|
};
|
|
1151
1184
|
export declare function defineSecrets<const T extends Record<string, Source>>(input: T): Secrets<Extract<keyof T, string>>;
|
|
1152
|
-
//#endregion
|
|
1153
|
-
//#region src/authoring/proxy-id.d.ts
|
|
1154
1185
|
/** Stable identity independent of engine and mutable metadata. */
|
|
1155
1186
|
export declare function proxyId(namespace: string, name: string): string;
|
|
1156
|
-
//#endregion
|
|
1157
|
-
//#region src/model/build-types.d.ts
|
|
1158
1187
|
type BuildDefinition = {
|
|
1159
1188
|
readonly outDir?: string;
|
|
1160
1189
|
readonly profiles: Readonly<Record<string, Profile>>;
|
|
1161
1190
|
readonly secrets?: Secrets;
|
|
1162
1191
|
} & SDK<"build">;
|
|
1163
|
-
//#endregion
|
|
1164
|
-
//#region src/authoring/build.d.ts
|
|
1165
1192
|
/** Capture the immutable batch before any secret source is invoked. */
|
|
1166
1193
|
export declare function defineBuild(input: Omit<BuildDefinition, keyof SDK<"build">>): BuildDefinition;
|
|
1167
|
-
//#endregion
|
|
1168
|
-
//#region src/model/definitions.d.ts
|
|
1169
1194
|
export declare class ProfileDefinitionError extends Error {
|
|
1170
1195
|
readonly code: string;
|
|
1171
1196
|
readonly paths?: readonly string[];
|
|
1172
1197
|
readonly origin?: Origin;
|
|
1173
1198
|
constructor(code: string, paths?: readonly string[]);
|
|
1174
1199
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1200
|
+
export type Socks5Node = Extract<ProxyNode, {
|
|
1201
|
+
type: "socks5";
|
|
1202
|
+
}>;
|
|
1177
1203
|
export type HttpNode = Extract<ProxyNode, {
|
|
1178
1204
|
type: "http";
|
|
1179
1205
|
}>;
|
|
@@ -1195,8 +1221,6 @@ export type VMessNode = Extract<ProxyNode, {
|
|
|
1195
1221
|
export type VLESSNode = Extract<ProxyNode, {
|
|
1196
1222
|
type: "vless";
|
|
1197
1223
|
}>;
|
|
1198
|
-
//#endregion
|
|
1199
|
-
//#region src/model/inspect-profile.d.ts
|
|
1200
1224
|
type Selection = {
|
|
1201
1225
|
kind: "name";
|
|
1202
1226
|
resource: string;
|
|
@@ -1212,11 +1236,7 @@ type Selection = {
|
|
|
1212
1236
|
branch: "surge" | "singBox" | "mihomo";
|
|
1213
1237
|
nativeName: string;
|
|
1214
1238
|
};
|
|
1215
|
-
//#endregion
|
|
1216
|
-
//#region src/build/explain.d.ts
|
|
1217
1239
|
export declare function explainProfile(profile: Profile, request: RouteRequest, assume?: Assumptions): ExplainResult;
|
|
1218
|
-
//#endregion
|
|
1219
|
-
//#region src/build/index.d.ts
|
|
1220
1240
|
type CheckResult = {
|
|
1221
1241
|
readonly ok: boolean;
|
|
1222
1242
|
readonly code: "CHECKED" | "CHECK_FAILED" | "CASE_FAILED";
|
|
@@ -1243,5 +1263,4 @@ export declare function checkBuild(definition: BuildDefinition): CheckResult;
|
|
|
1243
1263
|
export declare function runBuild(definition: BuildDefinition, options?: {
|
|
1244
1264
|
readonly validation?: boolean;
|
|
1245
1265
|
}): Promise<BuildResult>;
|
|
1246
|
-
//#endregion
|
|
1247
1266
|
export type { Assumptions, BuildDefinition, BuildResult, CaseResult, CheckResult, Condition, ProfileDiagnostic as Diagnostic, DnsRule, Exit, ExplainResult, Explanation, Fragments, GroupAlgorithm, Need, Origin, Profile, ProfileDefinition, ProxyBuilder, ProxyGroup, ProxyNode, Route, RouteCase, RouteRequest, RuleSet, SecretRef, Secrets, Selection, SingBoxEndpoint, SurgeGeneral, SurgeHost, SurgeTunnel, TailscaleDnsOptions, Target };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ProfileDefinitionError, T as inspectDefinition, _ as endpointSchema, a as defineBuild, b as nativeRuleSetSchema, c as dnsRulesSchema, d as tunnelSchema, f as created, g as requireKind, h as parsed, l as conditionSchema, m as inspectRecord, n as runBuild, o as secretSources, p as flatten, r as explainProfile, s as defineProfile, t as checkBuild, u as groupTestSchema, v as idSchema, w as exactDefinition, x as nodeSchema, y as matchSchema } from "./build-
|
|
1
|
+
import { S as ProfileDefinitionError, T as inspectDefinition, _ as endpointSchema, a as defineBuild, b as nativeRuleSetSchema, c as dnsRulesSchema, d as tunnelSchema, f as created, g as requireKind, h as parsed, l as conditionSchema, m as inspectRecord, n as runBuild, o as secretSources, p as flatten, r as explainProfile, s as defineProfile, t as checkBuild, u as groupTestSchema, v as idSchema, w as exactDefinition, x as nodeSchema, y as matchSchema } from "./build-Dlv1JO0_.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
-
|
|
3
|
+
// src/authoring/resources.ts
|
|
4
4
|
const builtin = (builtin) => created({ builtin }, "builtin");
|
|
5
5
|
const outbound = {
|
|
6
6
|
direct: builtin("DIRECT"),
|
|
@@ -56,8 +56,7 @@ function defineRoutes(input) {
|
|
|
56
56
|
}, "route");
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
//#region src/authoring/proxy-builder.ts
|
|
59
|
+
// src/authoring/proxy-builder.ts
|
|
61
60
|
function proxyBuilder(node) {
|
|
62
61
|
requireKind(node, ["node"]);
|
|
63
62
|
const fork = (patch) => proxyBuilder(created({
|
|
@@ -81,8 +80,7 @@ function proxyBuilder(node) {
|
|
|
81
80
|
build: () => created({ ...node }, "node")
|
|
82
81
|
});
|
|
83
82
|
}
|
|
84
|
-
|
|
85
|
-
//#region src/authoring/surge-match.ts
|
|
83
|
+
// src/authoring/surge-match.ts
|
|
86
84
|
function condition(value) {
|
|
87
85
|
inspectDefinition(value);
|
|
88
86
|
const fields = value.type === "ruleSet" ? [
|
|
@@ -124,8 +122,7 @@ const surgeMatch = {
|
|
|
124
122
|
ipCidr6: (value, options = {}) => atom$1("ipCidr6")(value, options),
|
|
125
123
|
macAddress: (value) => atom$1("macAddress")(value)
|
|
126
124
|
};
|
|
127
|
-
|
|
128
|
-
//#region src/authoring/constructors.ts
|
|
125
|
+
// src/authoring/constructors.ts
|
|
129
126
|
function dnsRule(pattern, server) {
|
|
130
127
|
const batch = Array.isArray(pattern);
|
|
131
128
|
const result = parsed(dnsRulesSchema, (batch ? pattern : [pattern]).map((p) => ({
|
|
@@ -267,6 +264,7 @@ function nodeConstructor(type) {
|
|
|
267
264
|
}
|
|
268
265
|
const proxy = {
|
|
269
266
|
builder: proxyBuilder,
|
|
267
|
+
socks5: nodeConstructor("socks5"),
|
|
270
268
|
http: nodeConstructor("http"),
|
|
271
269
|
trojan: nodeConstructor("trojan"),
|
|
272
270
|
anytls: nodeConstructor("anytls"),
|
|
@@ -306,6 +304,7 @@ const surge = {
|
|
|
306
304
|
builtin: "SYSTEM"
|
|
307
305
|
}, "ruleSet")
|
|
308
306
|
},
|
|
307
|
+
fallback: () => created({ type: "surge-fallback" }, "algorithm"),
|
|
309
308
|
smart: () => created({ type: "surge-smart" }, "algorithm"),
|
|
310
309
|
tailscale: tunnel("tailscale"),
|
|
311
310
|
wireguard: tunnel("wireguard")
|
|
@@ -323,8 +322,7 @@ const singbox = { tailscale: (input) => {
|
|
|
323
322
|
type: "sing-box-tailscale"
|
|
324
323
|
}, "endpoint");
|
|
325
324
|
} };
|
|
326
|
-
|
|
327
|
-
//#region src/authoring/secret-inputs.ts
|
|
325
|
+
// src/authoring/secret-inputs.ts
|
|
328
326
|
function defineSecrets(input) {
|
|
329
327
|
inspectRecord(input);
|
|
330
328
|
exactDefinition(input, Object.keys(input));
|
|
@@ -352,12 +350,10 @@ function defineSecrets(input) {
|
|
|
352
350
|
secretSources.set(collection, sources);
|
|
353
351
|
return collection;
|
|
354
352
|
}
|
|
355
|
-
|
|
356
|
-
//#region src/authoring/proxy-id.ts
|
|
353
|
+
// src/authoring/proxy-id.ts
|
|
357
354
|
/** Stable identity independent of engine and mutable metadata. */
|
|
358
355
|
function proxyId(namespace, name) {
|
|
359
356
|
if (typeof namespace !== "string" || !namespace.length || typeof name !== "string" || !name.length) throw new ProfileDefinitionError("INVALID_FIELD");
|
|
360
357
|
return `node-${createHash("sha256").update(JSON.stringify([namespace, name])).digest("hex").slice(0, 16)}`;
|
|
361
358
|
}
|
|
362
|
-
//#endregion
|
|
363
359
|
export { ProfileDefinitionError, checkBuild, defineBuild, defineProfile, defineProxyGroup, defineRoutes, defineSecrets, dnsRule, explainProfile, group, match, outbound, proxy, proxyId, ruleSet, runBuild, singbox, surge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proxylang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Composable routing policies in TypeScript with explicit platform targets",
|
|
5
5
|
"homepage": "https://github.com/CorrectRoadH/proxylang#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"zod": "4.6.7"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/node": "^
|
|
52
|
+
"@types/node": "^26.6.6",
|
|
53
53
|
"typescript": "7.0.2",
|
|
54
|
-
"vite-plus": "1.
|
|
54
|
+
"vite-plus": "1.7.0"
|
|
55
55
|
},
|
|
56
56
|
"overrides": {
|
|
57
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@
|
|
57
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@8.3.8000"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=24.11.0 <25 || >=26.0.0 <27"
|
|
61
61
|
},
|
|
62
|
-
"packageManager": "npm@11.
|
|
62
|
+
"packageManager": "npm@11.20.0"
|
|
63
63
|
}
|