proxylang 0.9.1 → 0.10.1

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, Z as definitionDiagnostic, i as buildToDirectory, n as defineBuild, r as runBuild, t as checkBuild } from "./profile-build-Cyrem-0-.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-BC7eIYBy.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";
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;
@@ -457,6 +466,9 @@ type SurgeCondition = {
457
466
  }) | (NoSniff & {
458
467
  readonly type: "network";
459
468
  readonly value: "tcp" | "udp";
469
+ }) | (NoSniff & {
470
+ readonly type: "ipAsn";
471
+ readonly value: number;
460
472
  }) | (NoSniff & {
461
473
  readonly type: "all" | "any";
462
474
  readonly conditions: readonly SurgeCondition[];
@@ -523,7 +535,7 @@ export declare const targetCatalog: readonly [{
523
535
  readonly version: "1.11.0";
524
536
  readonly autoGroup: "urltest";
525
537
  readonly platforms: readonly ["linux", "macos"];
526
- readonly protocols: readonly ["trojan", "http", "shadowsocks", "vmess", "vless"];
538
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "shadowsocks", "vmess", "vless"];
527
539
  readonly endpoints: readonly [];
528
540
  readonly groups: readonly ["select", "urltest"];
529
541
  readonly nativeRuleSets: readonly ["source", "binary"];
@@ -533,7 +545,7 @@ export declare const targetCatalog: readonly [{
533
545
  readonly version: "1.12.0";
534
546
  readonly autoGroup: "urltest";
535
547
  readonly platforms: readonly ["linux", "macos"];
536
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
548
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
537
549
  readonly endpoints: readonly ["sing-box-tailscale"];
538
550
  readonly groups: readonly ["select", "urltest"];
539
551
  readonly nativeRuleSets: readonly ["source", "binary"];
@@ -543,7 +555,7 @@ export declare const targetCatalog: readonly [{
543
555
  readonly version: "6.10.0";
544
556
  readonly autoGroup: "surge-smart";
545
557
  readonly platforms: readonly ["macos"];
546
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
558
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess"];
547
559
  readonly endpoints: readonly [];
548
560
  readonly groups: readonly ["select", "surge-smart"];
549
561
  readonly nativeRuleSets: readonly ["rule-set", "domain-set"];
@@ -553,7 +565,7 @@ export declare const targetCatalog: readonly [{
553
565
  readonly version: "1.19.32";
554
566
  readonly autoGroup: "urltest";
555
567
  readonly platforms: readonly ["linux", "macos"];
556
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
568
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
557
569
  readonly endpoints: readonly [];
558
570
  readonly groups: readonly ["select", "urltest"];
559
571
  readonly nativeRuleSets: readonly ["yaml", "text"];
@@ -563,7 +575,7 @@ export declare const targetCatalog: readonly [{
563
575
  readonly version: "4.2.1";
564
576
  readonly autoGroup: null;
565
577
  readonly platforms: readonly ["macos"];
566
- readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
578
+ readonly protocols: readonly ["hysteria2", "trojan", "http", "anytls", "shadowsocks", "vmess"];
567
579
  readonly endpoints: readonly [];
568
580
  readonly groups: readonly ["select"];
569
581
  readonly nativeRuleSets: readonly [];
@@ -863,6 +875,10 @@ export declare const surge: {
863
875
  readonly noResolve?: boolean;
864
876
  readonly includeSniffed?: never;
865
877
  } | undefined) => SurgeCondition;
878
+ ipAsn: (value: number, options?: {
879
+ readonly noResolve?: boolean;
880
+ readonly includeSniffed?: never;
881
+ }) => SurgeCondition;
866
882
  sourceIp: (value: string, options?: {
867
883
  readonly noResolve?: boolean;
868
884
  readonly includeSniffed?: never;
@@ -984,6 +1000,7 @@ export declare const proxy: {
984
1000
  http: (options: Omit<HttpNode, "type">) => HttpNode;
985
1001
  trojan: (options: Omit<TrojanNode, "type">) => TrojanNode;
986
1002
  anytls: (options: Omit<AnyTLSNode, "type">) => AnyTLSNode;
1003
+ hysteria2: (options: Omit<Hysteria2Node, "type">) => Hysteria2Node;
987
1004
  shadowsocks: (options: Omit<ShadowsocksNode, "type">) => ShadowsocksNode;
988
1005
  vmess: (options: Omit<VMessNode, "type">) => VMessNode;
989
1006
  vless: (options: Omit<VLESSNode, "type">) => VLESSNode;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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-Cyrem-0-.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-BC7eIYBy.js";
2
2
  import { z } from "zod";
3
3
  import { createHash } from "node:crypto";
4
4
  //#region src/proxy-fragments.ts
@@ -389,6 +389,14 @@ const surgeMatch = {
389
389
  domainSuffix: atom$2("domainSuffix"),
390
390
  ipCidr: atom$2("ipCidr"),
391
391
  ipCidr6: atom$2("ipCidr6"),
392
+ ipAsn: (value, options = {}) => {
393
+ inspectDefinition(options);
394
+ return condition({
395
+ ...options,
396
+ type: "ipAsn",
397
+ value
398
+ });
399
+ },
392
400
  sourceIp: atom$2("sourceIp"),
393
401
  processName: atom$2("processName"),
394
402
  macAddress: atom$2("macAddress"),
@@ -637,6 +645,10 @@ const surgeOptions$1 = { blockQuic: z.enum([
637
645
  "on",
638
646
  "off"
639
647
  ]).optional() };
648
+ const portHoppingSchema = z.string().max(2048).regex(/^[0-9]+(?:-[0-9]+)?(?:;[0-9]+(?:-[0-9]+)?)*$/).refine((value) => value.split(";").every((part) => {
649
+ const [start, end = start] = part.split("-").map(Number);
650
+ return start !== void 0 && end !== void 0 && start >= 1 && end <= 65535 && start <= end;
651
+ }));
640
652
  const nodeSchema = z.discriminatedUnion("type", [
641
653
  z.strictObject({
642
654
  ...nodeBase,
@@ -660,6 +672,16 @@ const nodeSchema = z.discriminatedUnion("type", [
660
672
  udpRelay: z.literal(true).optional()
661
673
  }).optional()
662
674
  }),
675
+ z.strictObject({
676
+ ...nodeBase,
677
+ type: z.literal("hysteria2"),
678
+ tcpFastOpen: z.never().optional(),
679
+ password: secretSchema,
680
+ serverName: domain$1.optional(),
681
+ skipCertVerify: z.boolean().optional(),
682
+ portHopping: portHoppingSchema.optional(),
683
+ portHoppingInterval: z.number().int().positive().optional()
684
+ }).refine((node) => node.portHoppingInterval === void 0 || node.portHopping !== void 0),
663
685
  z.strictObject({
664
686
  ...nodeBase,
665
687
  type: z.literal("http"),
@@ -1182,6 +1204,16 @@ function nodeIsTcpOnly(node, engine) {
1182
1204
  return node.type === "http" || node.type === "anytls" && engine !== "surge" || node.type === "vmess" || node.type === "vless" || engine === "surge" && node.type === "shadowsocks" && node.surge?.udpRelay === false;
1183
1205
  }
1184
1206
  function validateProxyOptions(node, target, diagnostics) {
1207
+ if (node.type === "hysteria2") {
1208
+ if (target.engine === "surge" && node.portHopping && node.via) diagnostics.push({
1209
+ severity: "error",
1210
+ code: "PROXY_OPTION_UNSUPPORTED",
1211
+ target: target.id,
1212
+ path: `targets.${target.id}.nodes.${node.id}`,
1213
+ message: "Surge 端口跳跃不能与 underlying-proxy 同用"
1214
+ });
1215
+ return;
1216
+ }
1185
1217
  const tls = "tls" in node ? node.tls : void 0;
1186
1218
  if (target.engine !== "surge") {
1187
1219
  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({
@@ -1215,6 +1247,19 @@ function singboxProxy(node, secret) {
1215
1247
  ...node.via ? { detour: node.via } : {}
1216
1248
  };
1217
1249
  switch (node.type) {
1250
+ case "hysteria2":
1251
+ result.password = secret(node.password);
1252
+ result.tls = {
1253
+ enabled: true,
1254
+ ...node.serverName ? { server_name: node.serverName } : {},
1255
+ ...node.skipCertVerify !== void 0 ? { insecure: node.skipCertVerify } : {}
1256
+ };
1257
+ if (node.portHopping) {
1258
+ delete result.server_port;
1259
+ result.server_ports = node.portHopping.split(";").map((part) => part.includes("-") ? part.replace("-", ":") : `${part}:${part}`);
1260
+ }
1261
+ if (node.portHoppingInterval !== void 0) result.hop_interval = `${node.portHoppingInterval}s`;
1262
+ break;
1218
1263
  case "http":
1219
1264
  result.password = secret(node.password);
1220
1265
  if (node.username) result.username = secret(node.username);
@@ -1262,6 +1307,13 @@ function clashProxy(node, engine, secret) {
1262
1307
  ...engine === "stash" ? { "block-quic": "off" } : {}
1263
1308
  };
1264
1309
  switch (node.type) {
1310
+ case "hysteria2":
1311
+ result[engine === "stash" ? "auth" : "password"] = secret(node.password);
1312
+ if (node.serverName) result.sni = node.serverName;
1313
+ if (node.skipCertVerify !== void 0) result["skip-cert-verify"] = node.skipCertVerify;
1314
+ if (node.portHopping) result.ports = node.portHopping.replaceAll(";", ",");
1315
+ if (node.portHoppingInterval !== void 0) result["hop-interval"] = node.portHoppingInterval;
1316
+ break;
1265
1317
  case "http":
1266
1318
  result.password = secret(node.password);
1267
1319
  if (node.username) result.username = secret(node.username);
@@ -1315,6 +1367,13 @@ function surgeProxy(node, secret, name = (id) => id) {
1315
1367
  if (node.username) params.push(`username=${atom(secret(node.username))}`);
1316
1368
  params.push(`password=${atom(secret(node.password))}`);
1317
1369
  break;
1370
+ case "hysteria2":
1371
+ params.push(`password=${atom(secret(node.password))}`);
1372
+ if (node.serverName) params.push(`sni=${node.serverName}`);
1373
+ if (node.skipCertVerify !== void 0) params.push(`skip-cert-verify=${node.skipCertVerify}`);
1374
+ if (node.portHopping) params.push(`port-hopping=${node.portHopping}`);
1375
+ if (node.portHoppingInterval !== void 0) params.push(`port-hopping-interval=${node.portHoppingInterval}`);
1376
+ break;
1318
1377
  case "trojan":
1319
1378
  case "anytls":
1320
1379
  params.push(`password=${atom(secret(node.password))}`);
@@ -1447,6 +1506,7 @@ const targetCatalog = deepFreeze([
1447
1506
  autoGroup: "urltest",
1448
1507
  platforms: ["linux", "macos"],
1449
1508
  protocols: [
1509
+ "hysteria2",
1450
1510
  "trojan",
1451
1511
  "http",
1452
1512
  "shadowsocks",
@@ -1464,6 +1524,7 @@ const targetCatalog = deepFreeze([
1464
1524
  autoGroup: "urltest",
1465
1525
  platforms: ["linux", "macos"],
1466
1526
  protocols: [
1527
+ "hysteria2",
1467
1528
  "trojan",
1468
1529
  "http",
1469
1530
  "anytls",
@@ -1482,6 +1543,7 @@ const targetCatalog = deepFreeze([
1482
1543
  autoGroup: "surge-smart",
1483
1544
  platforms: ["macos"],
1484
1545
  protocols: [
1546
+ "hysteria2",
1485
1547
  "trojan",
1486
1548
  "http",
1487
1549
  "anytls",
@@ -1499,6 +1561,7 @@ const targetCatalog = deepFreeze([
1499
1561
  autoGroup: "urltest",
1500
1562
  platforms: ["linux", "macos"],
1501
1563
  protocols: [
1564
+ "hysteria2",
1502
1565
  "trojan",
1503
1566
  "http",
1504
1567
  "anytls",
@@ -1517,6 +1580,7 @@ const targetCatalog = deepFreeze([
1517
1580
  autoGroup: null,
1518
1581
  platforms: ["macos"],
1519
1582
  protocols: [
1583
+ "hysteria2",
1520
1584
  "trojan",
1521
1585
  "http",
1522
1586
  "anytls",
@@ -2159,6 +2223,11 @@ const conditionSchema = z.lazy(() => z.union([
2159
2223
  atom("domainSuffix", domain),
2160
2224
  atom("ipCidr", cidr(4)),
2161
2225
  atom("ipCidr6", cidr(6)),
2226
+ z.strictObject({
2227
+ type: z.literal("ipAsn"),
2228
+ value: z.number().int().min(1).max(4294967295),
2229
+ ...options$1
2230
+ }),
2162
2231
  atom("sourceIp", z.union([ip, cidr()])),
2163
2232
  atom("processName", safe),
2164
2233
  atom("macAddress", z.string().regex(/^(?:[\da-fA-F]{2}:){5}[\da-fA-F]{2}$/)),
@@ -2320,6 +2389,7 @@ function compileSurgeProfile(input) {
2320
2389
  if (c.noResolve !== void 0 && ![
2321
2390
  "ipCidr",
2322
2391
  "ipCidr6",
2392
+ "ipAsn",
2323
2393
  "ruleSet"
2324
2394
  ].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
2325
2395
  if (c.includeSniffed !== void 0 && ![
@@ -2383,6 +2453,7 @@ function conditionText(c) {
2383
2453
  domainSuffix: "DOMAIN-SUFFIX",
2384
2454
  ipCidr: "IP-CIDR",
2385
2455
  ipCidr6: "IP-CIDR6",
2456
+ ipAsn: "IP-ASN",
2386
2457
  sourceIp: "SRC-IP",
2387
2458
  processName: "PROCESS-NAME",
2388
2459
  macAddress: "MAC-ADDRESS"
@@ -3019,6 +3090,7 @@ const proxy = {
3019
3090
  http: nodeConstructor("http"),
3020
3091
  trojan: nodeConstructor("trojan"),
3021
3092
  anytls: nodeConstructor("anytls"),
3093
+ hysteria2: nodeConstructor("hysteria2"),
3022
3094
  shadowsocks: nodeConstructor("shadowsocks"),
3023
3095
  vmess: nodeConstructor("vmess"),
3024
3096
  vless: nodeConstructor("vless")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proxylang",
3
- "version": "0.9.1",
3
+ "version": "0.10.1",
4
4
  "description": "Composable routing policies in TypeScript with explicit platform targets",
5
5
  "homepage": "https://github.com/CorrectRoadH/proxylang#readme",
6
6
  "bugs": {