proxylang 0.14.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.
@@ -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 {
@@ -200,7 +198,7 @@ function unsafeTunResolvers(model) {
200
198
  const networks = model.tun.address.map((value) => ipaddr.parseCIDR(value));
201
199
  return [
202
200
  ...model.listener ? [model.listener.resolver] : [],
203
- ...(model.dns ?? []).map((rule) => isIP(rule.server) ? rule.server : new URL(rule.server).hostname.replace(/^\[|\]$/g, "")),
201
+ ...(model.dns ?? []).flatMap(({ server }) => typeof server === "string" ? [isIP(server) ? server : new URL(server).hostname.replace(/^\[|\]$/g, "")] : []),
204
202
  ...(model.endpoints ?? []).map((endpoint) => endpoint.bootstrapResolver)
205
203
  ].filter((value) => {
206
204
  if (!isIP(value)) return false;
@@ -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()
@@ -422,7 +426,10 @@ const endpointSchema = z.strictObject({
422
426
  type: z.literal("sing-box-tailscale"),
423
427
  id: idSchema,
424
428
  hostname: domain$3.refine((x) => !x.includes(".")),
425
- stateDirectory: z.string().max(4096).refine((x) => x.startsWith("/") && !/[\p{C}$\\]/u.test(x) && x.split("/").slice(1).every((part) => part !== "" && part !== "." && part !== "..")),
429
+ stateDirectory: z.string().max(4096).refine((value) => {
430
+ if (/[\p{C}$\\]/u.test(value) || /^(?:~|[a-z]:)/i.test(value)) return false;
431
+ return (value.startsWith("/") ? value.slice(1) : value).split("/").every((part) => part !== "" && part !== "." && part !== "..");
432
+ }),
426
433
  acceptRoutes: z.boolean(),
427
434
  bootstrapResolver: ip$2,
428
435
  authKey: secretSchema.optional(),
@@ -485,8 +492,7 @@ const engineOptionsSchema = z.strictObject({
485
492
  routeExcludeAddress: z.array(cidr$1).optional()
486
493
  }).refine((t) => !t.strictRoute || t.autoRoute).optional()
487
494
  });
488
- //#endregion
489
- //#region src/authoring/data.ts
495
+ // src/authoring/data.ts
490
496
  function frozen(value) {
491
497
  return deepFreeze(snapshotDefinition(value));
492
498
  }
@@ -518,8 +524,7 @@ function inspectRecord(value) {
518
524
  inspectDefinition(value);
519
525
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new ProfileDefinitionError("INVALID_FIELD");
520
526
  }
521
- //#endregion
522
- //#region src/model/names.ts
527
+ // src/model/names.ts
523
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-"));
524
529
  function isReservedNativeName(name, engine) {
525
530
  return (engine === "surge" ? [
@@ -539,8 +544,7 @@ function isReservedNativeName(name, engine) {
539
544
  "REJECT-DROP"
540
545
  ] : []).includes(name.toUpperCase());
541
546
  }
542
- //#endregion
543
- //#region src/model/surge-schema.ts
547
+ // src/model/surge-schema.ts
544
548
  const builtin = z.enum([
545
549
  "DIRECT",
546
550
  "REJECT",
@@ -673,17 +677,25 @@ const tunnelSchema = z.discriminatedUnion("type", [z.strictObject({
673
677
  })]);
674
678
  const groupSchema = z.strictObject({
675
679
  id: idSchema,
676
- type: z.enum(["select", "smart"]),
680
+ type: z.enum([
681
+ "select",
682
+ "smart",
683
+ "fallback"
684
+ ]),
677
685
  members: list(policy$2),
686
+ hidden: z.boolean().optional(),
687
+ category: z.string().min(1).regex(/^[^,=\r\n]+$/).optional(),
678
688
  url: url.optional(),
679
689
  intervalSeconds: z.number().int().positive().max(2147483647).optional(),
680
690
  timeoutSeconds: z.number().int().positive().max(3600).optional()
681
691
  });
682
692
  const groupTestSchema = groupSchema.pick({
693
+ hidden: true,
694
+ category: true,
683
695
  url: true,
684
696
  intervalSeconds: true,
685
697
  timeoutSeconds: true
686
- }).required({ url: true });
698
+ }).refine((g) => g.url !== void 0 || g.intervalSeconds === void 0 && g.timeoutSeconds === void 0);
687
699
  const options = { noResolve: z.boolean().optional() };
688
700
  const domainOptions = {
689
701
  ...options,
@@ -762,15 +774,14 @@ const inputSchema = z.strictObject({
762
774
  fallback: policy$2,
763
775
  names: z.record(idSchema, nativeNameSchema).optional()
764
776
  });
765
- //#endregion
766
- //#region src/model/dns.ts
777
+ // src/model/dns.ts
767
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;
768
779
  function dohUrl(value) {
769
780
  const url = new URL(value);
770
781
  if (!/^https:\/\/[^/]+\//.test(value)) url.pathname = "/dns-query";
771
782
  return url;
772
783
  }
773
- const server = z.string().max(2048).refine((value) => {
784
+ const address = z.string().max(2048).refine((value) => {
774
785
  if (isIP(value) && !value.includes("%")) return true;
775
786
  if (!value.startsWith("https://") || /[\s\p{C},()\\"'?#]/u.test(value)) return false;
776
787
  try {
@@ -782,15 +793,19 @@ const server = z.string().max(2048).refine((value) => {
782
793
  return false;
783
794
  }
784
795
  });
796
+ const tailscale = z.strictObject({
797
+ endpoint: z.custom((value) => kindOf(value) === "endpoint"),
798
+ acceptDefaultResolvers: z.boolean().optional()
799
+ });
785
800
  const dnsRulesSchema = z.array(z.strictObject({
786
801
  pattern: z.string().min(1).max(253).refine((value) => domain$1.test(value.startsWith("*.") ? value.slice(2) : value)),
787
- server
802
+ server: z.union([address, tailscale])
788
803
  })).max(2e3).superRefine((rules, ctx) => {
789
- if (rules.length > 2e3 || rules.some((rule) => rule.pattern.length > 253 || rule.server.length > 2048)) return;
804
+ if (rules.length > 2e3 || rules.some(({ pattern, server }) => pattern.length > 253 || typeof server === "string" && server.length > 2048)) return;
790
805
  for (let i = 0; i < rules.length; i++) for (let j = 0; j < i; j++) {
791
806
  const a = rules[i], b = rules[j];
792
807
  const x = a.pattern.toLowerCase(), y = b.pattern.toLowerCase();
793
- if (x === y || overlap(x, y) && a.server !== b.server) {
808
+ if (x === y || overlap(x, y) && !sameServer(a.server, b.server)) {
794
809
  ctx.addIssue({
795
810
  code: "custom",
796
811
  message: "DNS_RULE_CONFLICT"
@@ -799,6 +814,10 @@ const dnsRulesSchema = z.array(z.strictObject({
799
814
  }
800
815
  }
801
816
  });
817
+ function sameServer(a, b) {
818
+ if (typeof a === "string" || typeof b === "string") return a === b;
819
+ return a.endpoint === b.endpoint && (a.acceptDefaultResolvers ?? false) === (b.acceptDefaultResolvers ?? false);
820
+ }
802
821
  function overlap(a, b) {
803
822
  const wildA = a.startsWith("*."), wildB = b.startsWith("*.");
804
823
  if (wildA && wildB) return a.slice(1).endsWith(b.slice(1)) || b.slice(1).endsWith(a.slice(1));
@@ -808,8 +827,7 @@ function dnsCondition(rule) {
808
827
  const pattern = rule.pattern.toLowerCase();
809
828
  return pattern.startsWith("*.") ? { domain_regex: [`^.+\\.${pattern.slice(2).replaceAll(".", "\\.")}$`] } : { domain: [pattern] };
810
829
  }
811
- //#endregion
812
- //#region src/authoring/profile.ts
830
+ // src/authoring/profile.ts
813
831
  const fail$2 = (code) => {
814
832
  throw new ProfileDefinitionError(code);
815
833
  };
@@ -984,14 +1002,12 @@ function defineProfile(input) {
984
1002
  ...surge === void 0 ? {} : { surge }
985
1003
  }, "profile");
986
1004
  }
987
- //#endregion
988
- //#region src/model/secret-store.ts
1005
+ // src/model/secret-store.ts
989
1006
  const secretSources = /* @__PURE__ */ new WeakMap();
990
1007
  function sourceFor(secrets, ref) {
991
1008
  return secrets ? secretSources.get(secrets)?.get(ref) : void 0;
992
1009
  }
993
- //#endregion
994
- //#region src/authoring/build.ts
1010
+ // src/authoring/build.ts
995
1011
  function record(value, keys) {
996
1012
  if (!value || typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
997
1013
  for (const key of Reflect.ownKeys(value)) {
@@ -1023,8 +1039,7 @@ function defineBuild(input) {
1023
1039
  throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
1024
1040
  }
1025
1041
  }
1026
- //#endregion
1027
- //#region src/model/routing-model.ts
1042
+ // src/model/routing-model.ts
1028
1043
  const exitId = (exit) => "builtin" in exit ? exit.builtin : exit.id;
1029
1044
  function normalizeRouting(profile, inspected) {
1030
1045
  const sets = /* @__PURE__ */ new Map();
@@ -1075,8 +1090,7 @@ function normalizeRouting(profile, inspected) {
1075
1090
  ruleSets: sets
1076
1091
  });
1077
1092
  }
1078
- //#endregion
1079
- //#region src/routing/request.ts
1093
+ // src/routing/request.ts
1080
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])?$/);
1081
1095
  const ip = z.string().refine((v) => isIP(v) !== 0 && !v.includes("%"));
1082
1096
  const port = z.number().int().min(1).max(65535);
@@ -1107,8 +1121,7 @@ function parseRequest(input) {
1107
1121
  network: parsed.data.network ?? "tcp"
1108
1122
  });
1109
1123
  }
1110
- //#endregion
1111
- //#region src/routing/assumptions.ts
1124
+ // src/routing/assumptions.ts
1112
1125
  function prepareAssumptions(model, input = {}) {
1113
1126
  const values = /* @__PURE__ */ new Map();
1114
1127
  const errors = [];
@@ -1163,8 +1176,7 @@ function prepareAssumptions(model, input = {}) {
1163
1176
  errors
1164
1177
  };
1165
1178
  }
1166
- //#endregion
1167
- //#region src/routing/evaluate.ts
1179
+ // src/routing/evaluate.ts
1168
1180
  const yes = { matched: true };
1169
1181
  const no = { matched: false };
1170
1182
  const unknown = (needs) => ({
@@ -1251,8 +1263,7 @@ function evaluate(model, request, assumptions) {
1251
1263
  trace
1252
1264
  };
1253
1265
  }
1254
- //#endregion
1255
- //#region src/build/cases.ts
1266
+ // src/build/cases.ts
1256
1267
  function checkCases(profile, key, prepared, valid) {
1257
1268
  const diagnostics = [];
1258
1269
  const cases = [];
@@ -1313,8 +1324,7 @@ function checkCases(profile, key, prepared, valid) {
1313
1324
  cases
1314
1325
  };
1315
1326
  }
1316
- //#endregion
1317
- //#region src/model/diagnostic-view.ts
1327
+ // src/model/diagnostic-view.ts
1318
1328
  function diagnosticView(profile, inspected) {
1319
1329
  const diagnosticSecret = register({
1320
1330
  type: "env",
@@ -1333,13 +1343,13 @@ function diagnosticView(profile, inspected) {
1333
1343
  return resource;
1334
1344
  });
1335
1345
  const groups = profile.groups.map((resource) => {
1336
- 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;
1337
1347
  const { surge: options, ...rest } = resource;
1338
1348
  return {
1339
1349
  ...rest,
1340
1350
  algorithm,
1341
1351
  members: resource.members.map(destination),
1342
- ...surge && algorithm.type === "select" && options ? { surge: options } : {}
1352
+ ...surge && options ? { surge: options } : {}
1343
1353
  };
1344
1354
  });
1345
1355
  const stripName = (resource) => {
@@ -1357,13 +1367,11 @@ function diagnosticView(profile, inspected) {
1357
1367
  fallback: destination(profile.fallback)
1358
1368
  };
1359
1369
  }
1360
- //#endregion
1361
- //#region src/model/protocols.ts
1370
+ // src/model/protocols.ts
1362
1371
  function nodeIsTcpOnly(node, engine) {
1363
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;
1364
1373
  }
1365
- //#endregion
1366
- //#region src/model/network.ts
1374
+ // src/model/network.ts
1367
1375
  function truthPossibilities(condition, network) {
1368
1376
  switch (condition.type) {
1369
1377
  case "network": return [condition.value === network];
@@ -1379,8 +1387,7 @@ function truthPossibilities(condition, network) {
1379
1387
  default: return [false, true];
1380
1388
  }
1381
1389
  }
1382
- //#endregion
1383
- //#region src/model/inspect-profile.ts
1390
+ // src/model/inspect-profile.ts
1384
1391
  function inspectProfile(profile, key, secrets, checkSecrets = true) {
1385
1392
  const diagnostics = [];
1386
1393
  const selections = [];
@@ -1426,8 +1433,12 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
1426
1433
  const path = resource.type === "proxy-group" ? `groups.${resource.id}` : `proxies.${resource.id}`;
1427
1434
  if (kindOf(resource) === "tunnel" && profile.target.engine !== "surge" || kindOf(resource) === "endpoint" && profile.target.engine !== "sing-box") error("TUNNEL_UNSUPPORTED", path, resource);
1428
1435
  if (resource.type === "proxy-group") {
1429
- if (resource.surge !== void 0 && (profile.target.engine !== "surge" || resource.algorithm.type !== "select")) error("GROUP_OPTION_UNSUPPORTED", path + ".surge", resource);
1430
- 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);
1431
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);
1432
1443
  }
1433
1444
  }
@@ -1435,13 +1446,24 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
1435
1446
  if (kindOf(exit) !== "builtin" && !listed.has(exit)) error("UNLISTED_EXIT", path, owner);
1436
1447
  if (profile.target.engine !== "surge" && "builtin" in exit && !["DIRECT", "REJECT"].includes(exit.builtin)) error("EXIT_UNSUPPORTED", path, owner);
1437
1448
  };
1449
+ const tailscaleDnsDefaults = /* @__PURE__ */ new Map();
1450
+ profile.dns?.forEach((rule, i) => {
1451
+ if (typeof rule.server === "string") return;
1452
+ const { endpoint, acceptDefaultResolvers = false } = rule.server;
1453
+ const path = `dns[${i}].server`;
1454
+ reference(endpoint, `${path}.endpoint`, rule);
1455
+ if (profile.target.engine !== "sing-box" || profile.singBox?.mode === "fragment") error("DNS_UNSUPPORTED", path, rule, "Tailscale DNS requires sing-box standalone");
1456
+ const previous = tailscaleDnsDefaults.get(endpoint);
1457
+ if (previous === void 0) tailscaleDnsDefaults.set(endpoint, acceptDefaultResolvers);
1458
+ else if (previous !== acceptDefaultResolvers) error("TAILSCALE_DNS_OPTIONS_CONFLICT", `${path}.acceptDefaultResolvers`, rule);
1459
+ });
1438
1460
  const edges = /* @__PURE__ */ new Map();
1439
1461
  for (const resource of resources) {
1440
1462
  const path = resource.type === "proxy-group" ? `groups.${resource.id}` : `proxies.${resource.id}`;
1441
1463
  if (resource.type === "proxy-group") {
1442
1464
  resource.members.forEach((m, i) => {
1443
1465
  reference(m, `${path}.members[${i}]`, resource);
1444
- if (kindOf(m) === "endpoint") error("MEMBER_TYPE_UNSUPPORTED", `${path}.members[${i}]`, resource);
1466
+ if (kindOf(m) === "endpoint" && (profile.target.engine !== "sing-box" || profile.singBox?.mode === "fragment" || resource.algorithm.type !== "select")) error("MEMBER_TYPE_UNSUPPORTED", `${path}.members[${i}]`, resource);
1445
1467
  });
1446
1468
  edges.set(resource, resource.members.filter((m) => kindOf(m) !== "builtin"));
1447
1469
  if (resource.algorithm.type === "auto" && profile.target.engine !== "stash") selections.push({
@@ -1643,8 +1665,7 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
1643
1665
  mapped
1644
1666
  };
1645
1667
  }
1646
- //#endregion
1647
- //#region src/model/normalize.ts
1668
+ // src/model/normalize.ts
1648
1669
  const fail$1 = (code) => {
1649
1670
  throw new ProfileDefinitionError(code);
1650
1671
  };
@@ -1753,12 +1774,17 @@ function normalizeProfile(profile) {
1753
1774
  };
1754
1775
  }),
1755
1776
  fallback: destination(profile.fallback),
1756
- ...profile.dns === void 0 ? {} : { dns: profile.dns },
1777
+ ...profile.dns === void 0 ? {} : { dns: profile.dns.map(({ pattern, server }) => ({
1778
+ pattern,
1779
+ server: typeof server === "string" ? server : {
1780
+ ...server,
1781
+ endpoint: server.endpoint.id
1782
+ }
1783
+ })) },
1757
1784
  ...extension
1758
1785
  }));
1759
1786
  }
1760
- //#endregion
1761
- //#region src/model/errors.ts
1787
+ // src/model/errors.ts
1762
1788
  var RenderError = class extends Error {
1763
1789
  code;
1764
1790
  constructor(code) {
@@ -1767,8 +1793,7 @@ var RenderError = class extends Error {
1767
1793
  this.name = "RenderError";
1768
1794
  }
1769
1795
  };
1770
- //#endregion
1771
- //#region src/model/proxy-values.ts
1796
+ // src/model/proxy-values.ts
1772
1797
  function uuid(token, secret) {
1773
1798
  const value = secret(token);
1774
1799
  if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(value)) throw new RenderError("INVALID_UUID_SECRET");
@@ -1787,8 +1812,7 @@ function aliasProxyServer(node, aliases) {
1787
1812
  server
1788
1813
  };
1789
1814
  }
1790
- //#endregion
1791
- //#region src/engines/surge/proxies.ts
1815
+ // src/engines/surge/proxies.ts
1792
1816
  function surgeProxy(node, secret, name = (id) => id) {
1793
1817
  const atom = (value) => {
1794
1818
  if (!/^[A-Za-z0-9_./:@+%-]+$/.test(value)) throw new RenderError("SURGE_VALUE_UNREPRESENTABLE");
@@ -1800,9 +1824,11 @@ function surgeProxy(node, secret, name = (id) => id) {
1800
1824
  String(node.port)
1801
1825
  ];
1802
1826
  switch (node.type) {
1827
+ case "socks5":
1803
1828
  case "http":
1804
1829
  if (node.username) params.push(`username=${atom(secret(node.username))}`);
1805
1830
  params.push(`password=${atom(secret(node.password))}`);
1831
+ if (node.type === "http" && node.surge?.testUrl) params.push(`test-url=${node.surge.testUrl}`);
1806
1832
  break;
1807
1833
  case "hysteria2":
1808
1834
  params.push(`password=${atom(secret(node.password))}`);
@@ -1834,12 +1860,11 @@ function surgeProxy(node, secret, name = (id) => id) {
1834
1860
  if (node.tcpFastOpen !== void 0) params.push(`tfo=${node.tcpFastOpen}`);
1835
1861
  if (node.type === "trojan" || node.type === "anytls" && node.surge?.udpRelay) params.push("udp-relay=true");
1836
1862
  if (node.type === "shadowsocks") params.push(`udp-relay=${node.surge?.udpRelay ?? true}`, `block-quic=${node.surge?.blockQuic ?? "off"}`);
1837
- 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}`);
1838
1864
  if (node.via) params.push(`underlying-proxy=${name(node.via)}`);
1839
1865
  return params.join(", ");
1840
1866
  }
1841
- //#endregion
1842
- //#region src/targets/proxies.ts
1867
+ // src/targets/proxies.ts
1843
1868
  function validateProxyOptions(node, target, diagnostics) {
1844
1869
  if (node.type === "hysteria2") {
1845
1870
  if (target.engine === "surge" && node.portHopping && node.via) diagnostics.push({
@@ -1884,8 +1909,7 @@ function validateProxyOptions(node, target, diagnostics) {
1884
1909
  message: "Surge 编码不接受特殊 SNI off 或显式 ALPN;不会丢弃 TLS 选项"
1885
1910
  });
1886
1911
  }
1887
- //#endregion
1888
- //#region src/engines/surge/profile.ts
1912
+ // src/engines/surge/profile.ts
1889
1913
  const plans = /* @__PURE__ */ new WeakMap();
1890
1914
  function compileSurgeProfile(input) {
1891
1915
  const diagnostics = [];
@@ -2109,6 +2133,8 @@ function renderProfile(compilation, read) {
2109
2133
  for (const g of p.groups) lines.push(`${name(g.id)} = ${[
2110
2134
  g.type,
2111
2135
  ...g.members.map(action),
2136
+ ...g.hidden !== void 0 ? [`hidden=${g.hidden}`] : [],
2137
+ ...g.category ? [`category=${g.category}`] : [],
2112
2138
  ...g.url ? [`url=${g.url}`] : [],
2113
2139
  ...g.intervalSeconds !== void 0 ? [`interval=${g.intervalSeconds}`] : [],
2114
2140
  ...g.timeoutSeconds !== void 0 ? [`timeout=${g.timeoutSeconds}`] : []
@@ -2130,8 +2156,7 @@ function renderSurgeProfiles(compilations, resolveSecret) {
2130
2156
  const read = resolveSecret;
2131
2157
  return deepFreeze(compilations.map((c) => renderProfile(c, read)));
2132
2158
  }
2133
- //#endregion
2134
- //#region src/model/normalize-surge.ts
2159
+ // src/model/normalize-surge.ts
2135
2160
  const outbound = {
2136
2161
  direct: { builtin: "DIRECT" },
2137
2162
  reject: { builtin: "REJECT" },
@@ -2197,6 +2222,7 @@ function lowerSurgeProfile(input) {
2197
2222
  if (!definition.algorithm || ![
2198
2223
  "select",
2199
2224
  "surge-smart",
2225
+ "surge-fallback",
2200
2226
  "auto"
2201
2227
  ].includes(definition.algorithm.type)) fail("UNSUPPORTED_GROUP_ALGORITHM");
2202
2228
  exactDefinition(definition.algorithm, ["type"]);
@@ -2204,7 +2230,7 @@ function lowerSurgeProfile(input) {
2204
2230
  const { id } = definition;
2205
2231
  return {
2206
2232
  id,
2207
- type: definition.algorithm.type === "select" ? "select" : "smart",
2233
+ type: definition.algorithm.type === "surge-fallback" ? "fallback" : definition.algorithm.type === "select" ? "select" : "smart",
2208
2234
  members: definition.members.map(lower),
2209
2235
  ...definition.surge
2210
2236
  };
@@ -2269,10 +2295,14 @@ function normalizeSurgeProfile(p) {
2269
2295
  const tunnels = p.proxies.filter((x) => ["tailscale", "wireguard"].includes(x.type));
2270
2296
  if (p.proxies.some((x) => x.type === "sing-box-tailscale")) throw new ProfileDefinitionError("PROFILE_ENDPOINT_UNSUPPORTED");
2271
2297
  const groups = p.groups;
2298
+ const dns = p.dns?.flatMap(({ pattern, server }) => typeof server === "string" ? [{
2299
+ pattern,
2300
+ server
2301
+ }] : []);
2272
2302
  return lowerSurgeProfile({
2273
2303
  target: p.target,
2274
2304
  ...p.surge,
2275
- ...p.dns?.length ? { hosts: [...p.dns, ...p.surge?.hosts ?? []] } : {},
2305
+ ...dns?.length ? { hosts: [...dns, ...p.surge?.hosts ?? []] } : {},
2276
2306
  nodes: nodes.map((n) => {
2277
2307
  const { name: _name, ...rest } = n;
2278
2308
  return {
@@ -2293,15 +2323,13 @@ function normalizeSurgeProfile(p) {
2293
2323
  fallback: p.fallback
2294
2324
  });
2295
2325
  }
2296
- //#endregion
2297
- //#region src/model/semantics.ts
2326
+ // src/model/semantics.ts
2298
2327
  const singboxMemberTag = (id) => id === "DIRECT" ? "pl-direct" : id === "REJECT" ? "pl-reject" : id;
2299
2328
  /** Only top-level atoms (or transparent named wrappers) can request ordered DNS. */
2300
2329
  function needsResolve(condition) {
2301
2330
  return condition.type === "ipCidr" && condition.noResolve !== true || condition.type === "nativeRuleSet" && condition.engine === "sing-box" && condition.resolve === true;
2302
2331
  }
2303
- //#endregion
2304
- //#region src/engines/sing-box/groups.ts
2332
+ // src/engines/sing-box/groups.ts
2305
2333
  function singboxGroup(group, name = (id) => id) {
2306
2334
  if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
2307
2335
  return group.type === "select" ? {
@@ -2321,11 +2349,10 @@ function singboxGroup(group, name = (id) => id) {
2321
2349
  interrupt_exist_connections: false
2322
2350
  };
2323
2351
  }
2324
- //#endregion
2325
- //#region src/engines/sing-box/proxies.ts
2352
+ // src/engines/sing-box/proxies.ts
2326
2353
  function singboxProxy(node, secret) {
2327
2354
  const result = {
2328
- type: node.type,
2355
+ type: node.type === "socks5" ? "socks" : node.type,
2329
2356
  tag: node.id,
2330
2357
  server: node.server,
2331
2358
  server_port: node.port,
@@ -2346,6 +2373,7 @@ function singboxProxy(node, secret) {
2346
2373
  }
2347
2374
  if (node.portHoppingInterval !== void 0) result.hop_interval = `${node.portHoppingInterval}s`;
2348
2375
  break;
2376
+ case "socks5":
2349
2377
  case "http":
2350
2378
  result.password = secret(node.password);
2351
2379
  if (node.username) result.username = secret(node.username);
@@ -2401,8 +2429,7 @@ function singboxProxy(node, secret) {
2401
2429
  }
2402
2430
  return result;
2403
2431
  }
2404
- //#endregion
2405
- //#region src/engines/sing-box/render.ts
2432
+ // src/engines/sing-box/render.ts
2406
2433
  const DIRECT = "pl-direct";
2407
2434
  const DNS = "pl-dns";
2408
2435
  const actionTag = (a, name) => a.type === "route" ? name(a.to) : a.type === "direct" ? DIRECT : "pl-reject";
@@ -2566,9 +2593,25 @@ function singbox(plan, secret) {
2566
2593
  server: "127.0.0.1",
2567
2594
  server_port: model.listener.port
2568
2595
  });
2596
+ const tailscaleDnsTags = /* @__PURE__ */ new Map();
2569
2597
  dns.rules = model.dns.map((rule, index) => {
2570
2598
  const tag = `pl-domain-dns-${index}`;
2571
- if (isIP(rule.server)) dns.servers.push({
2599
+ const condition = dnsCondition(rule);
2600
+ if (typeof rule.server !== "string") {
2601
+ const { endpoint, acceptDefaultResolvers } = rule.server;
2602
+ const existing = tailscaleDnsTags.get(endpoint);
2603
+ if (existing !== void 0) return {
2604
+ ...condition,
2605
+ server: existing
2606
+ };
2607
+ tailscaleDnsTags.set(endpoint, tag);
2608
+ dns.servers.push({
2609
+ type: "tailscale",
2610
+ tag,
2611
+ endpoint: name(endpoint),
2612
+ ...acceptDefaultResolvers === void 0 ? {} : { accept_default_resolvers: acceptDefaultResolvers }
2613
+ });
2614
+ } else if (isIP(rule.server)) dns.servers.push({
2572
2615
  type: "udp",
2573
2616
  tag,
2574
2617
  server: rule.server,
@@ -2590,7 +2633,7 @@ function singbox(plan, secret) {
2590
2633
  });
2591
2634
  }
2592
2635
  return {
2593
- ...dnsCondition(rule),
2636
+ ...condition,
2594
2637
  server: tag
2595
2638
  };
2596
2639
  });
@@ -2617,8 +2660,7 @@ function singbox(plan, secret) {
2617
2660
  }
2618
2661
  return config;
2619
2662
  }
2620
- //#endregion
2621
- //#region src/engines/mihomo/proxies.ts
2663
+ // src/engines/mihomo/proxies.ts
2622
2664
  function clashProxy$1(node, secret, name = (id) => id) {
2623
2665
  const result = {
2624
2666
  name: name(node.id),
@@ -2635,6 +2677,7 @@ function clashProxy$1(node, secret, name = (id) => id) {
2635
2677
  if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
2636
2678
  if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
2637
2679
  break;
2680
+ case "socks5":
2638
2681
  case "http":
2639
2682
  result.password = secret(node.password);
2640
2683
  if (node.username) result.username = secret(node.username);
@@ -2673,8 +2716,7 @@ function clashProxy$1(node, secret, name = (id) => id) {
2673
2716
  }
2674
2717
  return result;
2675
2718
  }
2676
- //#endregion
2677
- //#region src/engines/mihomo/render.ts
2719
+ // src/engines/mihomo/render.ts
2678
2720
  function clashGroup$1(group, name = (id) => id) {
2679
2721
  if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
2680
2722
  return {
@@ -2746,8 +2788,7 @@ function clashConfig$1(plan, secret) {
2746
2788
  }
2747
2789
  return config;
2748
2790
  }
2749
- //#endregion
2750
- //#region src/engines/stash/proxies.ts
2791
+ // src/engines/stash/proxies.ts
2751
2792
  function clashProxy(node, secret, name = (id) => id) {
2752
2793
  const result = {
2753
2794
  name: name(node.id),
@@ -2765,6 +2806,7 @@ function clashProxy(node, secret, name = (id) => id) {
2765
2806
  if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
2766
2807
  if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
2767
2808
  break;
2809
+ case "socks5":
2768
2810
  case "http":
2769
2811
  result.password = secret(node.password);
2770
2812
  if (node.username) result.username = secret(node.username);
@@ -2803,8 +2845,7 @@ function clashProxy(node, secret, name = (id) => id) {
2803
2845
  }
2804
2846
  return result;
2805
2847
  }
2806
- //#endregion
2807
- //#region src/engines/stash/render.ts
2848
+ // src/engines/stash/render.ts
2808
2849
  function clashGroup(group, name = (id) => id) {
2809
2850
  if (group.type !== "select" && group.type !== "urltest") throw new Error("GROUP_UNSUPPORTED");
2810
2851
  return {
@@ -2876,8 +2917,7 @@ function clashConfig(plan, secret) {
2876
2917
  }
2877
2918
  return config;
2878
2919
  }
2879
- //#endregion
2880
- //#region src/engines/sing-box/check.ts
2920
+ // src/engines/sing-box/check.ts
2881
2921
  function engineChecks$2(model) {
2882
2922
  const t = model.target;
2883
2923
  return {
@@ -2900,8 +2940,7 @@ function engineChecks$2(model) {
2900
2940
  }
2901
2941
  };
2902
2942
  }
2903
- //#endregion
2904
- //#region src/engines/mihomo/check.ts
2943
+ // src/engines/mihomo/check.ts
2905
2944
  function engineChecks$1(model) {
2906
2945
  const t = model.target;
2907
2946
  return {
@@ -2922,8 +2961,7 @@ function engineChecks$1(model) {
2922
2961
  }
2923
2962
  };
2924
2963
  }
2925
- //#endregion
2926
- //#region src/engines/stash/check.ts
2964
+ // src/engines/stash/check.ts
2927
2965
  function engineChecks(model) {
2928
2966
  const t = model.target;
2929
2967
  return {
@@ -2946,8 +2984,7 @@ function engineChecks(model) {
2946
2984
  }
2947
2985
  };
2948
2986
  }
2949
- //#endregion
2950
- //#region src/targets/catalog.ts
2987
+ // src/targets/catalog.ts
2951
2988
  const targetCatalog = deepFreeze([
2952
2989
  {
2953
2990
  engine: "sing-box",
@@ -2958,6 +2995,7 @@ const targetCatalog = deepFreeze([
2958
2995
  "hysteria2",
2959
2996
  "trojan",
2960
2997
  "http",
2998
+ "socks5",
2961
2999
  "anytls",
2962
3000
  "shadowsocks",
2963
3001
  "vmess",
@@ -2977,12 +3015,17 @@ const targetCatalog = deepFreeze([
2977
3015
  "hysteria2",
2978
3016
  "trojan",
2979
3017
  "http",
3018
+ "socks5",
2980
3019
  "anytls",
2981
3020
  "shadowsocks",
2982
3021
  "vmess"
2983
3022
  ],
2984
3023
  endpoints: [],
2985
- groups: ["select", "surge-smart"],
3024
+ groups: [
3025
+ "select",
3026
+ "surge-smart",
3027
+ "surge-fallback"
3028
+ ],
2986
3029
  nativeRuleSets: ["rule-set", "domain-set"],
2987
3030
  dns: "general"
2988
3031
  },
@@ -2995,12 +3038,17 @@ const targetCatalog = deepFreeze([
2995
3038
  "hysteria2",
2996
3039
  "trojan",
2997
3040
  "http",
3041
+ "socks5",
2998
3042
  "anytls",
2999
3043
  "shadowsocks",
3000
3044
  "vmess"
3001
3045
  ],
3002
3046
  endpoints: [],
3003
- groups: ["select", "surge-smart"],
3047
+ groups: [
3048
+ "select",
3049
+ "surge-smart",
3050
+ "surge-fallback"
3051
+ ],
3004
3052
  nativeRuleSets: ["rule-set", "domain-set"],
3005
3053
  dns: "general"
3006
3054
  },
@@ -3013,6 +3061,7 @@ const targetCatalog = deepFreeze([
3013
3061
  "hysteria2",
3014
3062
  "trojan",
3015
3063
  "http",
3064
+ "socks5",
3016
3065
  "anytls",
3017
3066
  "shadowsocks",
3018
3067
  "vmess",
@@ -3032,6 +3081,7 @@ const targetCatalog = deepFreeze([
3032
3081
  "hysteria2",
3033
3082
  "trojan",
3034
3083
  "http",
3084
+ "socks5",
3035
3085
  "anytls",
3036
3086
  "shadowsocks",
3037
3087
  "vmess",
@@ -3043,13 +3093,12 @@ const targetCatalog = deepFreeze([
3043
3093
  dns: "external"
3044
3094
  }
3045
3095
  ]);
3046
- //#endregion
3047
- //#region src/model/paths.ts
3096
+ // src/model/paths.ts
3048
3097
  function pathsOverlap(a, b) {
3098
+ if (a.startsWith("/") !== b.startsWith("/")) return false;
3049
3099
  return a === b || a.startsWith(b.endsWith("/") ? b : `${b}/`) || b.startsWith(a.endsWith("/") ? a : `${a}/`);
3050
3100
  }
3051
- //#endregion
3052
- //#region src/targets/check.ts
3101
+ // src/targets/check.ts
3053
3102
  function checkTarget(model, checks) {
3054
3103
  const diagnostics = [];
3055
3104
  const error = (code, path) => diagnostics.push({
@@ -3073,7 +3122,7 @@ function checkTarget(model, checks) {
3073
3122
  for (const [id, refs] of edges) for (const [index, ref] of refs.entries()) {
3074
3123
  const path = registry.get(id)?.type === "select" || registry.get(id)?.type === "urltest" ? `groups.${id}.members[${index}]` : `proxies.${id}.via`;
3075
3124
  if (!registry.has(ref) && !["DIRECT", "REJECT"].includes(ref)) error("MISSING_REFERENCE", path);
3076
- if (registry.get(ref)?.type === "sing-box-tailscale") error("ENDPOINT_REFERENCE_UNSUPPORTED", path);
3125
+ if (registry.get(ref)?.type === "sing-box-tailscale" && (t.engine !== "sing-box" || t.mode !== "standalone" || registry.get(id)?.type !== "select")) error("ENDPOINT_REFERENCE_UNSUPPORTED", path);
3077
3126
  }
3078
3127
  const state = /* @__PURE__ */ new Map(), tcp = /* @__PURE__ */ new Map();
3079
3128
  const visit = (id) => {
@@ -3151,8 +3200,7 @@ function checkTarget(model, checks) {
3151
3200
  }
3152
3201
  };
3153
3202
  }
3154
- //#endregion
3155
- //#region src/build/plans.ts
3203
+ // src/build/plans.ts
3156
3204
  function prepareProfile(input, key, secrets, checkSecrets = true) {
3157
3205
  let engine = "surge";
3158
3206
  const collected = [];
@@ -3294,8 +3342,7 @@ function diagnosticOrigin(p, path) {
3294
3342
  if (resource) return originOf([...p.proxies, ...p.groups].find((r) => r.id === resource[1])) ?? originOf(p);
3295
3343
  return originOf(p);
3296
3344
  }
3297
- //#endregion
3298
- //#region src/build/secrets.ts
3345
+ // src/build/secrets.ts
3299
3346
  const failures = /* @__PURE__ */ new WeakMap();
3300
3347
  function secretFailure(error) {
3301
3348
  return error && typeof error === "object" ? failures.get(error) ?? {} : {};
@@ -3322,8 +3369,7 @@ function secretReader(secrets, validation) {
3322
3369
  return value;
3323
3370
  };
3324
3371
  }
3325
- //#endregion
3326
- //#region src/build/publish.ts
3372
+ // src/build/publish.ts
3327
3373
  var SurgePublishError = class extends Error {
3328
3374
  published;
3329
3375
  constructor(message, published) {
@@ -3418,8 +3464,7 @@ async function publishProfiles(files, surgeDirectory, io = { rename }) {
3418
3464
  }
3419
3465
  if (failure) throw new SurgePublishError(failure.message === "PROFILE_PUBLISH_CLEANUP_FAILED" ? committed ? "PUBLISHED_CLEANUP_FAILED" : "FAILED_CLEANUP_REQUIRED" : failure.message, committed);
3420
3466
  }
3421
- //#endregion
3422
- //#region src/build/explain.ts
3467
+ // src/build/explain.ts
3423
3468
  function explainProfile(profile, request, assume) {
3424
3469
  if (kindOf(profile) !== "profile") return {
3425
3470
  ok: false,
@@ -3457,8 +3502,7 @@ function explainProfile(profile, request, assume) {
3457
3502
  explanation: evaluate(prepared.routing, parsed, assumptions.values)
3458
3503
  };
3459
3504
  }
3460
- //#endregion
3461
- //#region src/build/index.ts
3505
+ // src/build/index.ts
3462
3506
  function compile(definition) {
3463
3507
  if (kindOf(definition) !== "build") throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
3464
3508
  const entries = Object.entries(definition.profiles);
@@ -3579,5 +3623,4 @@ async function runBuild(definition, options = {}) {
3579
3623
  };
3580
3624
  }
3581
3625
  }
3582
- //#endregion
3583
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-TmM3uIDQ.js";
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
- //#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
  } | {
@@ -165,9 +173,13 @@ type GroupAlgorithm = {
165
173
  readonly intervalSeconds?: number;
166
174
  readonly toleranceMs?: number;
167
175
  };
168
- type DnsRule = {
176
+ type DnsRule<Server = string> = {
169
177
  readonly pattern: string;
170
- readonly server: string;
178
+ readonly server: Server;
179
+ };
180
+ type TailscaleDnsServer<Endpoint> = {
181
+ readonly endpoint: Endpoint;
182
+ readonly acceptDefaultResolvers?: boolean;
171
183
  };
172
184
  type Tun = {
173
185
  readonly address: readonly string[];
@@ -189,8 +201,6 @@ type Diagnostic = {
189
201
  type ProfileDiagnostic = Omit<Diagnostic, "target" | "profile"> & {
190
202
  readonly profile: string;
191
203
  };
192
- //#endregion
193
- //#region src/model/routing-types.d.ts
194
204
  type RouteRequest = {
195
205
  readonly network?: "tcp" | "udp";
196
206
  readonly domain?: string;
@@ -253,8 +263,6 @@ type CaseResult = {
253
263
  readonly needs?: Need;
254
264
  readonly route?: Explanation["route"];
255
265
  };
256
- //#endregion
257
- //#region src/model/surge-schema.d.ts
258
266
  declare const policy: z.ZodUnion<readonly [z.ZodObject<{
259
267
  ref: z.ZodString;
260
268
  }, z.core.$strict>, z.ZodObject<{
@@ -348,6 +356,7 @@ type SurgeTunnel$1 = z.infer<typeof tunnelSchema>;
348
356
  declare const groupSchema: z.ZodObject<{
349
357
  id: z.ZodString;
350
358
  type: z.ZodEnum<{
359
+ fallback: "fallback";
351
360
  select: "select";
352
361
  smart: "smart";
353
362
  }>;
@@ -362,6 +371,8 @@ declare const groupSchema: z.ZodObject<{
362
371
  "REJECT-TINYGIF": "REJECT-TINYGIF";
363
372
  }>;
364
373
  }, z.core.$strict>]>>;
374
+ hidden: z.ZodOptional<z.ZodBoolean>;
375
+ category: z.ZodOptional<z.ZodString>;
365
376
  url: z.ZodOptional<z.ZodString>;
366
377
  intervalSeconds: z.ZodOptional<z.ZodNumber>;
367
378
  timeoutSeconds: z.ZodOptional<z.ZodNumber>;
@@ -429,8 +440,6 @@ type SurgeProfileInput = {
429
440
  readonly fallback: SurgePolicy;
430
441
  readonly names?: Readonly<Record<string, string>>;
431
442
  };
432
- //#endregion
433
- //#region src/model/profile-types.d.ts
434
443
  type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
435
444
  type Fragments<T> = T | readonly Fragments<T>[];
436
445
  type Target = {
@@ -469,7 +478,9 @@ type ProxyGroup<A extends GroupAlgorithm = GroupAlgorithm> = {
469
478
  readonly algorithm: A;
470
479
  readonly members: readonly Exit[];
471
480
  readonly surge?: {
472
- readonly url: string;
481
+ readonly hidden?: boolean;
482
+ readonly category?: string;
483
+ readonly url?: string;
473
484
  readonly intervalSeconds?: number;
474
485
  readonly timeoutSeconds?: number;
475
486
  };
@@ -480,6 +491,8 @@ type SurgeTunnel = PublicSecrets<SurgeTunnel$1> & {
480
491
  type SingBoxEndpoint = PublicSecrets<TailscaleEndpoint> & {
481
492
  readonly name?: string;
482
493
  } & SDK<"endpoint">;
494
+ type TailscaleDnsOptions = TailscaleDnsServer<SingBoxEndpoint>;
495
+ type ProfileDnsRule = DnsRule<string | TailscaleDnsOptions>;
483
496
  type Builtin = {
484
497
  readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
485
498
  } & SDK<"builtin">;
@@ -549,13 +562,13 @@ type SingBoxOptions = {
549
562
  };
550
563
  type Common = {
551
564
  readonly cases?: Fragments<RouteCase>;
552
- readonly dns?: Fragments<DnsRule>;
565
+ readonly dns?: Fragments<ProfileDnsRule>;
553
566
  readonly proxies: Fragments<ProfileProxy>;
554
567
  readonly routes: Fragments<Route>;
555
568
  readonly fallback: Exit;
556
569
  };
557
570
  type Portable = Exclude<GroupAlgorithm, {
558
- type: "surge-smart";
571
+ type: "surge-smart" | "surge-fallback";
559
572
  }>;
560
573
  type ProfileDefinition = Common & ({
561
574
  readonly target: Extract<Target, {
@@ -603,7 +616,7 @@ type FlattenedProfile<D extends ProfileDefinition> = D extends ProfileDefinition
603
616
  };
604
617
  } ? ProxyGroup : ProxyGroup<Portable>)[];
605
618
  readonly routes: readonly Route[];
606
- readonly dns: readonly DnsRule[];
619
+ readonly dns: readonly ProfileDnsRule[];
607
620
  readonly cases: readonly RouteCase[];
608
621
  readonly surge?: D extends {
609
622
  target: {
@@ -612,11 +625,7 @@ type FlattenedProfile<D extends ProfileDefinition> = D extends ProfileDefinition
612
625
  } ? ResolvedSurge : never;
613
626
  } : never;
614
627
  type Profile<D extends ProfileDefinition = ProfileDefinition> = FlattenedProfile<D> & SDK<"profile">;
615
- //#endregion
616
- //#region src/authoring/profile.d.ts
617
628
  export declare function defineProfile<const D extends ProfileDefinition>(input: D): Profile<D>;
618
- //#endregion
619
- //#region src/authoring/resources.d.ts
620
629
  export declare const outbound: {
621
630
  direct: {
622
631
  builtin: "DIRECT";
@@ -645,8 +654,6 @@ export declare function defineRoutes(input: {
645
654
  readonly when: Fragments<Condition>;
646
655
  readonly to: Exit;
647
656
  }): Route[];
648
- //#endregion
649
- //#region src/authoring/proxy-builder.d.ts
650
657
  type ProxyBuilder<N extends ProxyNode> = {
651
658
  readonly via: (exit: ProxyNode | ProxyGroup) => ProxyBuilder<N>;
652
659
  readonly name: (text: string) => ProxyBuilder<N>;
@@ -654,10 +661,10 @@ type ProxyBuilder<N extends ProxyNode> = {
654
661
  readonly build: () => N;
655
662
  };
656
663
  declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<N>;
657
- //#endregion
658
- //#region src/authoring/constructors.d.ts
659
664
  export declare function dnsRule(pattern: string, server: string): DnsRule;
660
665
  export declare function dnsRule(pattern: readonly string[], server: string): DnsRule[];
666
+ export declare function dnsRule(pattern: string, server: TailscaleDnsOptions): DnsRule<TailscaleDnsOptions>;
667
+ export declare function dnsRule(pattern: readonly string[], server: TailscaleDnsOptions): DnsRule<TailscaleDnsOptions>[];
661
668
  type DomainOptions = {
662
669
  readonly includeSniffed?: boolean;
663
670
  };
@@ -757,6 +764,33 @@ export declare const group: {
757
764
  type Input<T extends object> = Omit<T, "type" | keyof SDK<string>>;
758
765
  export declare const proxy: {
759
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">;
760
794
  http: (input: Input<Omit<{
761
795
  readonly id: string;
762
796
  readonly server: string;
@@ -764,6 +798,9 @@ export declare const proxy: {
764
798
  readonly via?: string;
765
799
  readonly tcpFastOpen?: boolean;
766
800
  readonly type: "http";
801
+ readonly surge?: {
802
+ readonly testUrl: string;
803
+ } | undefined;
767
804
  readonly serverName?: never;
768
805
  readonly password: SecretRef;
769
806
  readonly username?: SecretRef | undefined;
@@ -777,6 +814,9 @@ export declare const proxy: {
777
814
  readonly via?: string;
778
815
  readonly tcpFastOpen?: boolean;
779
816
  readonly type: "http";
817
+ readonly surge?: {
818
+ readonly testUrl: string;
819
+ } | undefined;
780
820
  readonly serverName?: never;
781
821
  readonly password: SecretRef;
782
822
  readonly username?: SecretRef | undefined;
@@ -1064,6 +1104,9 @@ export declare const surge: {
1064
1104
  builtin: "SYSTEM";
1065
1105
  } & SDK<"ruleSet">;
1066
1106
  };
1107
+ fallback: () => {
1108
+ type: "surge-fallback";
1109
+ } & SDK<"algorithm">;
1067
1110
  smart: () => {
1068
1111
  type: "surge-smart";
1069
1112
  } & SDK<"algorithm">;
@@ -1129,8 +1172,6 @@ export declare const surge: {
1129
1172
  export declare const singbox: {
1130
1173
  tailscale: (input: Input<SingBoxEndpoint>) => SingBoxEndpoint;
1131
1174
  };
1132
- //#endregion
1133
- //#region src/authoring/secret-inputs.d.ts
1134
1175
  type Source = ({
1135
1176
  readonly env: string;
1136
1177
  readonly value?: never;
@@ -1141,31 +1182,24 @@ type Source = ({
1141
1182
  readonly validation?: string;
1142
1183
  };
1143
1184
  export declare function defineSecrets<const T extends Record<string, Source>>(input: T): Secrets<Extract<keyof T, string>>;
1144
- //#endregion
1145
- //#region src/authoring/proxy-id.d.ts
1146
1185
  /** Stable identity independent of engine and mutable metadata. */
1147
1186
  export declare function proxyId(namespace: string, name: string): string;
1148
- //#endregion
1149
- //#region src/model/build-types.d.ts
1150
1187
  type BuildDefinition = {
1151
1188
  readonly outDir?: string;
1152
1189
  readonly profiles: Readonly<Record<string, Profile>>;
1153
1190
  readonly secrets?: Secrets;
1154
1191
  } & SDK<"build">;
1155
- //#endregion
1156
- //#region src/authoring/build.d.ts
1157
1192
  /** Capture the immutable batch before any secret source is invoked. */
1158
1193
  export declare function defineBuild(input: Omit<BuildDefinition, keyof SDK<"build">>): BuildDefinition;
1159
- //#endregion
1160
- //#region src/model/definitions.d.ts
1161
1194
  export declare class ProfileDefinitionError extends Error {
1162
1195
  readonly code: string;
1163
1196
  readonly paths?: readonly string[];
1164
1197
  readonly origin?: Origin;
1165
1198
  constructor(code: string, paths?: readonly string[]);
1166
1199
  }
1167
- //#endregion
1168
- //#region src/authoring/index.d.ts
1200
+ export type Socks5Node = Extract<ProxyNode, {
1201
+ type: "socks5";
1202
+ }>;
1169
1203
  export type HttpNode = Extract<ProxyNode, {
1170
1204
  type: "http";
1171
1205
  }>;
@@ -1187,8 +1221,6 @@ export type VMessNode = Extract<ProxyNode, {
1187
1221
  export type VLESSNode = Extract<ProxyNode, {
1188
1222
  type: "vless";
1189
1223
  }>;
1190
- //#endregion
1191
- //#region src/model/inspect-profile.d.ts
1192
1224
  type Selection = {
1193
1225
  kind: "name";
1194
1226
  resource: string;
@@ -1204,11 +1236,7 @@ type Selection = {
1204
1236
  branch: "surge" | "singBox" | "mihomo";
1205
1237
  nativeName: string;
1206
1238
  };
1207
- //#endregion
1208
- //#region src/build/explain.d.ts
1209
1239
  export declare function explainProfile(profile: Profile, request: RouteRequest, assume?: Assumptions): ExplainResult;
1210
- //#endregion
1211
- //#region src/build/index.d.ts
1212
1240
  type CheckResult = {
1213
1241
  readonly ok: boolean;
1214
1242
  readonly code: "CHECKED" | "CHECK_FAILED" | "CASE_FAILED";
@@ -1235,5 +1263,4 @@ export declare function checkBuild(definition: BuildDefinition): CheckResult;
1235
1263
  export declare function runBuild(definition: BuildDefinition, options?: {
1236
1264
  readonly validation?: boolean;
1237
1265
  }): Promise<BuildResult>;
1238
- //#endregion
1239
- 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, Target };
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-TmM3uIDQ.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-Dlv1JO0_.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.14.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": "^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
  }