proxylang 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { K as requestSchema, L as targetCatalog, M as compile, N as explain, V as StaticRuleSetUnknownError, i as buildToDirectory, n as defineBuild, r as runBuild, t as checkBuild } from "./profile-build-Dg7xfQbi.js";
2
+ import { K as requestSchema, L as targetCatalog, M as compile, N as explain, V as StaticRuleSetUnknownError, Z as definitionDiagnostic, i as buildToDirectory, n as defineBuild, r as runBuild, t as checkBuild } from "./profile-build-B04BpEx3.js";
3
3
  import { lstat, open, stat } from "node:fs/promises";
4
4
  import { resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
@@ -41,6 +41,17 @@ async function readRequestFile(path) {
41
41
  }
42
42
  }
43
43
  function loadFailure(cause) {
44
+ const diagnostic = definitionDiagnostic(cause);
45
+ if (diagnostic) {
46
+ print({
47
+ ok: false,
48
+ code: "CONFIG_LOAD_FAILED",
49
+ reason: "INVALID_CONFIGURATION",
50
+ diagnostic,
51
+ hint: "检查配置字段与库定义约束"
52
+ });
53
+ return 1;
54
+ }
44
55
  let code;
45
56
  let name;
46
57
  try {
package/dist/index.d.ts CHANGED
@@ -129,6 +129,15 @@ export type AnyTLSNode = ProxyBase & {
129
129
  readonly skipCertVerify?: boolean;
130
130
  readonly surge?: SurgeAutomaticUdpOptions;
131
131
  };
132
+ export type Hysteria2Node = Omit<ProxyBase, "tcpFastOpen"> & {
133
+ readonly type: "hysteria2";
134
+ readonly tcpFastOpen?: never;
135
+ readonly password: Secret;
136
+ readonly serverName?: string;
137
+ readonly skipCertVerify?: boolean;
138
+ readonly portHopping?: string;
139
+ readonly portHoppingInterval?: number;
140
+ };
132
141
  export type HttpNode = ProxyBase & {
133
142
  readonly type: "http";
134
143
  readonly serverName?: never;
@@ -154,7 +163,7 @@ export type VLESSNode = ProxyBase & {
154
163
  readonly tls?: ProxyTLS;
155
164
  readonly transport?: WebSocketTransport;
156
165
  };
157
- export type ProxyNode = TrojanNode | AnyTLSNode | HttpNode | ShadowsocksNode | VMessNode | VLESSNode;
166
+ export type ProxyNode = TrojanNode | AnyTLSNode | Hysteria2Node | HttpNode | ShadowsocksNode | VMessNode | VLESSNode;
158
167
  export type TailscaleEndpoint = {
159
168
  readonly type: "sing-box-tailscale";
160
169
  readonly id: string;
@@ -523,7 +532,7 @@ export declare const targetCatalog: readonly [{
523
532
  readonly version: "1.11.0";
524
533
  readonly autoGroup: "urltest";
525
534
  readonly platforms: readonly ["linux", "macos"];
526
- readonly protocols: readonly ["trojan", "http", "shadowsocks", "vmess", "vless"];
535
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "shadowsocks", "vmess", "vless"];
527
536
  readonly endpoints: readonly [];
528
537
  readonly groups: readonly ["select", "urltest"];
529
538
  readonly nativeRuleSets: readonly ["source", "binary"];
@@ -533,7 +542,7 @@ export declare const targetCatalog: readonly [{
533
542
  readonly version: "1.12.0";
534
543
  readonly autoGroup: "urltest";
535
544
  readonly platforms: readonly ["linux", "macos"];
536
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
545
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
537
546
  readonly endpoints: readonly ["sing-box-tailscale"];
538
547
  readonly groups: readonly ["select", "urltest"];
539
548
  readonly nativeRuleSets: readonly ["source", "binary"];
@@ -543,7 +552,7 @@ export declare const targetCatalog: readonly [{
543
552
  readonly version: "6.10.0";
544
553
  readonly autoGroup: "surge-smart";
545
554
  readonly platforms: readonly ["macos"];
546
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
555
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess"];
547
556
  readonly endpoints: readonly [];
548
557
  readonly groups: readonly ["select", "surge-smart"];
549
558
  readonly nativeRuleSets: readonly ["rule-set", "domain-set"];
@@ -553,7 +562,7 @@ export declare const targetCatalog: readonly [{
553
562
  readonly version: "1.19.32";
554
563
  readonly autoGroup: "urltest";
555
564
  readonly platforms: readonly ["linux", "macos"];
556
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
565
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
557
566
  readonly endpoints: readonly [];
558
567
  readonly groups: readonly ["select", "urltest"];
559
568
  readonly nativeRuleSets: readonly ["yaml", "text"];
@@ -563,7 +572,7 @@ export declare const targetCatalog: readonly [{
563
572
  readonly version: "4.2.1";
564
573
  readonly autoGroup: null;
565
574
  readonly platforms: readonly ["macos"];
566
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
575
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess"];
567
576
  readonly endpoints: readonly [];
568
577
  readonly groups: readonly ["select"];
569
578
  readonly nativeRuleSets: readonly [];
@@ -626,7 +635,8 @@ type RouteDefinition = {
626
635
  };
627
636
  export declare class ProfileDefinitionError extends Error {
628
637
  readonly code: string;
629
- constructor(code: string);
638
+ readonly paths?: readonly string[];
639
+ constructor(code: string, paths?: readonly string[]);
630
640
  }
631
641
  export declare const outbound: {
632
642
  direct: Readonly<{
@@ -713,6 +723,7 @@ type ProfileCompilation = {
713
723
  readonly engine: "invalid";
714
724
  readonly ok: false;
715
725
  readonly code: string;
726
+ readonly paths?: readonly string[];
716
727
  };
717
728
  declare function surgeConfig(input: SurgeConfig): SurgeConfig;
718
729
  export declare function defineProfile(input: ProfileDefinition | Profile): Profile;
@@ -982,6 +993,7 @@ export declare const proxy: {
982
993
  http: (options: Omit<HttpNode, "type">) => HttpNode;
983
994
  trojan: (options: Omit<TrojanNode, "type">) => TrojanNode;
984
995
  anytls: (options: Omit<AnyTLSNode, "type">) => AnyTLSNode;
996
+ hysteria2: (options: Omit<Hysteria2Node, "type">) => Hysteria2Node;
985
997
  shadowsocks: (options: Omit<ShadowsocksNode, "type">) => ShadowsocksNode;
986
998
  vmess: (options: Omit<VMessNode, "type">) => VMessNode;
987
999
  vless: (options: Omit<VLESSNode, "type">) => VLESSNode;
@@ -1029,11 +1041,18 @@ type Artifact = {
1029
1041
  /** Secret resolution is once per token per batch, including across providers. */
1030
1042
  export declare function render(compilation: Compilation, resolveSecret: (token: Secret) => string | undefined): readonly Artifact[];
1031
1043
  //#endregion
1044
+ //#region src/secrets.d.ts
1045
+ type SecretFailure = {
1046
+ readonly secretName?: string;
1047
+ readonly secretReason?: "MISSING" | "RESOLUTION_FAILED";
1048
+ };
1049
+ //#endregion
1032
1050
  //#region src/host.d.ts
1033
- type BuildResult = {
1051
+ type BuildResult = SecretFailure & {
1034
1052
  readonly published: boolean;
1035
1053
  readonly exitCode: 0 | 1 | 2;
1036
1054
  readonly code: string;
1055
+ readonly paths?: readonly string[];
1037
1056
  readonly active?: string;
1038
1057
  readonly generation?: string;
1039
1058
  readonly reason?: "ACCESS_DENIED" | "NO_SPACE" | "READ_ONLY" | "INVALID_DIRECTORY" | "IO_ERROR";
@@ -1123,6 +1142,7 @@ type ProfileCheckResult = {
1123
1142
  readonly engine: "surge" | "sing-box" | "invalid";
1124
1143
  readonly ok: boolean;
1125
1144
  readonly code?: string;
1145
+ readonly paths?: readonly string[];
1126
1146
  readonly diagnostics: readonly Diagnostic[];
1127
1147
  }[];
1128
1148
  };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as outbound, A as renderSurgeProfiles, B as validateProxyOptions, C as strategy, D as defineProfile, E as compileProfile, F as isReservedNativeName, G as nodeSchema, H as assertData, I as nativeNameSchema, J as defineProxyGroup, L as targetCatalog, M as compile, N as explain, O as compileSurgeProfile, P as compileStrategyGroups, Q as inspectDefinition, R as RenderError, S as slot, T as use, U as deepFreeze, V as StaticRuleSetUnknownError, W as idSchema, X as defineRoutes, Y as defineRoute, Z as exactDefinition, _ as rule, a as render, b as sequence, c as direct, d as match, f as mihomo, g as route, h as reject, i as buildToDirectory, j as secretReader, k as renderSurgeProfile, l as dnsRule, m as proxy, n as defineBuild, o as block, p as policy, q as ProfileDefinitionError, r as runBuild, s as defineConfig, t as checkBuild, u as group, v as ruleSet, w as surge, x as singbox, y as secret, z as surgeProxy } from "./profile-build-Dg7xfQbi.js";
1
+ import { $ as inspectDefinition, A as renderSurgeProfiles, B as validateProxyOptions, C as strategy, D as defineProfile, E as compileProfile, F as isReservedNativeName, G as nodeSchema, H as assertData, I as nativeNameSchema, J as defineProxyGroup, L as targetCatalog, M as compile, N as explain, O as compileSurgeProfile, P as compileStrategyGroups, Q as exactDefinition, R as RenderError, S as slot, T as use, U as deepFreeze, V as StaticRuleSetUnknownError, W as idSchema, X as defineRoutes, Y as defineRoute, _ as rule, a as render, b as sequence, c as direct, d as match, et as outbound, f as mihomo, g as route, h as reject, i as buildToDirectory, j as secretReader, k as renderSurgeProfile, l as dnsRule, m as proxy, n as defineBuild, o as block, p as policy, q as ProfileDefinitionError, r as runBuild, s as defineConfig, t as checkBuild, u as group, v as ruleSet, w as surge, x as singbox, y as secret, z as surgeProxy } from "./profile-build-B04BpEx3.js";
2
2
  import { z } from "zod";
3
3
  import { createHash } from "node:crypto";
4
4
  //#region src/proxy-fragments.ts
@@ -58,12 +58,75 @@ function dnsCondition(rule) {
58
58
  }
59
59
  //#endregion
60
60
  //#region src/surge-definitions.ts
61
+ const definitionCodes = /* @__PURE__ */ new Set([
62
+ "DEFINITION_CYCLE",
63
+ "DEFINITION_DEPTH_EXCEEDED",
64
+ "DEFINITION_EDGE_BUDGET_EXCEEDED",
65
+ "DEFINITION_NOT_DATA",
66
+ "DEFINITION_OBJECT_BUDGET_EXCEEDED",
67
+ "DEFINITION_OUTPUT_BUDGET_EXCEEDED",
68
+ "DEFINITION_UNKNOWN_FIELD",
69
+ "DNS_HOSTS_CONFLICT",
70
+ "DNS_RULE_CONFLICT",
71
+ "DUPLICATE_RESOURCE_ID",
72
+ "GROUP_NAME_CONFLICT",
73
+ "INVALID_BUILD_DEFINITION",
74
+ "INVALID_DESTINATION",
75
+ "INVALID_DNS_RULE",
76
+ "INVALID_DNS_RULES",
77
+ "INVALID_GROUP_DEFINITION",
78
+ "INVALID_MATCH_OPTIONS",
79
+ "INVALID_NATIVE_RULESET",
80
+ "INVALID_PROFILE_DEFINITION",
81
+ "INVALID_RESOURCE_DEFINITION",
82
+ "INVALID_ROUTE_DEFINITION",
83
+ "INVALID_SECRETS_DEFINITION",
84
+ "INVALID_SURGE_GENERAL",
85
+ "INVALID_SURGE_HOSTS",
86
+ "LOGICAL_DEPTH_EXCEEDED",
87
+ "PROFILE_CONDITION_UNSUPPORTED",
88
+ "PROFILE_DESTINATION_UNSUPPORTED",
89
+ "PROFILE_ENDPOINT_UNSUPPORTED",
90
+ "PROFILE_EXTENSION_UNSUPPORTED",
91
+ "PROFILE_GROUP_MEMBER_UNSUPPORTED",
92
+ "PROFILE_GROUP_OPTIONS_UNSUPPORTED",
93
+ "PROFILE_TARGET_UNSUPPORTED",
94
+ "RULESET_COMPOSITION_UNSUPPORTED",
95
+ "UNKNOWN_DESTINATION_ID",
96
+ "UNREGISTERED_DESTINATION_INSTANCE",
97
+ "UNSUPPORTED_GROUP_ALGORITHM"
98
+ ]);
99
+ function validDiagnosticPath(path) {
100
+ return typeof path === "string" && /^(dns|surge\.hosts)\[\d{1,4}\]$/.test(path);
101
+ }
102
+ function definitionDiagnostic(error) {
103
+ try {
104
+ if (!error || typeof error !== "object") return;
105
+ const name = Object.getOwnPropertyDescriptor(error, "name")?.value;
106
+ const code = Object.getOwnPropertyDescriptor(error, "code")?.value;
107
+ if (name !== "ProfileDefinitionError" || typeof code !== "string" || !definitionCodes.has(code)) return;
108
+ const paths = Object.getOwnPropertyDescriptor(error, "paths")?.value;
109
+ if (code === "DNS_HOSTS_CONFLICT" && Array.isArray(paths) && Object.getOwnPropertyDescriptor(paths, "length")?.value === 2) {
110
+ const first = Object.getOwnPropertyDescriptor(paths, "0")?.value;
111
+ const second = Object.getOwnPropertyDescriptor(paths, "1")?.value;
112
+ if (validDiagnosticPath(first) && validDiagnosticPath(second)) return {
113
+ code,
114
+ paths: [first, second]
115
+ };
116
+ }
117
+ return { code };
118
+ } catch {
119
+ return;
120
+ }
121
+ }
61
122
  var ProfileDefinitionError = class extends Error {
62
123
  code;
63
- constructor(code) {
124
+ paths;
125
+ constructor(code, paths) {
64
126
  super(code);
65
127
  this.code = code;
66
128
  this.name = "ProfileDefinitionError";
129
+ if (paths?.length === 2 && paths.every(validDiagnosticPath)) this.paths = Object.freeze([...paths]);
67
130
  }
68
131
  };
69
132
  const fail$1 = (code) => {
@@ -574,6 +637,10 @@ const surgeOptions$1 = { blockQuic: z.enum([
574
637
  "on",
575
638
  "off"
576
639
  ]).optional() };
640
+ const portHoppingSchema = z.string().max(2048).regex(/^[0-9]+(?:-[0-9]+)?(?:;[0-9]+(?:-[0-9]+)?)*$/).refine((value) => value.split(";").every((part) => {
641
+ const [start, end = start] = part.split("-").map(Number);
642
+ return start !== void 0 && end !== void 0 && start >= 1 && end <= 65535 && start <= end;
643
+ }));
577
644
  const nodeSchema = z.discriminatedUnion("type", [
578
645
  z.strictObject({
579
646
  ...nodeBase,
@@ -597,6 +664,16 @@ const nodeSchema = z.discriminatedUnion("type", [
597
664
  udpRelay: z.literal(true).optional()
598
665
  }).optional()
599
666
  }),
667
+ z.strictObject({
668
+ ...nodeBase,
669
+ type: z.literal("hysteria2"),
670
+ tcpFastOpen: z.never().optional(),
671
+ password: secretSchema,
672
+ serverName: domain$1.optional(),
673
+ skipCertVerify: z.boolean().optional(),
674
+ portHopping: portHoppingSchema.optional(),
675
+ portHoppingInterval: z.number().int().positive().optional()
676
+ }).refine((node) => node.portHoppingInterval === void 0 || node.portHopping !== void 0),
600
677
  z.strictObject({
601
678
  ...nodeBase,
602
679
  type: z.literal("http"),
@@ -1119,6 +1196,16 @@ function nodeIsTcpOnly(node, engine) {
1119
1196
  return node.type === "http" || node.type === "anytls" && engine !== "surge" || node.type === "vmess" || node.type === "vless" || engine === "surge" && node.type === "shadowsocks" && node.surge?.udpRelay === false;
1120
1197
  }
1121
1198
  function validateProxyOptions(node, target, diagnostics) {
1199
+ if (node.type === "hysteria2") {
1200
+ if (target.engine === "surge" && node.portHopping && node.via) diagnostics.push({
1201
+ severity: "error",
1202
+ code: "PROXY_OPTION_UNSUPPORTED",
1203
+ target: target.id,
1204
+ path: `targets.${target.id}.nodes.${node.id}`,
1205
+ message: "Surge 端口跳跃不能与 underlying-proxy 同用"
1206
+ });
1207
+ return;
1208
+ }
1122
1209
  const tls = "tls" in node ? node.tls : void 0;
1123
1210
  if (target.engine !== "surge") {
1124
1211
  if (node.tcpFastOpen !== void 0 || "skipCertVerify" in node && node.skipCertVerify !== void 0 || tls?.skipCertVerify !== void 0 || "surge" in node && node.surge !== void 0) diagnostics.push({
@@ -1152,6 +1239,19 @@ function singboxProxy(node, secret) {
1152
1239
  ...node.via ? { detour: node.via } : {}
1153
1240
  };
1154
1241
  switch (node.type) {
1242
+ case "hysteria2":
1243
+ result.password = secret(node.password);
1244
+ result.tls = {
1245
+ enabled: true,
1246
+ ...node.serverName ? { server_name: node.serverName } : {},
1247
+ ...node.skipCertVerify !== void 0 ? { insecure: node.skipCertVerify } : {}
1248
+ };
1249
+ if (node.portHopping) {
1250
+ delete result.server_port;
1251
+ result.server_ports = node.portHopping.split(";").map((part) => part.includes("-") ? part.replace("-", ":") : `${part}:${part}`);
1252
+ }
1253
+ if (node.portHoppingInterval !== void 0) result.hop_interval = `${node.portHoppingInterval}s`;
1254
+ break;
1155
1255
  case "http":
1156
1256
  result.password = secret(node.password);
1157
1257
  if (node.username) result.username = secret(node.username);
@@ -1199,6 +1299,13 @@ function clashProxy(node, engine, secret) {
1199
1299
  ...engine === "stash" ? { "block-quic": "off" } : {}
1200
1300
  };
1201
1301
  switch (node.type) {
1302
+ case "hysteria2":
1303
+ result[engine === "stash" ? "auth" : "password"] = secret(node.password);
1304
+ if (node.serverName) result.sni = node.serverName;
1305
+ if (node.skipCertVerify !== void 0) result["skip-cert-verify"] = node.skipCertVerify;
1306
+ if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
1307
+ if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
1308
+ break;
1202
1309
  case "http":
1203
1310
  result.password = secret(node.password);
1204
1311
  if (node.username) result.username = secret(node.username);
@@ -1252,6 +1359,13 @@ function surgeProxy(node, secret, name = (id) => id) {
1252
1359
  if (node.username) params.push(`username=${atom(secret(node.username))}`);
1253
1360
  params.push(`password=${atom(secret(node.password))}`);
1254
1361
  break;
1362
+ case "hysteria2":
1363
+ params.push(`password=${atom(secret(node.password))}`);
1364
+ if (node.serverName) params.push(`sni=${node.serverName}`);
1365
+ if (node.skipCertVerify !== void 0) params.push(`skip-cert-verify=${node.skipCertVerify}`);
1366
+ if (node.portHopping) params.push(`port-hopping=${node.portHopping}`);
1367
+ if (node.portHoppingInterval !== void 0) params.push(`port-hopping-interval=${node.portHoppingInterval}`);
1368
+ break;
1255
1369
  case "trojan":
1256
1370
  case "anytls":
1257
1371
  params.push(`password=${atom(secret(node.password))}`);
@@ -1384,6 +1498,7 @@ const targetCatalog = deepFreeze([
1384
1498
  autoGroup: "urltest",
1385
1499
  platforms: ["linux", "macos"],
1386
1500
  protocols: [
1501
+ "hysteria2",
1387
1502
  "trojan",
1388
1503
  "http",
1389
1504
  "shadowsocks",
@@ -1401,6 +1516,7 @@ const targetCatalog = deepFreeze([
1401
1516
  autoGroup: "urltest",
1402
1517
  platforms: ["linux", "macos"],
1403
1518
  protocols: [
1519
+ "hysteria2",
1404
1520
  "trojan",
1405
1521
  "http",
1406
1522
  "anytls",
@@ -1419,6 +1535,7 @@ const targetCatalog = deepFreeze([
1419
1535
  autoGroup: "surge-smart",
1420
1536
  platforms: ["macos"],
1421
1537
  protocols: [
1538
+ "hysteria2",
1422
1539
  "trojan",
1423
1540
  "http",
1424
1541
  "anytls",
@@ -1436,6 +1553,7 @@ const targetCatalog = deepFreeze([
1436
1553
  autoGroup: "urltest",
1437
1554
  platforms: ["linux", "macos"],
1438
1555
  protocols: [
1556
+ "hysteria2",
1439
1557
  "trojan",
1440
1558
  "http",
1441
1559
  "anytls",
@@ -1454,6 +1572,7 @@ const targetCatalog = deepFreeze([
1454
1572
  autoGroup: null,
1455
1573
  platforms: ["macos"],
1456
1574
  protocols: [
1575
+ "hysteria2",
1457
1576
  "trojan",
1458
1577
  "http",
1459
1578
  "anytls",
@@ -1910,6 +2029,18 @@ function explain(compilation, target, request) {
1910
2029
  }
1911
2030
  //#endregion
1912
2031
  //#region src/secrets.ts
2032
+ const failures = /* @__PURE__ */ new WeakMap();
2033
+ function secretFailure(error) {
2034
+ return error !== null && typeof error === "object" ? failures.get(error) ?? {} : {};
2035
+ }
2036
+ function failure(code, name, reason) {
2037
+ const error = new RenderError(code);
2038
+ if (/^[A-Z][A-Z0-9_]{0,127}$/.test(name)) failures.set(error, Object.freeze({
2039
+ secretName: name,
2040
+ secretReason: reason
2041
+ }));
2042
+ return error;
2043
+ }
1913
2044
  /** One reader per rendering batch; exceptions and missing values never disclose credentials. */
1914
2045
  function secretReader(resolveSecret) {
1915
2046
  const values = /* @__PURE__ */ new Map();
@@ -1918,10 +2049,11 @@ function secretReader(resolveSecret) {
1918
2049
  let value;
1919
2050
  try {
1920
2051
  value = resolveSecret(token);
1921
- } catch {
1922
- throw new RenderError("SECRET_RESOLUTION_FAILED");
2052
+ } catch (error) {
2053
+ const nested = secretFailure(error);
2054
+ throw failure("SECRET_RESOLUTION_FAILED", token.name, nested.secretName === token.name && nested.secretReason === "MISSING" ? "MISSING" : "RESOLUTION_FAILED");
1923
2055
  }
1924
- if (typeof value !== "string" || value.length === 0) throw new RenderError("SECRET_MISSING");
2056
+ if (typeof value !== "string" || value.length === 0) throw failure("SECRET_MISSING", token.name, "MISSING");
1925
2057
  values.set(token.name, value);
1926
2058
  return value;
1927
2059
  };
@@ -2495,7 +2627,15 @@ function defineProfile(input) {
2495
2627
  ...input.surge.hosts === void 0 ? {} : { hosts: flatten(input.surge.hosts) }
2496
2628
  };
2497
2629
  }
2498
- if (dns?.length && surge?.hosts?.length) fail("DNS_HOSTS_CONFLICT");
2630
+ if (dns?.length && surge?.hosts?.length) {
2631
+ if (dns.length + surge.hosts.length > 2e3) fail("INVALID_SURGE_HOSTS");
2632
+ const patterns = new Map(dns.map((entry, index) => [entry.pattern.toLowerCase(), index]));
2633
+ for (const [index, host] of surge.hosts.entries()) {
2634
+ if (typeof host?.pattern !== "string") fail("INVALID_SURGE_HOSTS");
2635
+ const dnsIndex = patterns.get(host.pattern.toLowerCase());
2636
+ if (dnsIndex !== void 0) throw new ProfileDefinitionError("DNS_HOSTS_CONFLICT", [`dns[${dnsIndex}]`, `surge.hosts[${index}]`]);
2637
+ }
2638
+ }
2499
2639
  const { dns: _dns, surge: _surge, proxies: _proxies, groups: _groups, routes: _routes, ...rest } = input;
2500
2640
  return snapshotProfile({
2501
2641
  ...rest,
@@ -2584,7 +2724,7 @@ function compileProfile(input) {
2584
2724
  const compilation = compileSurgeProfile(lowerSurgeProfile({
2585
2725
  target: profile.target,
2586
2726
  ...profile.surge,
2587
- ...profile.dns?.length ? { hosts: profile.dns } : {},
2727
+ ...profile.dns?.length ? { hosts: [...profile.dns, ...profile.surge?.hosts ?? []] } : {},
2588
2728
  nodes,
2589
2729
  tunnels: endpoints,
2590
2730
  groups: profile.groups,
@@ -2701,7 +2841,8 @@ function compileProfile(input) {
2701
2841
  return {
2702
2842
  engine: "invalid",
2703
2843
  ok: false,
2704
- code: error instanceof ProfileDefinitionError ? error.code : "INVALID_PROFILE_DEFINITION"
2844
+ code: error instanceof ProfileDefinitionError ? error.code : "INVALID_PROFILE_DEFINITION",
2845
+ ...error instanceof ProfileDefinitionError && error.paths ? { paths: error.paths } : {}
2705
2846
  };
2706
2847
  }
2707
2848
  }
@@ -2934,6 +3075,7 @@ const proxy = {
2934
3075
  http: nodeConstructor("http"),
2935
3076
  trojan: nodeConstructor("trojan"),
2936
3077
  anytls: nodeConstructor("anytls"),
3078
+ hysteria2: nodeConstructor("hysteria2"),
2937
3079
  shadowsocks: nodeConstructor("shadowsocks"),
2938
3080
  vmess: nodeConstructor("vmess"),
2939
3081
  vless: nodeConstructor("vless")
@@ -3299,7 +3441,10 @@ async function buildToDirectory(compilation, output, resolveSecret = (token) =>
3299
3441
  code = "PUBLISHED";
3300
3442
  } catch (error) {
3301
3443
  code = error instanceof RenderError ? error.code : "OUTPUT_FAILED";
3302
- detail = error instanceof RenderError ? { hint: buildHints[code] } : outputFailure(error);
3444
+ detail = error instanceof RenderError ? {
3445
+ hint: buildHints[code],
3446
+ ...secretFailure(error)
3447
+ } : outputFailure(error);
3303
3448
  } finally {
3304
3449
  if (locked) {
3305
3450
  try {
@@ -3434,7 +3579,8 @@ function compileBatch(profiles, output) {
3434
3579
  const entries = Object.entries(profiles);
3435
3580
  const compiled = [];
3436
3581
  let outputDirectoryChecked = false;
3437
- const result = (code) => ({
3582
+ const result = (code, paths) => ({
3583
+ ...paths ? { paths } : {},
3438
3584
  ok: code === "CHECKED",
3439
3585
  code,
3440
3586
  entries,
@@ -3444,7 +3590,7 @@ function compileBatch(profiles, output) {
3444
3590
  if (!entries.length || entries.length > 16 || entries.some(([id]) => !/^[a-z0-9][a-z0-9-]*$/.test(id))) return result("INVALID_PROFILE_FILENAMES");
3445
3591
  compiled.push(...entries.map(([, profile]) => compileProfile(profile)));
3446
3592
  const invalid = compiled.find((profile) => !profile.ok);
3447
- if (invalid) return result(invalid.engine === "invalid" ? invalid.code : "COMPILATION_FAILED");
3593
+ if (invalid) return result(invalid.engine === "invalid" ? invalid.code : "COMPILATION_FAILED", invalid.engine === "invalid" ? invalid.paths : void 0);
3448
3594
  if (output !== void 0) {
3449
3595
  outputDirectoryChecked = true;
3450
3596
  if (compiled.some((profile) => profile.engine === "sing-box" && profile.compilation.plans.some((plan) => plan.program.endpoints?.some((endpoint) => pathsOverlap(output, endpoint.stateDirectory))))) return result("ENDPOINT_STATE_OVERLAP");
@@ -3477,6 +3623,7 @@ function checkBuild(input) {
3477
3623
  ok: profile.ok,
3478
3624
  ...profile.engine === "invalid" ? {
3479
3625
  code: profile.code,
3626
+ ...profile.paths ? { paths: profile.paths } : {},
3480
3627
  diagnostics: []
3481
3628
  } : { diagnostics: profile.compilation.diagnostics }
3482
3629
  }))
@@ -3488,7 +3635,8 @@ async function publish(profiles, output, readSecret) {
3488
3635
  if (!checked.ok) return {
3489
3636
  published: false,
3490
3637
  exitCode: 1,
3491
- code: checked.code
3638
+ code: checked.code,
3639
+ ...checked.paths ? { paths: checked.paths } : {}
3492
3640
  };
3493
3641
  const { entries, compiled } = checked;
3494
3642
  const read = secretReader(readSecret);
@@ -3516,7 +3664,8 @@ async function publish(profiles, output, readSecret) {
3516
3664
  return {
3517
3665
  published: false,
3518
3666
  exitCode: 1,
3519
- code: error instanceof RenderError ? error.code : "BUILD_FAILED"
3667
+ code: error instanceof RenderError ? error.code : "BUILD_FAILED",
3668
+ ...secretFailure(error)
3520
3669
  };
3521
3670
  }
3522
3671
  }
@@ -3605,4 +3754,4 @@ async function runBuild(input, output, options = {}) {
3605
3754
  };
3606
3755
  }
3607
3756
  //#endregion
3608
- export { outbound as $, renderSurgeProfiles as A, validateProxyOptions as B, strategy as C, defineProfile as D, compileProfile as E, isReservedNativeName as F, nodeSchema as G, assertData as H, nativeNameSchema as I, defineProxyGroup as J, requestSchema as K, targetCatalog as L, compile as M, explain as N, compileSurgeProfile as O, compileStrategyGroups as P, inspectDefinition as Q, RenderError as R, slot as S, use as T, deepFreeze as U, StaticRuleSetUnknownError as V, idSchema as W, defineRoutes as X, defineRoute as Y, exactDefinition as Z, rule as _, render as a, sequence as b, direct as c, match as d, mihomo as f, route as g, reject as h, buildToDirectory as i, secretReader as j, renderSurgeProfile as k, dnsRule as l, proxy as m, defineBuild as n, block as o, policy as p, ProfileDefinitionError as q, runBuild as r, defineConfig as s, checkBuild as t, group as u, ruleSet as v, surge$1 as w, singbox$1 as x, secret as y, surgeProxy as z };
3757
+ export { inspectDefinition as $, renderSurgeProfiles as A, validateProxyOptions as B, strategy as C, defineProfile as D, compileProfile as E, isReservedNativeName as F, nodeSchema as G, assertData as H, nativeNameSchema as I, defineProxyGroup as J, requestSchema as K, targetCatalog as L, compile as M, explain as N, compileSurgeProfile as O, compileStrategyGroups as P, exactDefinition as Q, RenderError as R, slot as S, use as T, deepFreeze as U, StaticRuleSetUnknownError as V, idSchema as W, defineRoutes as X, defineRoute as Y, definitionDiagnostic as Z, rule as _, render as a, sequence as b, direct as c, match as d, outbound as et, mihomo as f, route as g, reject as h, buildToDirectory as i, secretReader as j, renderSurgeProfile as k, dnsRule as l, proxy as m, defineBuild as n, block as o, policy as p, ProfileDefinitionError as q, runBuild as r, defineConfig as s, checkBuild as t, group as u, ruleSet as v, surge$1 as w, singbox$1 as x, secret as y, surgeProxy as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proxylang",
3
- "version": "0.9.0",
3
+ "version": "0.10.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": {