proxylang 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +43 -55
- package/dist/index.js +5 -5
- package/dist/{profile-build-EO6TsFJ-.js → profile-build-Dg7xfQbi.js} +79 -73
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -313,7 +313,7 @@ const vless = proxy.vless({
|
|
|
313
313
|
});
|
|
314
314
|
```
|
|
315
315
|
|
|
316
|
-
把这些值放进程序的 `nodes`,便可用 `route("ss")` 或策略组的 `members: ["ss", "vmess"]` 引用。还提供 `proxy.trojan`、`proxy.anytls`、`proxy.http
|
|
316
|
+
把这些值放进程序的 `nodes`,便可用 `route("ss")` 或策略组的 `members: ["ss", "vmess"]` 引用。还提供 `proxy.trojan`、`proxy.anytls`、`proxy.http`;已有对象声明仍可用。地区、供应商等业务信息由应用维护,通过普通数组选择代理或 ID;`via` 引用另一个节点或组,声明拨号链。
|
|
317
317
|
|
|
318
318
|
TLS 的 `serverName` 是证书身份,WebSocket 的 `host` 是 HTTP Host,二者明确分开。省略 `tls` 表示不启用 TLS,省略 `transport` 表示普通 TCP。VMess 当前固定 AEAD/AES-128-GCM;VMess 与 VLESS 暂只允许 TCP 规则,不能作为覆盖 UDP 的 fallback。SS 支持三种 AEAD 方法及 TCP/UDP。
|
|
319
319
|
|
|
@@ -405,6 +405,8 @@ DEMO_PASSWORD=example-only DEMO_UUID=11111111-2222-4333-8444-555555555555 \
|
|
|
405
405
|
|
|
406
406
|
支持域名、IP、端口、网络类型与逻辑条件,节点协议包括 Trojan、HTTP、AnyTLS、Shadowsocks、VMess、VLESS,具体能力按目标版本检查。未知版本和影响路由行为的不支持项报错;可省略的展示信息报 warning,可用 `warningsAsErrors` 提升为错误。
|
|
407
407
|
|
|
408
|
+
需要额外匹配 TLS SNI 和 HTTP Host 时,使用 `match.domainSuffix("example.com", { includeSniffed: true })`。原域名仍参与匹配;Surge 编译为 `extended-matching`。其他引擎的嗅探通常优先使用识别域名,不能等价为多来源 OR,因此拒绝此选项的 `true`。它不改变连接目的地址。详见[匹配语义](docs/feature/target-compilation/domain-sources.md)。
|
|
409
|
+
|
|
408
410
|
Stash 当前拒绝来源 IP/端口、端口范围和组级 URLTest。完整配置的节点地址暂限 IP,独立 Surge 节点片段支持域名。HTTP、VMess、VLESS 及经过它们的代理链按 TCP-only 检查;AnyTLS 目前仅在 Surge 放行 UDP。远程节点订阅、MAC/进程匹配和 TUN 尚未实现。完整限制见 [SDK 细则](docs/implementation-v0.md)和 [Mihomo / Stash 转换边界](docs/engineering/clash-backends/README.md)。
|
|
409
411
|
|
|
410
412
|
配置文件是可信的 TypeScript 代码;构建产物包含密码,旧构建也会保留。凭据与产物管理见[构建契约](docs/feature/artifact-publication/use-case/publish-generation.md)。
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
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";
|
|
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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
//#region src/types.d.ts
|
|
3
|
-
export type DomainSource = "destination" | "tlsSni" | "httpHost";
|
|
4
3
|
export type Network = "tcp" | "udp";
|
|
5
4
|
export type NamedRuleSet = {
|
|
6
5
|
readonly type: "ruleSet";
|
|
@@ -16,7 +15,7 @@ export type NativeRuleSet = {
|
|
|
16
15
|
readonly format: "rule-set" | "domain-set";
|
|
17
16
|
readonly intervalSeconds?: number;
|
|
18
17
|
readonly noResolve?: boolean;
|
|
19
|
-
readonly
|
|
18
|
+
readonly includeSniffed?: boolean;
|
|
20
19
|
} | {
|
|
21
20
|
readonly engine: "sing-box";
|
|
22
21
|
readonly format: "source" | "binary";
|
|
@@ -29,7 +28,7 @@ export type NativeRuleSet = {
|
|
|
29
28
|
});
|
|
30
29
|
export type Match = NamedRuleSet | NativeRuleSet | {
|
|
31
30
|
readonly type: "domain" | "domainSuffix";
|
|
32
|
-
readonly
|
|
31
|
+
readonly includeSniffed?: boolean;
|
|
33
32
|
readonly value: string;
|
|
34
33
|
} | {
|
|
35
34
|
readonly type: "ipCidr";
|
|
@@ -98,9 +97,6 @@ export type ProxyBase = {
|
|
|
98
97
|
readonly via?: string;
|
|
99
98
|
readonly tcpFastOpen?: boolean;
|
|
100
99
|
readonly label?: string;
|
|
101
|
-
readonly region?: string;
|
|
102
|
-
readonly provider?: string;
|
|
103
|
-
readonly tags?: readonly string[];
|
|
104
100
|
};
|
|
105
101
|
export type ProxyTLS = {
|
|
106
102
|
readonly serverName: string;
|
|
@@ -442,32 +438,38 @@ declare const groupSchema: z.ZodObject<{
|
|
|
442
438
|
timeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
443
439
|
}, z.core.$strict>;
|
|
444
440
|
type SurgeGroup = z.infer<typeof groupSchema>;
|
|
445
|
-
type
|
|
446
|
-
readonly
|
|
447
|
-
readonly sources?: readonly DomainSource[];
|
|
441
|
+
type NoSniff = {
|
|
442
|
+
readonly includeSniffed?: never;
|
|
448
443
|
};
|
|
449
|
-
type SurgeCondition =
|
|
450
|
-
readonly
|
|
444
|
+
type SurgeCondition = {
|
|
445
|
+
readonly noResolve?: boolean;
|
|
446
|
+
} & ({
|
|
447
|
+
readonly type: "domain" | "domainSuffix";
|
|
451
448
|
readonly value: string;
|
|
452
|
-
|
|
449
|
+
readonly includeSniffed?: boolean;
|
|
450
|
+
} | (NoSniff & {
|
|
451
|
+
readonly type: "ipCidr" | "ipCidr6" | "sourceIp" | "processName" | "macAddress";
|
|
452
|
+
readonly value: string;
|
|
453
|
+
}) | (NoSniff & {
|
|
453
454
|
readonly type: "port" | "sourcePort";
|
|
454
455
|
readonly from: number;
|
|
455
456
|
readonly to?: number;
|
|
456
|
-
} | {
|
|
457
|
+
}) | (NoSniff & {
|
|
457
458
|
readonly type: "network";
|
|
458
459
|
readonly value: "tcp" | "udp";
|
|
459
|
-
} | {
|
|
460
|
+
}) | (NoSniff & {
|
|
460
461
|
readonly type: "all" | "any";
|
|
461
462
|
readonly conditions: readonly SurgeCondition[];
|
|
462
|
-
} | {
|
|
463
|
+
}) | (NoSniff & {
|
|
463
464
|
readonly type: "not";
|
|
464
465
|
readonly condition: SurgeCondition;
|
|
465
|
-
} | {
|
|
466
|
+
}) | {
|
|
466
467
|
readonly type: "ruleSet";
|
|
467
468
|
readonly format: "rule-set" | "domain-set";
|
|
468
469
|
readonly url?: string;
|
|
469
470
|
readonly builtin?: "LAN" | "SYSTEM";
|
|
470
471
|
readonly intervalSeconds?: number;
|
|
472
|
+
readonly includeSniffed?: boolean;
|
|
471
473
|
});
|
|
472
474
|
type SurgeRule = {
|
|
473
475
|
readonly when: SurgeCondition;
|
|
@@ -649,12 +651,6 @@ export declare function defineRoutes(input: {
|
|
|
649
651
|
readonly when: readonly ProfileCondition[];
|
|
650
652
|
readonly to: ProfileDestination;
|
|
651
653
|
}): RouteDefinition[];
|
|
652
|
-
export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
|
|
653
|
-
ids?: readonly string[];
|
|
654
|
-
regions?: readonly string[];
|
|
655
|
-
providers?: readonly string[];
|
|
656
|
-
tags?: readonly string[];
|
|
657
|
-
}): ProxyNode[];
|
|
658
654
|
//#endregion
|
|
659
655
|
//#region src/profile.d.ts
|
|
660
656
|
type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
|
|
@@ -664,12 +660,10 @@ type ProfileCondition = Exclude<Match | SurgeCondition, {
|
|
|
664
660
|
readonly type: "all" | "any";
|
|
665
661
|
readonly conditions: readonly ProfileCondition[];
|
|
666
662
|
readonly noResolve?: boolean;
|
|
667
|
-
readonly sources?: readonly DomainSource[];
|
|
668
663
|
} | {
|
|
669
664
|
readonly type: "not";
|
|
670
665
|
readonly condition: ProfileCondition;
|
|
671
666
|
readonly noResolve?: boolean;
|
|
672
|
-
readonly sources?: readonly DomainSource[];
|
|
673
667
|
};
|
|
674
668
|
type ProfileDestination = string | ProxyNode | ProxyGroupDefinition | SurgeTunnel | TailscaleEndpoint | {
|
|
675
669
|
readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
|
|
@@ -742,7 +736,7 @@ export declare function dnsRule(pattern: string, server: string): DnsRule;
|
|
|
742
736
|
export declare function dnsRule(patterns: readonly string[], server: string): DnsRule[];
|
|
743
737
|
export declare const ruleSet: (definition: Omit<NamedRuleSet, "type">) => NamedRuleSet;
|
|
744
738
|
type DomainOptions = {
|
|
745
|
-
readonly
|
|
739
|
+
readonly includeSniffed?: boolean;
|
|
746
740
|
};
|
|
747
741
|
type IpOptions = {
|
|
748
742
|
readonly noResolve?: boolean;
|
|
@@ -754,12 +748,12 @@ export declare const match: {
|
|
|
754
748
|
};
|
|
755
749
|
ruleSet: (set: NamedRuleSet) => NamedRuleSet;
|
|
756
750
|
domain: (value: string, opts?: DomainOptions) => {
|
|
757
|
-
|
|
751
|
+
includeSniffed?: boolean;
|
|
758
752
|
type: "domain";
|
|
759
753
|
value: string;
|
|
760
754
|
};
|
|
761
755
|
domainSuffix: (value: string, opts?: DomainOptions) => {
|
|
762
|
-
|
|
756
|
+
includeSniffed?: boolean;
|
|
763
757
|
type: "domainSuffix";
|
|
764
758
|
value: string;
|
|
765
759
|
};
|
|
@@ -833,12 +827,6 @@ export declare const defineConfig: <const T extends Config>(config: T & {
|
|
|
833
827
|
readonly program: string extends NonNullable<NoInfer<T>["cases"]>[number]["program"] ? string : keyof NoInfer<T>["programs"] & string;
|
|
834
828
|
})[];
|
|
835
829
|
}) => T;
|
|
836
|
-
/** Filtering is stable: catalogue order determines initial selector order. */
|
|
837
|
-
export declare function selectNodes(nodes: readonly ProxyNode[], query?: {
|
|
838
|
-
regions?: readonly string[];
|
|
839
|
-
providers?: readonly string[];
|
|
840
|
-
tags?: readonly string[];
|
|
841
|
-
}): string[];
|
|
842
830
|
/** A shared strategy declares an algorithm or explicitly selects native implementations. */
|
|
843
831
|
export declare const strategy: (definition: StrategyDefinition) => Strategy;
|
|
844
832
|
export declare const group: {
|
|
@@ -859,55 +847,55 @@ export declare const surge: {
|
|
|
859
847
|
match: {
|
|
860
848
|
domain: (value: string, options?: {
|
|
861
849
|
readonly noResolve?: boolean;
|
|
862
|
-
readonly
|
|
863
|
-
}) => SurgeCondition;
|
|
850
|
+
readonly includeSniffed?: boolean;
|
|
851
|
+
} | undefined) => SurgeCondition;
|
|
864
852
|
domainSuffix: (value: string, options?: {
|
|
865
853
|
readonly noResolve?: boolean;
|
|
866
|
-
readonly
|
|
867
|
-
}) => SurgeCondition;
|
|
854
|
+
readonly includeSniffed?: boolean;
|
|
855
|
+
} | undefined) => SurgeCondition;
|
|
868
856
|
ipCidr: (value: string, options?: {
|
|
869
857
|
readonly noResolve?: boolean;
|
|
870
|
-
readonly
|
|
871
|
-
}) => SurgeCondition;
|
|
858
|
+
readonly includeSniffed?: never;
|
|
859
|
+
} | undefined) => SurgeCondition;
|
|
872
860
|
ipCidr6: (value: string, options?: {
|
|
873
861
|
readonly noResolve?: boolean;
|
|
874
|
-
readonly
|
|
875
|
-
}) => SurgeCondition;
|
|
862
|
+
readonly includeSniffed?: never;
|
|
863
|
+
} | undefined) => SurgeCondition;
|
|
876
864
|
sourceIp: (value: string, options?: {
|
|
877
865
|
readonly noResolve?: boolean;
|
|
878
|
-
readonly
|
|
879
|
-
}) => SurgeCondition;
|
|
866
|
+
readonly includeSniffed?: never;
|
|
867
|
+
} | undefined) => SurgeCondition;
|
|
880
868
|
processName: (value: string, options?: {
|
|
881
869
|
readonly noResolve?: boolean;
|
|
882
|
-
readonly
|
|
883
|
-
}) => SurgeCondition;
|
|
870
|
+
readonly includeSniffed?: never;
|
|
871
|
+
} | undefined) => SurgeCondition;
|
|
884
872
|
macAddress: (value: string, options?: {
|
|
885
873
|
readonly noResolve?: boolean;
|
|
886
|
-
readonly
|
|
887
|
-
}) => SurgeCondition;
|
|
874
|
+
readonly includeSniffed?: never;
|
|
875
|
+
} | undefined) => SurgeCondition;
|
|
888
876
|
network: (value: "tcp" | "udp", options?: {
|
|
889
877
|
readonly noResolve?: boolean;
|
|
890
|
-
readonly
|
|
878
|
+
readonly includeSniffed?: never;
|
|
891
879
|
}) => SurgeCondition;
|
|
892
880
|
port: (from: number, to?: number, options?: {
|
|
893
881
|
readonly noResolve?: boolean;
|
|
894
|
-
readonly
|
|
882
|
+
readonly includeSniffed?: never;
|
|
895
883
|
}) => SurgeCondition;
|
|
896
884
|
sourcePort: (from: number, to?: number, options?: {
|
|
897
885
|
readonly noResolve?: boolean;
|
|
898
|
-
readonly
|
|
886
|
+
readonly includeSniffed?: never;
|
|
899
887
|
}) => SurgeCondition;
|
|
900
888
|
all: (conditions: readonly SurgeCondition[], options?: {
|
|
901
889
|
readonly noResolve?: boolean;
|
|
902
|
-
readonly
|
|
890
|
+
readonly includeSniffed?: never;
|
|
903
891
|
}) => SurgeCondition;
|
|
904
892
|
any: (conditions: readonly SurgeCondition[], options?: {
|
|
905
893
|
readonly noResolve?: boolean;
|
|
906
|
-
readonly
|
|
894
|
+
readonly includeSniffed?: never;
|
|
907
895
|
}) => SurgeCondition;
|
|
908
896
|
not: (value: SurgeCondition, options?: {
|
|
909
897
|
readonly noResolve?: boolean;
|
|
910
|
-
readonly
|
|
898
|
+
readonly includeSniffed?: never;
|
|
911
899
|
}) => SurgeCondition;
|
|
912
900
|
ruleSet: (options: Omit<Extract<SurgeCondition, {
|
|
913
901
|
type: "ruleSet";
|
|
@@ -931,7 +919,7 @@ export declare const surge: {
|
|
|
931
919
|
readonly format: "rule-set" | "domain-set";
|
|
932
920
|
readonly intervalSeconds?: number;
|
|
933
921
|
readonly noResolve?: boolean;
|
|
934
|
-
readonly
|
|
922
|
+
readonly includeSniffed?: boolean;
|
|
935
923
|
};
|
|
936
924
|
};
|
|
937
925
|
};
|
|
@@ -1162,7 +1150,7 @@ export declare function runBuild(input: BuildDefinition, output: string, options
|
|
|
1162
1150
|
//#endregion
|
|
1163
1151
|
//#region src/proxy-id.d.ts
|
|
1164
1152
|
/** Stable identity independent of engine and mutable metadata. */
|
|
1165
|
-
export declare function proxyId(
|
|
1153
|
+
export declare function proxyId(namespace: string, label: string): string;
|
|
1166
1154
|
//#endregion
|
|
1167
1155
|
//#region src/secret-inputs.d.ts
|
|
1168
1156
|
type SecretsInput = {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
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";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
//#region src/proxy-fragments.ts
|
|
@@ -132,9 +132,9 @@ function renderProxyNodes(compilation, resolveSecret) {
|
|
|
132
132
|
//#endregion
|
|
133
133
|
//#region src/proxy-id.ts
|
|
134
134
|
/** Stable identity independent of engine and mutable metadata. */
|
|
135
|
-
function proxyId(
|
|
136
|
-
if (typeof
|
|
137
|
-
return `node-${createHash("sha256").update(JSON.stringify([
|
|
135
|
+
function proxyId(namespace, label) {
|
|
136
|
+
if (typeof namespace !== "string" || !namespace.length || typeof label !== "string" || !label.length) throw new Error("INVALID_PROXY_ID_INPUT");
|
|
137
|
+
return `node-${createHash("sha256").update(JSON.stringify([namespace, label])).digest("hex").slice(0, 16)}`;
|
|
138
138
|
}
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/secret-inputs.ts
|
|
@@ -191,4 +191,4 @@ function secrets(input, environment = process.env) {
|
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
193
|
//#endregion
|
|
194
|
-
export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildToDirectory, checkBuild, compile, compileProfile, compileProxyNodes, compileStrategyGroups, compileSurgeProfile, defineBuild, defineConfig, defineProfile, defineProxyGroup, defineRoute, defineRoutes, direct, dnsRule, explain, group, match, mihomo, outbound, policy, proxy, proxyId, reject, render, renderProxyNodes, renderSurgeProfile, renderSurgeProfiles, route, rule, ruleSet, runBuild, secret, secrets,
|
|
194
|
+
export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildToDirectory, checkBuild, compile, compileProfile, compileProxyNodes, compileStrategyGroups, compileSurgeProfile, defineBuild, defineConfig, defineProfile, defineProxyGroup, defineRoute, defineRoutes, direct, dnsRule, explain, group, match, mihomo, outbound, policy, proxy, proxyId, reject, render, renderProxyNodes, renderSurgeProfile, renderSurgeProfiles, route, rule, ruleSet, runBuild, secret, secrets, sequence, singbox, slot, strategy, surge, targetCatalog, use };
|
|
@@ -1,30 +1,14 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { isIP } from "node:net";
|
|
2
|
+
import { z } from "zod";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import ipaddr from "ipaddr.js";
|
|
5
5
|
import { stringify } from "yaml";
|
|
6
6
|
import { lstat, mkdir, readlink, rename, rm, symlink, writeFile } from "node:fs/promises";
|
|
7
7
|
import { join, resolve } from "node:path";
|
|
8
|
-
//#region src/
|
|
9
|
-
|
|
10
|
-
"destination",
|
|
11
|
-
"tlsSni",
|
|
12
|
-
"httpHost"
|
|
13
|
-
];
|
|
14
|
-
const domainSourcesSchema = z.array(z.enum(order)).min(1).max(3).refine((sources) => new Set(sources).size === sources.length);
|
|
15
|
-
function supportsDomainSources(sources, engine) {
|
|
16
|
-
return sources === void 0 || sources.length === 1 && sources[0] === "destination" || engine === "surge" && sources.length === 3;
|
|
17
|
-
}
|
|
18
|
-
function extendedDomainSources(sources) {
|
|
19
|
-
return sources?.length === 3;
|
|
20
|
-
}
|
|
21
|
-
/** Identity only: preserve author snapshots and all non-source options. */
|
|
8
|
+
//#region src/match-identity.ts
|
|
9
|
+
/** Identity only: preserve explicit false in author snapshots. */
|
|
22
10
|
function domainIdentityFields(value) {
|
|
23
|
-
return Object.entries(value).
|
|
24
|
-
if (key !== "sources" || field === void 0) return [key, field];
|
|
25
|
-
const sources = field;
|
|
26
|
-
return [key, sources.length === 1 && sources[0] === "destination" ? void 0 : order.filter((source) => sources.includes(source))];
|
|
27
|
-
}).filter(([, field]) => field !== void 0).sort(([a], [b]) => a.localeCompare(b));
|
|
11
|
+
return Object.entries(value).filter(([key, field]) => field !== void 0 && !(key === "includeSniffed" && field === false)).sort(([a], [b]) => a.localeCompare(b));
|
|
28
12
|
}
|
|
29
13
|
//#endregion
|
|
30
14
|
//#region src/dns.ts
|
|
@@ -212,21 +196,6 @@ function defineRoutes(input) {
|
|
|
212
196
|
to: input.to
|
|
213
197
|
}));
|
|
214
198
|
}
|
|
215
|
-
function selectProxies(nodes, query = {}) {
|
|
216
|
-
inspectDefinition({
|
|
217
|
-
nodes,
|
|
218
|
-
query
|
|
219
|
-
});
|
|
220
|
-
exactDefinition(query, [
|
|
221
|
-
"ids",
|
|
222
|
-
"regions",
|
|
223
|
-
"providers",
|
|
224
|
-
"tags"
|
|
225
|
-
]);
|
|
226
|
-
if (!Array.isArray(nodes) || nodes.some((node) => !node || typeof node !== "object")) fail$1("DEFINITION_NOT_DATA");
|
|
227
|
-
for (const values of Object.values(query)) if (values !== void 0 && !Array.isArray(values)) fail$1("DEFINITION_NOT_DATA");
|
|
228
|
-
return nodes.filter((node) => (!query.ids || query.ids.includes(node.id)) && (!query.regions || node.region !== void 0 && query.regions.includes(node.region)) && (!query.providers || node.provider !== void 0 && query.providers.includes(node.provider)) && (!query.tags || query.tags.every((tag) => node.tags?.includes(tag))));
|
|
229
|
-
}
|
|
230
199
|
function lowerSurgeProfile(input) {
|
|
231
200
|
inspectDefinition(input);
|
|
232
201
|
exactDefinition(input, [
|
|
@@ -323,11 +292,28 @@ function lowerSurgeProfile(input) {
|
|
|
323
292
|
}
|
|
324
293
|
function condition(value) {
|
|
325
294
|
inspectDefinition(value);
|
|
295
|
+
exactDefinition(value, [
|
|
296
|
+
"type",
|
|
297
|
+
"noResolve",
|
|
298
|
+
...value.type === "ruleSet" ? [
|
|
299
|
+
"format",
|
|
300
|
+
"url",
|
|
301
|
+
"builtin",
|
|
302
|
+
"intervalSeconds"
|
|
303
|
+
] : value.type === "all" || value.type === "any" ? ["conditions"] : value.type === "not" ? ["condition"] : value.type === "port" || value.type === "sourcePort" ? ["from", "to"] : ["value"],
|
|
304
|
+
...[
|
|
305
|
+
"domain",
|
|
306
|
+
"domainSuffix",
|
|
307
|
+
"ruleSet"
|
|
308
|
+
].includes(value.type) ? ["includeSniffed"] : []
|
|
309
|
+
]);
|
|
310
|
+
if (value.includeSniffed !== void 0 && typeof value.includeSniffed !== "boolean") throw new ProfileDefinitionError("INVALID_MATCH_OPTIONS");
|
|
326
311
|
return value;
|
|
327
312
|
}
|
|
328
313
|
function atom$2(type) {
|
|
329
|
-
return (value, options
|
|
330
|
-
inspectDefinition(options);
|
|
314
|
+
return (value, options) => {
|
|
315
|
+
inspectDefinition(options ?? {});
|
|
316
|
+
exactDefinition(options ?? {}, ["noResolve", ...["domain", "domainSuffix"].includes(type) ? ["includeSniffed"] : []]);
|
|
331
317
|
return condition({
|
|
332
318
|
...options,
|
|
333
319
|
type,
|
|
@@ -452,7 +438,7 @@ const nativeRuleSetSchema = z.discriminatedUnion("engine", [
|
|
|
452
438
|
format: z.enum(["rule-set", "domain-set"]),
|
|
453
439
|
intervalSeconds: updateInterval.optional(),
|
|
454
440
|
noResolve: z.boolean().optional(),
|
|
455
|
-
|
|
441
|
+
includeSniffed: z.boolean().optional()
|
|
456
442
|
}),
|
|
457
443
|
z.strictObject({
|
|
458
444
|
...remoteBase,
|
|
@@ -482,12 +468,12 @@ const matchSchema = z.lazy(() => z.discriminatedUnion("type", [
|
|
|
482
468
|
z.strictObject({
|
|
483
469
|
type: z.literal("domain"),
|
|
484
470
|
value: domain$1,
|
|
485
|
-
|
|
471
|
+
includeSniffed: z.boolean().optional()
|
|
486
472
|
}),
|
|
487
473
|
z.strictObject({
|
|
488
474
|
type: z.literal("domainSuffix"),
|
|
489
475
|
value: domain$1,
|
|
490
|
-
|
|
476
|
+
includeSniffed: z.boolean().optional()
|
|
491
477
|
}),
|
|
492
478
|
z.strictObject({
|
|
493
479
|
type: z.literal("ipCidr"),
|
|
@@ -565,10 +551,7 @@ const nodeBase = {
|
|
|
565
551
|
port: port$1,
|
|
566
552
|
via: idSchema.optional(),
|
|
567
553
|
tcpFastOpen: z.boolean().optional(),
|
|
568
|
-
label: z.string().min(1).max(256).optional()
|
|
569
|
-
region: z.string().regex(/^[A-Z]{2}$/).optional(),
|
|
570
|
-
provider: idSchema.optional(),
|
|
571
|
-
tags: z.array(idSchema).refine(unique).optional()
|
|
554
|
+
label: z.string().min(1).max(256).optional()
|
|
572
555
|
};
|
|
573
556
|
const tlsSchema = z.strictObject({
|
|
574
557
|
serverName: domain$1,
|
|
@@ -790,8 +773,9 @@ function assertData(value) {
|
|
|
790
773
|
if (typeof v !== "object" || ancestors.has(v)) throw new Error("INPUT_GRAPH");
|
|
791
774
|
if (!Array.isArray(v) && Object.getPrototypeOf(v) !== Object.prototype && Object.getPrototypeOf(v) !== null) throw new Error("INPUT_OBJECT");
|
|
792
775
|
ancestors.add(v);
|
|
793
|
-
for (const
|
|
794
|
-
|
|
776
|
+
for (const key of Reflect.ownKeys(v)) {
|
|
777
|
+
const descriptor = Object.getOwnPropertyDescriptor(v, key);
|
|
778
|
+
if (typeof key !== "string" || !("value" in descriptor) || !descriptor.enumerable && !(Array.isArray(v) && key === "length")) throw new Error("INPUT_OBJECT");
|
|
795
779
|
visit(descriptor.value, depth + 1);
|
|
796
780
|
}
|
|
797
781
|
ancestors.delete(v);
|
|
@@ -1030,7 +1014,11 @@ function evaluate(condition, request) {
|
|
|
1030
1014
|
switch (condition.type) {
|
|
1031
1015
|
case "domain":
|
|
1032
1016
|
case "domainSuffix": {
|
|
1033
|
-
const domains =
|
|
1017
|
+
const domains = condition.includeSniffed ? [
|
|
1018
|
+
request.domain,
|
|
1019
|
+
request.tlsSni,
|
|
1020
|
+
request.httpHost
|
|
1021
|
+
] : [request.domain];
|
|
1034
1022
|
present = domains.some((value) => value !== void 0);
|
|
1035
1023
|
matched = domains.some((value) => value !== void 0 && (value === condition.value || condition.type === "domainSuffix" && value.endsWith(`.${condition.value}`)));
|
|
1036
1024
|
break;
|
|
@@ -1829,7 +1817,7 @@ function compile(input) {
|
|
|
1829
1817
|
for (const rule of rules) if (logicalDepth(rule.when) > 10) error("LOGICAL_DEPTH", rule.id, "Surge 逻辑条件最多嵌套 10 层", target.id);
|
|
1830
1818
|
}
|
|
1831
1819
|
const checkOptions = (condition) => {
|
|
1832
|
-
if ("
|
|
1820
|
+
if ("includeSniffed" in condition && condition.includeSniffed === true && target.engine !== "surge" || condition.type === "ipCidr" && condition.noResolve !== void 0 && target.engine === "sing-box") error("MATCH_OPTION_UNSUPPORTED", path, "目标无法等价实现显式匹配选项", target.id);
|
|
1833
1821
|
if (condition.type === "all" || condition.type === "any") condition.conditions.forEach(checkOptions);
|
|
1834
1822
|
else if (condition.type === "not") checkOptions(condition.condition);
|
|
1835
1823
|
else if (condition.type === "ruleSet") checkOptions(condition.when);
|
|
@@ -2080,14 +2068,15 @@ const groupSchema = z.strictObject({
|
|
|
2080
2068
|
intervalSeconds: z.number().int().positive().max(2147483647).optional(),
|
|
2081
2069
|
timeoutSeconds: z.number().int().positive().max(3600).optional()
|
|
2082
2070
|
});
|
|
2083
|
-
const options$1 = {
|
|
2084
|
-
|
|
2085
|
-
|
|
2071
|
+
const options$1 = { noResolve: z.boolean().optional() };
|
|
2072
|
+
const domainOptions = {
|
|
2073
|
+
...options$1,
|
|
2074
|
+
includeSniffed: z.boolean().optional()
|
|
2086
2075
|
};
|
|
2087
2076
|
const atom = (type, value) => z.strictObject({
|
|
2088
2077
|
type: z.literal(type),
|
|
2089
2078
|
value,
|
|
2090
|
-
...options$1
|
|
2079
|
+
...["domain", "domainSuffix"].includes(type) ? domainOptions : options$1
|
|
2091
2080
|
});
|
|
2092
2081
|
const conditionSchema = z.lazy(() => z.union([
|
|
2093
2082
|
atom("domain", domain),
|
|
@@ -2124,7 +2113,7 @@ const conditionSchema = z.lazy(() => z.union([
|
|
|
2124
2113
|
url: url.optional(),
|
|
2125
2114
|
builtin: z.enum(["LAN", "SYSTEM"]).optional(),
|
|
2126
2115
|
intervalSeconds: z.number().int().min(60).max(2147483647).optional(),
|
|
2127
|
-
...
|
|
2116
|
+
...domainOptions
|
|
2128
2117
|
}).refine((v) => v.url !== void 0 !== (v.builtin !== void 0))
|
|
2129
2118
|
]));
|
|
2130
2119
|
const managedSchema = z.strictObject({
|
|
@@ -2257,12 +2246,11 @@ function compileSurgeProfile(input) {
|
|
|
2257
2246
|
"ipCidr6",
|
|
2258
2247
|
"ruleSet"
|
|
2259
2248
|
].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
|
|
2260
|
-
if (c.
|
|
2249
|
+
if (c.includeSniffed !== void 0 && ![
|
|
2261
2250
|
"domain",
|
|
2262
2251
|
"domainSuffix",
|
|
2263
2252
|
"ruleSet"
|
|
2264
2253
|
].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
|
|
2265
|
-
if (c.sources !== void 0 && !supportsDomainSources(c.sources, "surge")) error("MATCH_OPTION_UNSUPPORTED");
|
|
2266
2254
|
if (p.target.platform === "ios" && ["processName", "macAddress"].includes(c.type)) error("PLATFORM_RULE_UNSUPPORTED");
|
|
2267
2255
|
if (c.type === "all" || c.type === "any") for (const child of c.conditions) checkCondition(child, depth + 1);
|
|
2268
2256
|
if (c.type === "not") checkCondition(c.condition, depth + 1);
|
|
@@ -2301,7 +2289,7 @@ function compileSurgeProfile(input) {
|
|
|
2301
2289
|
function conditionOptions(c) {
|
|
2302
2290
|
return [
|
|
2303
2291
|
...c.noResolve ? ["no-resolve"] : [],
|
|
2304
|
-
...
|
|
2292
|
+
..."includeSniffed" in c && c.includeSniffed ? ["extended-matching"] : [],
|
|
2305
2293
|
...c.type === "ruleSet" && c.intervalSeconds !== void 0 ? [`update-interval=${c.intervalSeconds}`] : []
|
|
2306
2294
|
];
|
|
2307
2295
|
}
|
|
@@ -2540,7 +2528,7 @@ function surgeCondition$1(condition, depth = 0) {
|
|
|
2540
2528
|
url: value.url,
|
|
2541
2529
|
...value.intervalSeconds !== void 0 ? { intervalSeconds: value.intervalSeconds } : {},
|
|
2542
2530
|
...value.noResolve !== void 0 ? { noResolve: value.noResolve } : {},
|
|
2543
|
-
...value.
|
|
2531
|
+
...value.includeSniffed !== void 0 ? { includeSniffed: value.includeSniffed } : {}
|
|
2544
2532
|
};
|
|
2545
2533
|
}
|
|
2546
2534
|
if (condition.type === "all" || condition.type === "any") {
|
|
@@ -2569,6 +2557,25 @@ function compileProfile(input) {
|
|
|
2569
2557
|
try {
|
|
2570
2558
|
const profile = defineProfile(input);
|
|
2571
2559
|
snapshotDefinition(profile.routes.map((route) => route.when));
|
|
2560
|
+
const ruleSets = [];
|
|
2561
|
+
const collectRuleSets = (condition) => {
|
|
2562
|
+
if (condition.type === "nativeRuleSet" || condition.type === "ruleSet" && "when" in condition) {
|
|
2563
|
+
const parsed = matchSchema.safeParse(condition);
|
|
2564
|
+
if (!parsed.success) return fail("PROFILE_CONDITION_UNSUPPORTED");
|
|
2565
|
+
ruleSets.push({
|
|
2566
|
+
type: "rule",
|
|
2567
|
+
id: `ruleset-${ruleSets.length}`,
|
|
2568
|
+
when: parsed.data,
|
|
2569
|
+
then: { type: "direct" }
|
|
2570
|
+
});
|
|
2571
|
+
} else if (condition.type === "all" || condition.type === "any") condition.conditions.forEach(collectRuleSets);
|
|
2572
|
+
else if (condition.type === "not") collectRuleSets(condition.condition);
|
|
2573
|
+
};
|
|
2574
|
+
profile.routes.forEach((route) => collectRuleSets(route.when));
|
|
2575
|
+
const ruleSetDiagnostics = [];
|
|
2576
|
+
validateRuleSets(ruleSets, profile.target.engine, ruleSetDiagnostics, "routes");
|
|
2577
|
+
const ruleSetError = ruleSetDiagnostics.find((diagnostic) => diagnostic.severity === "error");
|
|
2578
|
+
if (ruleSetError) return fail(ruleSetError.code);
|
|
2572
2579
|
const nodes = profile.proxies.filter((proxy) => !isEndpoint(proxy));
|
|
2573
2580
|
const endpoints = profile.proxies.filter(isEndpoint);
|
|
2574
2581
|
if (profile.target.engine === "surge") {
|
|
@@ -2732,15 +2739,18 @@ function dnsRule(pattern, server) {
|
|
|
2732
2739
|
if (!checked.success) throw new ProfileDefinitionError("INVALID_DNS_RULE");
|
|
2733
2740
|
return batch ? checked.data : checked.data[0];
|
|
2734
2741
|
}
|
|
2735
|
-
const ruleSet = (definition) =>
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2742
|
+
const ruleSet = (definition) => {
|
|
2743
|
+
inspectDefinition(definition);
|
|
2744
|
+
exactDefinition(definition, ["id", "when"]);
|
|
2745
|
+
return snapshotDefinition({
|
|
2746
|
+
...definition,
|
|
2747
|
+
type: "ruleSet"
|
|
2748
|
+
});
|
|
2749
|
+
};
|
|
2739
2750
|
function options(value, keys) {
|
|
2740
2751
|
inspectDefinition(value);
|
|
2741
2752
|
exactDefinition(value, keys);
|
|
2742
|
-
if (
|
|
2743
|
-
if (Object.entries(value).some(([key, v]) => key !== "sources" && v !== void 0 && typeof v !== "boolean")) throw new ProfileDefinitionError("INVALID_MATCH_OPTIONS");
|
|
2753
|
+
if (Object.values(value).some((v) => v !== void 0 && typeof v !== "boolean")) throw new ProfileDefinitionError("INVALID_MATCH_OPTIONS");
|
|
2744
2754
|
return snapshotDefinition(value);
|
|
2745
2755
|
}
|
|
2746
2756
|
const match = {
|
|
@@ -2755,12 +2765,12 @@ const match = {
|
|
|
2755
2765
|
domain: (value, opts = {}) => ({
|
|
2756
2766
|
type: "domain",
|
|
2757
2767
|
value,
|
|
2758
|
-
...options(opts, ["
|
|
2768
|
+
...options(opts, ["includeSniffed"])
|
|
2759
2769
|
}),
|
|
2760
2770
|
domainSuffix: (value, opts = {}) => ({
|
|
2761
2771
|
type: "domainSuffix",
|
|
2762
2772
|
value,
|
|
2763
|
-
...options(opts, ["
|
|
2773
|
+
...options(opts, ["includeSniffed"])
|
|
2764
2774
|
}),
|
|
2765
2775
|
ipCidr: (value, opts = {}) => ({
|
|
2766
2776
|
type: "ipCidr",
|
|
@@ -2808,7 +2818,7 @@ function nativeConstructor(engine) {
|
|
|
2808
2818
|
"format",
|
|
2809
2819
|
"intervalSeconds",
|
|
2810
2820
|
"noResolve",
|
|
2811
|
-
"
|
|
2821
|
+
"includeSniffed",
|
|
2812
2822
|
"behavior",
|
|
2813
2823
|
"to"
|
|
2814
2824
|
]);
|
|
@@ -2819,7 +2829,7 @@ function nativeConstructor(engine) {
|
|
|
2819
2829
|
"url",
|
|
2820
2830
|
"format",
|
|
2821
2831
|
"intervalSeconds",
|
|
2822
|
-
...engine === "surge" ? ["noResolve", "
|
|
2832
|
+
...engine === "surge" ? ["noResolve", "includeSniffed"] : engine === "mihomo" ? ["behavior"] : []
|
|
2823
2833
|
]);
|
|
2824
2834
|
const parsed = nativeRuleSetSchema.safeParse({
|
|
2825
2835
|
...engine === "surge" ? { format: "rule-set" } : {},
|
|
@@ -2889,10 +2899,6 @@ const use = (definition, options) => ({
|
|
|
2889
2899
|
});
|
|
2890
2900
|
const sequence = (...parts) => parts.flatMap((part) => Array.isArray(part) ? part : [part]);
|
|
2891
2901
|
const defineConfig = (config) => config;
|
|
2892
|
-
/** Filtering is stable: catalogue order determines initial selector order. */
|
|
2893
|
-
function selectNodes(nodes, query = {}) {
|
|
2894
|
-
return nodes.filter((node) => (!query.regions || node.region !== void 0 && query.regions.includes(node.region)) && (!query.providers || node.provider !== void 0 && query.providers.includes(node.provider)) && (!query.tags || query.tags.every((tag) => node.tags?.includes(tag)))).map((node) => node.id);
|
|
2895
|
-
}
|
|
2896
2902
|
/** A shared strategy declares an algorithm or explicitly selects native implementations. */
|
|
2897
2903
|
const strategy = (definition) => ({
|
|
2898
2904
|
type: "strategy",
|
|
@@ -3123,7 +3129,7 @@ function surgeOptions(condition) {
|
|
|
3123
3129
|
return [
|
|
3124
3130
|
...condition.type === "ipCidr" && condition.noResolve !== false ? ["no-resolve"] : [],
|
|
3125
3131
|
...condition.type === "nativeRuleSet" && condition.engine === "surge" && condition.noResolve ? ["no-resolve"] : [],
|
|
3126
|
-
..."
|
|
3132
|
+
..."includeSniffed" in condition && condition.includeSniffed ? ["extended-matching"] : []
|
|
3127
3133
|
].map((value) => `,${value}`).join("");
|
|
3128
3134
|
}
|
|
3129
3135
|
function surgeCondition(condition) {
|
|
@@ -3599,4 +3605,4 @@ async function runBuild(input, output, options = {}) {
|
|
|
3599
3605
|
};
|
|
3600
3606
|
}
|
|
3601
3607
|
//#endregion
|
|
3602
|
-
export {
|
|
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 };
|
package/package.json
CHANGED