proxylang 0.15.0 → 0.17.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/README.md CHANGED
@@ -62,7 +62,7 @@ const sharedCases = (exits: { ai: Exit }) => [
62
62
  ];
63
63
 
64
64
  const laptop = defineProfile({
65
- target: { engine: "surge", platform: "macos", version: "6.11.0" },
65
+ target: { engine: "surge", platform: "macos", version: "6.12.0" },
66
66
  proxies: [edge],
67
67
  groups: [ai],
68
68
  routes: sharedRoutes({ ai }),
@@ -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
- //#region src/model/identity.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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(["select", "smart"]),
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
- }).required({ url: true });
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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 === "surge-smart" || profile.target.engine === "stash" && resource.algorithm.type !== "select") ? { type: "select" } : resource.algorithm;
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 && algorithm.type === "select" && options ? { surge: options } : {}
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
- //#endregion
1372
- //#region src/model/protocols.ts
1370
+ // src/model/protocols.ts
1373
1371
  function nodeIsTcpOnly(node, engine) {
1374
- 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;
1372
+ return node.type === "http" || node.type === "anytls" && engine !== "surge" && engine !== "sing-box" || node.type === "vmess" || node.type === "vless" && engine !== "surge" && !(engine === "sing-box" && node.packetEncoding) || engine === "surge" && node.type === "shadowsocks" && node.surge?.udpRelay === false;
1375
1373
  }
1376
- //#endregion
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
- //#endregion
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" || resource.algorithm.type !== "select")) error("GROUP_OPTION_UNSUPPORTED", path + ".surge", resource);
1441
- if (resource.algorithm.type === "surge-smart" && profile.target.engine !== "surge") error("ALGORITHM_ENGINE_MISMATCH", path + ".algorithm", resource);
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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))}`);
@@ -1857,17 +1855,34 @@ function surgeProxy(node, secret, name = (id) => id) {
1857
1855
  if (node.transport.host) params.push(`ws-headers=Host:${node.transport.host}`);
1858
1856
  }
1859
1857
  break;
1860
- case "vless": throw new RenderError("PROTOCOL_UNSUPPORTED");
1858
+ case "vless":
1859
+ params.push(`username=${uuid(node.uuid, secret)}`);
1860
+ if (node.flow) params.push(`flow=${node.flow}`);
1861
+ if (node.tls) {
1862
+ if (!node.reality) params.push("tls=true");
1863
+ params.push(`sni=${node.tls.serverName}`);
1864
+ if (!node.reality && node.tls.skipCertVerify !== void 0) params.push(`skip-cert-verify=${node.tls.skipCertVerify}`);
1865
+ const alpn = node.tls.alpn;
1866
+ if (alpn) params.push(`alpn=${alpn.length === 1 ? alpn[0] : `"${alpn.join(",")}"`}`);
1867
+ }
1868
+ if (node.reality) {
1869
+ params.push(`reality-public-key=${node.reality.publicKey}`);
1870
+ if (node.reality.shortId) params.push(`reality-short-id=${node.reality.shortId}`);
1871
+ if (node.utlsFingerprint === "chrome") params.push("client-fingerprint=chromium-155");
1872
+ }
1873
+ if (node.transport) {
1874
+ params.push("ws=true", `ws-path=${node.transport.path}`);
1875
+ if (node.transport.host) params.push(`ws-headers=Host:${node.transport.host}`);
1876
+ }
1861
1877
  }
1862
1878
  if (node.tcpFastOpen !== void 0) params.push(`tfo=${node.tcpFastOpen}`);
1863
1879
  if (node.type === "trojan" || node.type === "anytls" && node.surge?.udpRelay) params.push("udp-relay=true");
1864
1880
  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}`);
1881
+ if (node.type !== "shadowsocks" && node.type !== "http" && "surge" in node && node.surge?.blockQuic !== void 0) params.push(`block-quic=${node.surge.blockQuic}`);
1866
1882
  if (node.via) params.push(`underlying-proxy=${name(node.via)}`);
1867
1883
  return params.join(", ");
1868
1884
  }
1869
- //#endregion
1870
- //#region src/targets/proxies.ts
1885
+ // src/targets/proxies.ts
1871
1886
  function validateProxyOptions(node, target, diagnostics) {
1872
1887
  if (node.type === "hysteria2") {
1873
1888
  if (target.engine === "surge" && node.portHopping && node.via) diagnostics.push({
@@ -1881,7 +1896,7 @@ function validateProxyOptions(node, target, diagnostics) {
1881
1896
  }
1882
1897
  const tls = "tls" in node ? node.tls : void 0;
1883
1898
  const singBox = target.engine === "sing-box";
1884
- if (node.type === "vless" && !singBox && (node.flow !== void 0 || node.packetEncoding !== void 0 || node.reality !== void 0 || node.utlsFingerprint !== void 0)) diagnostics.push({
1899
+ if (node.type === "vless" && !singBox && target.engine !== "surge" && (node.flow !== void 0 || node.packetEncoding !== void 0 || node.reality !== void 0 || node.utlsFingerprint !== void 0)) diagnostics.push({
1885
1900
  severity: "error",
1886
1901
  code: "PROXY_OPTION_UNSUPPORTED",
1887
1902
  target: target.id,
@@ -1904,7 +1919,23 @@ function validateProxyOptions(node, target, diagnostics) {
1904
1919
  });
1905
1920
  return;
1906
1921
  }
1907
- if (("serverName" in node ? node.serverName : tls?.serverName) === "off" || tls?.alpn !== void 0) diagnostics.push({
1922
+ const name = "serverName" in node ? node.serverName : tls?.serverName;
1923
+ if (node.type === "vless") {
1924
+ const path = `proxies.${node.id}`;
1925
+ const unsupported = (field, message) => diagnostics.push({
1926
+ severity: "error",
1927
+ code: "PROXY_OPTION_UNSUPPORTED",
1928
+ target: target.id,
1929
+ path: `${path}.${field}`,
1930
+ message
1931
+ });
1932
+ if (node.packetEncoding === "packetaddr") unsupported("packetEncoding", "Surge VLESS 仅支持 XUDP");
1933
+ if (node.reality && node.transport) unsupported("transport", "Surge VLESS REALITY 不支持 WebSocket");
1934
+ if (node.reality && tls?.skipCertVerify === true) unsupported("tls.skipCertVerify", "Surge REALITY 由握手验证服务端");
1935
+ if (node.utlsFingerprint && !node.reality) unsupported("utlsFingerprint", "此 Surge 版本仅在 REALITY 使用 Chrome 指纹");
1936
+ if (tls?.alpn && (node.reality || tls.alpn.some((value) => !/^[A-Za-z0-9._/-]+$/.test(value)))) unsupported("tls.alpn", "Surge VLESS ALPN 必须能安全编码,且仅适用于普通 TLS");
1937
+ }
1938
+ if (name === "off" || node.type !== "vless" && tls?.alpn !== void 0) diagnostics.push({
1908
1939
  severity: "error",
1909
1940
  code: "PROXY_OPTION_UNSUPPORTED",
1910
1941
  target: target.id,
@@ -1912,8 +1943,7 @@ function validateProxyOptions(node, target, diagnostics) {
1912
1943
  message: "Surge 编码不接受特殊 SNI off 或显式 ALPN;不会丢弃 TLS 选项"
1913
1944
  });
1914
1945
  }
1915
- //#endregion
1916
- //#region src/engines/surge/profile.ts
1946
+ // src/engines/surge/profile.ts
1917
1947
  const plans = /* @__PURE__ */ new WeakMap();
1918
1948
  function compileSurgeProfile(input) {
1919
1949
  const diagnostics = [];
@@ -1976,7 +2006,6 @@ function compileSurgeProfile(input) {
1976
2006
  const edges = new Map(resources.map((r) => [r.id, []]));
1977
2007
  const proxyIds = new Set([...p.nodes, ...tunnels].map((n) => n.id));
1978
2008
  for (const node of p.nodes) {
1979
- if (node.type === "vless") error("PROTOCOL_UNSUPPORTED", `proxies.${node.id}`);
1980
2009
  validateProxyOptions(node, {
1981
2010
  id: "profile",
1982
2011
  engine: "surge"
@@ -2137,6 +2166,8 @@ function renderProfile(compilation, read) {
2137
2166
  for (const g of p.groups) lines.push(`${name(g.id)} = ${[
2138
2167
  g.type,
2139
2168
  ...g.members.map(action),
2169
+ ...g.hidden !== void 0 ? [`hidden=${g.hidden}`] : [],
2170
+ ...g.category ? [`category=${g.category}`] : [],
2140
2171
  ...g.url ? [`url=${g.url}`] : [],
2141
2172
  ...g.intervalSeconds !== void 0 ? [`interval=${g.intervalSeconds}`] : [],
2142
2173
  ...g.timeoutSeconds !== void 0 ? [`timeout=${g.timeoutSeconds}`] : []
@@ -2158,8 +2189,7 @@ function renderSurgeProfiles(compilations, resolveSecret) {
2158
2189
  const read = resolveSecret;
2159
2190
  return deepFreeze(compilations.map((c) => renderProfile(c, read)));
2160
2191
  }
2161
- //#endregion
2162
- //#region src/model/normalize-surge.ts
2192
+ // src/model/normalize-surge.ts
2163
2193
  const outbound = {
2164
2194
  direct: { builtin: "DIRECT" },
2165
2195
  reject: { builtin: "REJECT" },
@@ -2225,6 +2255,7 @@ function lowerSurgeProfile(input) {
2225
2255
  if (!definition.algorithm || ![
2226
2256
  "select",
2227
2257
  "surge-smart",
2258
+ "surge-fallback",
2228
2259
  "auto"
2229
2260
  ].includes(definition.algorithm.type)) fail("UNSUPPORTED_GROUP_ALGORITHM");
2230
2261
  exactDefinition(definition.algorithm, ["type"]);
@@ -2232,7 +2263,7 @@ function lowerSurgeProfile(input) {
2232
2263
  const { id } = definition;
2233
2264
  return {
2234
2265
  id,
2235
- type: definition.algorithm.type === "select" ? "select" : "smart",
2266
+ type: definition.algorithm.type === "surge-fallback" ? "fallback" : definition.algorithm.type === "select" ? "select" : "smart",
2236
2267
  members: definition.members.map(lower),
2237
2268
  ...definition.surge
2238
2269
  };
@@ -2325,15 +2356,13 @@ function normalizeSurgeProfile(p) {
2325
2356
  fallback: p.fallback
2326
2357
  });
2327
2358
  }
2328
- //#endregion
2329
- //#region src/model/semantics.ts
2359
+ // src/model/semantics.ts
2330
2360
  const singboxMemberTag = (id) => id === "DIRECT" ? "pl-direct" : id === "REJECT" ? "pl-reject" : id;
2331
2361
  /** Only top-level atoms (or transparent named wrappers) can request ordered DNS. */
2332
2362
  function needsResolve(condition) {
2333
2363
  return condition.type === "ipCidr" && condition.noResolve !== true || condition.type === "nativeRuleSet" && condition.engine === "sing-box" && condition.resolve === true;
2334
2364
  }
2335
- //#endregion
2336
- //#region src/engines/sing-box/groups.ts
2365
+ // src/engines/sing-box/groups.ts
2337
2366
  function singboxGroup(group, name = (id) => id) {
2338
2367
  if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
2339
2368
  return group.type === "select" ? {
@@ -2353,11 +2382,10 @@ function singboxGroup(group, name = (id) => id) {
2353
2382
  interrupt_exist_connections: false
2354
2383
  };
2355
2384
  }
2356
- //#endregion
2357
- //#region src/engines/sing-box/proxies.ts
2385
+ // src/engines/sing-box/proxies.ts
2358
2386
  function singboxProxy(node, secret) {
2359
2387
  const result = {
2360
- type: node.type,
2388
+ type: node.type === "socks5" ? "socks" : node.type,
2361
2389
  tag: node.id,
2362
2390
  server: node.server,
2363
2391
  server_port: node.port,
@@ -2378,6 +2406,7 @@ function singboxProxy(node, secret) {
2378
2406
  }
2379
2407
  if (node.portHoppingInterval !== void 0) result.hop_interval = `${node.portHoppingInterval}s`;
2380
2408
  break;
2409
+ case "socks5":
2381
2410
  case "http":
2382
2411
  result.password = secret(node.password);
2383
2412
  if (node.username) result.username = secret(node.username);
@@ -2433,8 +2462,7 @@ function singboxProxy(node, secret) {
2433
2462
  }
2434
2463
  return result;
2435
2464
  }
2436
- //#endregion
2437
- //#region src/engines/sing-box/render.ts
2465
+ // src/engines/sing-box/render.ts
2438
2466
  const DIRECT = "pl-direct";
2439
2467
  const DNS = "pl-dns";
2440
2468
  const actionTag = (a, name) => a.type === "route" ? name(a.to) : a.type === "direct" ? DIRECT : "pl-reject";
@@ -2665,8 +2693,7 @@ function singbox(plan, secret) {
2665
2693
  }
2666
2694
  return config;
2667
2695
  }
2668
- //#endregion
2669
- //#region src/engines/mihomo/proxies.ts
2696
+ // src/engines/mihomo/proxies.ts
2670
2697
  function clashProxy$1(node, secret, name = (id) => id) {
2671
2698
  const result = {
2672
2699
  name: name(node.id),
@@ -2683,6 +2710,7 @@ function clashProxy$1(node, secret, name = (id) => id) {
2683
2710
  if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
2684
2711
  if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
2685
2712
  break;
2713
+ case "socks5":
2686
2714
  case "http":
2687
2715
  result.password = secret(node.password);
2688
2716
  if (node.username) result.username = secret(node.username);
@@ -2721,8 +2749,7 @@ function clashProxy$1(node, secret, name = (id) => id) {
2721
2749
  }
2722
2750
  return result;
2723
2751
  }
2724
- //#endregion
2725
- //#region src/engines/mihomo/render.ts
2752
+ // src/engines/mihomo/render.ts
2726
2753
  function clashGroup$1(group, name = (id) => id) {
2727
2754
  if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
2728
2755
  return {
@@ -2794,8 +2821,7 @@ function clashConfig$1(plan, secret) {
2794
2821
  }
2795
2822
  return config;
2796
2823
  }
2797
- //#endregion
2798
- //#region src/engines/stash/proxies.ts
2824
+ // src/engines/stash/proxies.ts
2799
2825
  function clashProxy(node, secret, name = (id) => id) {
2800
2826
  const result = {
2801
2827
  name: name(node.id),
@@ -2813,6 +2839,7 @@ function clashProxy(node, secret, name = (id) => id) {
2813
2839
  if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
2814
2840
  if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
2815
2841
  break;
2842
+ case "socks5":
2816
2843
  case "http":
2817
2844
  result.password = secret(node.password);
2818
2845
  if (node.username) result.username = secret(node.username);
@@ -2851,8 +2878,7 @@ function clashProxy(node, secret, name = (id) => id) {
2851
2878
  }
2852
2879
  return result;
2853
2880
  }
2854
- //#endregion
2855
- //#region src/engines/stash/render.ts
2881
+ // src/engines/stash/render.ts
2856
2882
  function clashGroup(group, name = (id) => id) {
2857
2883
  if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
2858
2884
  return {
@@ -2924,8 +2950,7 @@ function clashConfig(plan, secret) {
2924
2950
  }
2925
2951
  return config;
2926
2952
  }
2927
- //#endregion
2928
- //#region src/engines/sing-box/check.ts
2953
+ // src/engines/sing-box/check.ts
2929
2954
  function engineChecks$2(model) {
2930
2955
  const t = model.target;
2931
2956
  return {
@@ -2948,8 +2973,7 @@ function engineChecks$2(model) {
2948
2973
  }
2949
2974
  };
2950
2975
  }
2951
- //#endregion
2952
- //#region src/engines/mihomo/check.ts
2976
+ // src/engines/mihomo/check.ts
2953
2977
  function engineChecks$1(model) {
2954
2978
  const t = model.target;
2955
2979
  return {
@@ -2970,8 +2994,7 @@ function engineChecks$1(model) {
2970
2994
  }
2971
2995
  };
2972
2996
  }
2973
- //#endregion
2974
- //#region src/engines/stash/check.ts
2997
+ // src/engines/stash/check.ts
2975
2998
  function engineChecks(model) {
2976
2999
  const t = model.target;
2977
3000
  return {
@@ -2994,8 +3017,7 @@ function engineChecks(model) {
2994
3017
  }
2995
3018
  };
2996
3019
  }
2997
- //#endregion
2998
- //#region src/targets/catalog.ts
3020
+ // src/targets/catalog.ts
2999
3021
  const targetCatalog = deepFreeze([
3000
3022
  {
3001
3023
  engine: "sing-box",
@@ -3006,6 +3028,7 @@ const targetCatalog = deepFreeze([
3006
3028
  "hysteria2",
3007
3029
  "trojan",
3008
3030
  "http",
3031
+ "socks5",
3009
3032
  "anytls",
3010
3033
  "shadowsocks",
3011
3034
  "vmess",
@@ -3018,37 +3041,49 @@ const targetCatalog = deepFreeze([
3018
3041
  },
3019
3042
  {
3020
3043
  engine: "surge",
3021
- version: "5.23.0",
3044
+ version: "6.0.0",
3022
3045
  autoGroup: "surge-smart",
3023
3046
  platforms: ["ios"],
3024
3047
  protocols: [
3025
3048
  "hysteria2",
3026
3049
  "trojan",
3027
3050
  "http",
3051
+ "socks5",
3028
3052
  "anytls",
3029
3053
  "shadowsocks",
3030
- "vmess"
3054
+ "vmess",
3055
+ "vless"
3031
3056
  ],
3032
3057
  endpoints: [],
3033
- groups: ["select", "surge-smart"],
3058
+ groups: [
3059
+ "select",
3060
+ "surge-smart",
3061
+ "surge-fallback"
3062
+ ],
3034
3063
  nativeRuleSets: ["rule-set", "domain-set"],
3035
3064
  dns: "general"
3036
3065
  },
3037
3066
  {
3038
3067
  engine: "surge",
3039
- version: "6.11.0",
3068
+ version: "6.12.0",
3040
3069
  autoGroup: "surge-smart",
3041
3070
  platforms: ["macos"],
3042
3071
  protocols: [
3043
3072
  "hysteria2",
3044
3073
  "trojan",
3045
3074
  "http",
3075
+ "socks5",
3046
3076
  "anytls",
3047
3077
  "shadowsocks",
3048
- "vmess"
3078
+ "vmess",
3079
+ "vless"
3049
3080
  ],
3050
3081
  endpoints: [],
3051
- groups: ["select", "surge-smart"],
3082
+ groups: [
3083
+ "select",
3084
+ "surge-smart",
3085
+ "surge-fallback"
3086
+ ],
3052
3087
  nativeRuleSets: ["rule-set", "domain-set"],
3053
3088
  dns: "general"
3054
3089
  },
@@ -3061,6 +3096,7 @@ const targetCatalog = deepFreeze([
3061
3096
  "hysteria2",
3062
3097
  "trojan",
3063
3098
  "http",
3099
+ "socks5",
3064
3100
  "anytls",
3065
3101
  "shadowsocks",
3066
3102
  "vmess",
@@ -3080,6 +3116,7 @@ const targetCatalog = deepFreeze([
3080
3116
  "hysteria2",
3081
3117
  "trojan",
3082
3118
  "http",
3119
+ "socks5",
3083
3120
  "anytls",
3084
3121
  "shadowsocks",
3085
3122
  "vmess",
@@ -3091,14 +3128,12 @@ const targetCatalog = deepFreeze([
3091
3128
  dns: "external"
3092
3129
  }
3093
3130
  ]);
3094
- //#endregion
3095
- //#region src/model/paths.ts
3131
+ // src/model/paths.ts
3096
3132
  function pathsOverlap(a, b) {
3097
3133
  if (a.startsWith("/") !== b.startsWith("/")) return false;
3098
3134
  return a === b || a.startsWith(b.endsWith("/") ? b : `${b}/`) || b.startsWith(a.endsWith("/") ? a : `${a}/`);
3099
3135
  }
3100
- //#endregion
3101
- //#region src/targets/check.ts
3136
+ // src/targets/check.ts
3102
3137
  function checkTarget(model, checks) {
3103
3138
  const diagnostics = [];
3104
3139
  const error = (code, path) => diagnostics.push({
@@ -3200,8 +3235,7 @@ function checkTarget(model, checks) {
3200
3235
  }
3201
3236
  };
3202
3237
  }
3203
- //#endregion
3204
- //#region src/build/plans.ts
3238
+ // src/build/plans.ts
3205
3239
  function prepareProfile(input, key, secrets, checkSecrets = true) {
3206
3240
  let engine = "surge";
3207
3241
  const collected = [];
@@ -3343,8 +3377,7 @@ function diagnosticOrigin(p, path) {
3343
3377
  if (resource) return originOf([...p.proxies, ...p.groups].find((r) => r.id === resource[1])) ?? originOf(p);
3344
3378
  return originOf(p);
3345
3379
  }
3346
- //#endregion
3347
- //#region src/build/secrets.ts
3380
+ // src/build/secrets.ts
3348
3381
  const failures = /* @__PURE__ */ new WeakMap();
3349
3382
  function secretFailure(error) {
3350
3383
  return error && typeof error === "object" ? failures.get(error) ?? {} : {};
@@ -3371,8 +3404,7 @@ function secretReader(secrets, validation) {
3371
3404
  return value;
3372
3405
  };
3373
3406
  }
3374
- //#endregion
3375
- //#region src/build/publish.ts
3407
+ // src/build/publish.ts
3376
3408
  var SurgePublishError = class extends Error {
3377
3409
  published;
3378
3410
  constructor(message, published) {
@@ -3467,8 +3499,7 @@ async function publishProfiles(files, surgeDirectory, io = { rename }) {
3467
3499
  }
3468
3500
  if (failure) throw new SurgePublishError(failure.message === "PROFILE_PUBLISH_CLEANUP_FAILED" ? committed ? "PUBLISHED_CLEANUP_FAILED" : "FAILED_CLEANUP_REQUIRED" : failure.message, committed);
3469
3501
  }
3470
- //#endregion
3471
- //#region src/build/explain.ts
3502
+ // src/build/explain.ts
3472
3503
  function explainProfile(profile, request, assume) {
3473
3504
  if (kindOf(profile) !== "profile") return {
3474
3505
  ok: false,
@@ -3506,8 +3537,7 @@ function explainProfile(profile, request, assume) {
3506
3537
  explanation: evaluate(prepared.routing, parsed, assumptions.values)
3507
3538
  };
3508
3539
  }
3509
- //#endregion
3510
- //#region src/build/index.ts
3540
+ // src/build/index.ts
3511
3541
  function compile(definition) {
3512
3542
  if (kindOf(definition) !== "build") throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
3513
3543
  const entries = Object.entries(definition.profiles);
@@ -3628,5 +3658,4 @@ async function runBuild(definition, options = {}) {
3628
3658
  };
3629
3659
  }
3630
3660
  }
3631
- //#endregion
3632
3661
  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-H0uxqVRQ.js";
2
+ import { C as definitionDiagnostic, i as targetCatalog } from "./build-WzQKLIE_.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
- //#region src/cli.ts
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,18 +440,16 @@ 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 = {
441
446
  readonly engine: "surge";
442
447
  readonly platform: "ios";
443
- readonly version: "5.23.0";
448
+ readonly version: "6.0.0";
444
449
  } | {
445
450
  readonly engine: "surge";
446
451
  readonly platform: "macos";
447
- readonly version: "6.11.0";
452
+ readonly version: "6.12.0";
448
453
  } | {
449
454
  readonly engine: "sing-box";
450
455
  readonly platform: "macos" | "linux";
@@ -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 url: string;
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
- //#endregion
1176
- //#region src/authoring/index.d.ts
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-H0uxqVRQ.js";
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-WzQKLIE_.js";
2
2
  import { createHash } from "node:crypto";
3
- //#region src/authoring/resources.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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.15.0",
3
+ "version": "0.17.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": "^24.0.0",
52
+ "@types/node": "^26.6.6",
53
53
  "typescript": "7.0.2",
54
- "vite-plus": "1.3.0"
54
+ "vite-plus": "1.7.0"
55
55
  },
56
56
  "overrides": {
57
- "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0"
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.12.1"
62
+ "packageManager": "npm@11.20.0"
63
63
  }