proxylang 0.8.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 +2 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +42 -39
- package/dist/index.js +1 -1
- package/dist/{profile-build-DuHp9nQt.js → profile-build-Dg7xfQbi.js} +74 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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 { 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-
|
|
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";
|
|
@@ -439,32 +438,38 @@ declare const groupSchema: z.ZodObject<{
|
|
|
439
438
|
timeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
440
439
|
}, z.core.$strict>;
|
|
441
440
|
type SurgeGroup = z.infer<typeof groupSchema>;
|
|
442
|
-
type
|
|
443
|
-
readonly
|
|
444
|
-
readonly sources?: readonly DomainSource[];
|
|
441
|
+
type NoSniff = {
|
|
442
|
+
readonly includeSniffed?: never;
|
|
445
443
|
};
|
|
446
|
-
type SurgeCondition =
|
|
447
|
-
readonly
|
|
444
|
+
type SurgeCondition = {
|
|
445
|
+
readonly noResolve?: boolean;
|
|
446
|
+
} & ({
|
|
447
|
+
readonly type: "domain" | "domainSuffix";
|
|
448
448
|
readonly value: string;
|
|
449
|
-
|
|
449
|
+
readonly includeSniffed?: boolean;
|
|
450
|
+
} | (NoSniff & {
|
|
451
|
+
readonly type: "ipCidr" | "ipCidr6" | "sourceIp" | "processName" | "macAddress";
|
|
452
|
+
readonly value: string;
|
|
453
|
+
}) | (NoSniff & {
|
|
450
454
|
readonly type: "port" | "sourcePort";
|
|
451
455
|
readonly from: number;
|
|
452
456
|
readonly to?: number;
|
|
453
|
-
} | {
|
|
457
|
+
}) | (NoSniff & {
|
|
454
458
|
readonly type: "network";
|
|
455
459
|
readonly value: "tcp" | "udp";
|
|
456
|
-
} | {
|
|
460
|
+
}) | (NoSniff & {
|
|
457
461
|
readonly type: "all" | "any";
|
|
458
462
|
readonly conditions: readonly SurgeCondition[];
|
|
459
|
-
} | {
|
|
463
|
+
}) | (NoSniff & {
|
|
460
464
|
readonly type: "not";
|
|
461
465
|
readonly condition: SurgeCondition;
|
|
462
|
-
} | {
|
|
466
|
+
}) | {
|
|
463
467
|
readonly type: "ruleSet";
|
|
464
468
|
readonly format: "rule-set" | "domain-set";
|
|
465
469
|
readonly url?: string;
|
|
466
470
|
readonly builtin?: "LAN" | "SYSTEM";
|
|
467
471
|
readonly intervalSeconds?: number;
|
|
472
|
+
readonly includeSniffed?: boolean;
|
|
468
473
|
});
|
|
469
474
|
type SurgeRule = {
|
|
470
475
|
readonly when: SurgeCondition;
|
|
@@ -655,12 +660,10 @@ type ProfileCondition = Exclude<Match | SurgeCondition, {
|
|
|
655
660
|
readonly type: "all" | "any";
|
|
656
661
|
readonly conditions: readonly ProfileCondition[];
|
|
657
662
|
readonly noResolve?: boolean;
|
|
658
|
-
readonly sources?: readonly DomainSource[];
|
|
659
663
|
} | {
|
|
660
664
|
readonly type: "not";
|
|
661
665
|
readonly condition: ProfileCondition;
|
|
662
666
|
readonly noResolve?: boolean;
|
|
663
|
-
readonly sources?: readonly DomainSource[];
|
|
664
667
|
};
|
|
665
668
|
type ProfileDestination = string | ProxyNode | ProxyGroupDefinition | SurgeTunnel | TailscaleEndpoint | {
|
|
666
669
|
readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
|
|
@@ -733,7 +736,7 @@ export declare function dnsRule(pattern: string, server: string): DnsRule;
|
|
|
733
736
|
export declare function dnsRule(patterns: readonly string[], server: string): DnsRule[];
|
|
734
737
|
export declare const ruleSet: (definition: Omit<NamedRuleSet, "type">) => NamedRuleSet;
|
|
735
738
|
type DomainOptions = {
|
|
736
|
-
readonly
|
|
739
|
+
readonly includeSniffed?: boolean;
|
|
737
740
|
};
|
|
738
741
|
type IpOptions = {
|
|
739
742
|
readonly noResolve?: boolean;
|
|
@@ -745,12 +748,12 @@ export declare const match: {
|
|
|
745
748
|
};
|
|
746
749
|
ruleSet: (set: NamedRuleSet) => NamedRuleSet;
|
|
747
750
|
domain: (value: string, opts?: DomainOptions) => {
|
|
748
|
-
|
|
751
|
+
includeSniffed?: boolean;
|
|
749
752
|
type: "domain";
|
|
750
753
|
value: string;
|
|
751
754
|
};
|
|
752
755
|
domainSuffix: (value: string, opts?: DomainOptions) => {
|
|
753
|
-
|
|
756
|
+
includeSniffed?: boolean;
|
|
754
757
|
type: "domainSuffix";
|
|
755
758
|
value: string;
|
|
756
759
|
};
|
|
@@ -844,55 +847,55 @@ export declare const surge: {
|
|
|
844
847
|
match: {
|
|
845
848
|
domain: (value: string, options?: {
|
|
846
849
|
readonly noResolve?: boolean;
|
|
847
|
-
readonly
|
|
848
|
-
}) => SurgeCondition;
|
|
850
|
+
readonly includeSniffed?: boolean;
|
|
851
|
+
} | undefined) => SurgeCondition;
|
|
849
852
|
domainSuffix: (value: string, options?: {
|
|
850
853
|
readonly noResolve?: boolean;
|
|
851
|
-
readonly
|
|
852
|
-
}) => SurgeCondition;
|
|
854
|
+
readonly includeSniffed?: boolean;
|
|
855
|
+
} | undefined) => SurgeCondition;
|
|
853
856
|
ipCidr: (value: string, options?: {
|
|
854
857
|
readonly noResolve?: boolean;
|
|
855
|
-
readonly
|
|
856
|
-
}) => SurgeCondition;
|
|
858
|
+
readonly includeSniffed?: never;
|
|
859
|
+
} | undefined) => SurgeCondition;
|
|
857
860
|
ipCidr6: (value: string, options?: {
|
|
858
861
|
readonly noResolve?: boolean;
|
|
859
|
-
readonly
|
|
860
|
-
}) => SurgeCondition;
|
|
862
|
+
readonly includeSniffed?: never;
|
|
863
|
+
} | undefined) => SurgeCondition;
|
|
861
864
|
sourceIp: (value: string, options?: {
|
|
862
865
|
readonly noResolve?: boolean;
|
|
863
|
-
readonly
|
|
864
|
-
}) => SurgeCondition;
|
|
866
|
+
readonly includeSniffed?: never;
|
|
867
|
+
} | undefined) => SurgeCondition;
|
|
865
868
|
processName: (value: string, options?: {
|
|
866
869
|
readonly noResolve?: boolean;
|
|
867
|
-
readonly
|
|
868
|
-
}) => SurgeCondition;
|
|
870
|
+
readonly includeSniffed?: never;
|
|
871
|
+
} | undefined) => SurgeCondition;
|
|
869
872
|
macAddress: (value: string, options?: {
|
|
870
873
|
readonly noResolve?: boolean;
|
|
871
|
-
readonly
|
|
872
|
-
}) => SurgeCondition;
|
|
874
|
+
readonly includeSniffed?: never;
|
|
875
|
+
} | undefined) => SurgeCondition;
|
|
873
876
|
network: (value: "tcp" | "udp", options?: {
|
|
874
877
|
readonly noResolve?: boolean;
|
|
875
|
-
readonly
|
|
878
|
+
readonly includeSniffed?: never;
|
|
876
879
|
}) => SurgeCondition;
|
|
877
880
|
port: (from: number, to?: number, options?: {
|
|
878
881
|
readonly noResolve?: boolean;
|
|
879
|
-
readonly
|
|
882
|
+
readonly includeSniffed?: never;
|
|
880
883
|
}) => SurgeCondition;
|
|
881
884
|
sourcePort: (from: number, to?: number, options?: {
|
|
882
885
|
readonly noResolve?: boolean;
|
|
883
|
-
readonly
|
|
886
|
+
readonly includeSniffed?: never;
|
|
884
887
|
}) => SurgeCondition;
|
|
885
888
|
all: (conditions: readonly SurgeCondition[], options?: {
|
|
886
889
|
readonly noResolve?: boolean;
|
|
887
|
-
readonly
|
|
890
|
+
readonly includeSniffed?: never;
|
|
888
891
|
}) => SurgeCondition;
|
|
889
892
|
any: (conditions: readonly SurgeCondition[], options?: {
|
|
890
893
|
readonly noResolve?: boolean;
|
|
891
|
-
readonly
|
|
894
|
+
readonly includeSniffed?: never;
|
|
892
895
|
}) => SurgeCondition;
|
|
893
896
|
not: (value: SurgeCondition, options?: {
|
|
894
897
|
readonly noResolve?: boolean;
|
|
895
|
-
readonly
|
|
898
|
+
readonly includeSniffed?: never;
|
|
896
899
|
}) => SurgeCondition;
|
|
897
900
|
ruleSet: (options: Omit<Extract<SurgeCondition, {
|
|
898
901
|
type: "ruleSet";
|
|
@@ -916,7 +919,7 @@ export declare const surge: {
|
|
|
916
919
|
readonly format: "rule-set" | "domain-set";
|
|
917
920
|
readonly intervalSeconds?: number;
|
|
918
921
|
readonly noResolve?: boolean;
|
|
919
|
-
readonly
|
|
922
|
+
readonly includeSniffed?: boolean;
|
|
920
923
|
};
|
|
921
924
|
};
|
|
922
925
|
};
|
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-
|
|
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
|
|
@@ -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
|
|
@@ -308,11 +292,28 @@ function lowerSurgeProfile(input) {
|
|
|
308
292
|
}
|
|
309
293
|
function condition(value) {
|
|
310
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");
|
|
311
311
|
return value;
|
|
312
312
|
}
|
|
313
313
|
function atom$2(type) {
|
|
314
|
-
return (value, options
|
|
315
|
-
inspectDefinition(options);
|
|
314
|
+
return (value, options) => {
|
|
315
|
+
inspectDefinition(options ?? {});
|
|
316
|
+
exactDefinition(options ?? {}, ["noResolve", ...["domain", "domainSuffix"].includes(type) ? ["includeSniffed"] : []]);
|
|
316
317
|
return condition({
|
|
317
318
|
...options,
|
|
318
319
|
type,
|
|
@@ -437,7 +438,7 @@ const nativeRuleSetSchema = z.discriminatedUnion("engine", [
|
|
|
437
438
|
format: z.enum(["rule-set", "domain-set"]),
|
|
438
439
|
intervalSeconds: updateInterval.optional(),
|
|
439
440
|
noResolve: z.boolean().optional(),
|
|
440
|
-
|
|
441
|
+
includeSniffed: z.boolean().optional()
|
|
441
442
|
}),
|
|
442
443
|
z.strictObject({
|
|
443
444
|
...remoteBase,
|
|
@@ -467,12 +468,12 @@ const matchSchema = z.lazy(() => z.discriminatedUnion("type", [
|
|
|
467
468
|
z.strictObject({
|
|
468
469
|
type: z.literal("domain"),
|
|
469
470
|
value: domain$1,
|
|
470
|
-
|
|
471
|
+
includeSniffed: z.boolean().optional()
|
|
471
472
|
}),
|
|
472
473
|
z.strictObject({
|
|
473
474
|
type: z.literal("domainSuffix"),
|
|
474
475
|
value: domain$1,
|
|
475
|
-
|
|
476
|
+
includeSniffed: z.boolean().optional()
|
|
476
477
|
}),
|
|
477
478
|
z.strictObject({
|
|
478
479
|
type: z.literal("ipCidr"),
|
|
@@ -1013,7 +1014,11 @@ function evaluate(condition, request) {
|
|
|
1013
1014
|
switch (condition.type) {
|
|
1014
1015
|
case "domain":
|
|
1015
1016
|
case "domainSuffix": {
|
|
1016
|
-
const domains =
|
|
1017
|
+
const domains = condition.includeSniffed ? [
|
|
1018
|
+
request.domain,
|
|
1019
|
+
request.tlsSni,
|
|
1020
|
+
request.httpHost
|
|
1021
|
+
] : [request.domain];
|
|
1017
1022
|
present = domains.some((value) => value !== void 0);
|
|
1018
1023
|
matched = domains.some((value) => value !== void 0 && (value === condition.value || condition.type === "domainSuffix" && value.endsWith(`.${condition.value}`)));
|
|
1019
1024
|
break;
|
|
@@ -1812,7 +1817,7 @@ function compile(input) {
|
|
|
1812
1817
|
for (const rule of rules) if (logicalDepth(rule.when) > 10) error("LOGICAL_DEPTH", rule.id, "Surge 逻辑条件最多嵌套 10 层", target.id);
|
|
1813
1818
|
}
|
|
1814
1819
|
const checkOptions = (condition) => {
|
|
1815
|
-
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);
|
|
1816
1821
|
if (condition.type === "all" || condition.type === "any") condition.conditions.forEach(checkOptions);
|
|
1817
1822
|
else if (condition.type === "not") checkOptions(condition.condition);
|
|
1818
1823
|
else if (condition.type === "ruleSet") checkOptions(condition.when);
|
|
@@ -2063,14 +2068,15 @@ const groupSchema = z.strictObject({
|
|
|
2063
2068
|
intervalSeconds: z.number().int().positive().max(2147483647).optional(),
|
|
2064
2069
|
timeoutSeconds: z.number().int().positive().max(3600).optional()
|
|
2065
2070
|
});
|
|
2066
|
-
const options$1 = {
|
|
2067
|
-
|
|
2068
|
-
|
|
2071
|
+
const options$1 = { noResolve: z.boolean().optional() };
|
|
2072
|
+
const domainOptions = {
|
|
2073
|
+
...options$1,
|
|
2074
|
+
includeSniffed: z.boolean().optional()
|
|
2069
2075
|
};
|
|
2070
2076
|
const atom = (type, value) => z.strictObject({
|
|
2071
2077
|
type: z.literal(type),
|
|
2072
2078
|
value,
|
|
2073
|
-
...options$1
|
|
2079
|
+
...["domain", "domainSuffix"].includes(type) ? domainOptions : options$1
|
|
2074
2080
|
});
|
|
2075
2081
|
const conditionSchema = z.lazy(() => z.union([
|
|
2076
2082
|
atom("domain", domain),
|
|
@@ -2107,7 +2113,7 @@ const conditionSchema = z.lazy(() => z.union([
|
|
|
2107
2113
|
url: url.optional(),
|
|
2108
2114
|
builtin: z.enum(["LAN", "SYSTEM"]).optional(),
|
|
2109
2115
|
intervalSeconds: z.number().int().min(60).max(2147483647).optional(),
|
|
2110
|
-
...
|
|
2116
|
+
...domainOptions
|
|
2111
2117
|
}).refine((v) => v.url !== void 0 !== (v.builtin !== void 0))
|
|
2112
2118
|
]));
|
|
2113
2119
|
const managedSchema = z.strictObject({
|
|
@@ -2240,12 +2246,11 @@ function compileSurgeProfile(input) {
|
|
|
2240
2246
|
"ipCidr6",
|
|
2241
2247
|
"ruleSet"
|
|
2242
2248
|
].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
|
|
2243
|
-
if (c.
|
|
2249
|
+
if (c.includeSniffed !== void 0 && ![
|
|
2244
2250
|
"domain",
|
|
2245
2251
|
"domainSuffix",
|
|
2246
2252
|
"ruleSet"
|
|
2247
2253
|
].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
|
|
2248
|
-
if (c.sources !== void 0 && !supportsDomainSources(c.sources, "surge")) error("MATCH_OPTION_UNSUPPORTED");
|
|
2249
2254
|
if (p.target.platform === "ios" && ["processName", "macAddress"].includes(c.type)) error("PLATFORM_RULE_UNSUPPORTED");
|
|
2250
2255
|
if (c.type === "all" || c.type === "any") for (const child of c.conditions) checkCondition(child, depth + 1);
|
|
2251
2256
|
if (c.type === "not") checkCondition(c.condition, depth + 1);
|
|
@@ -2284,7 +2289,7 @@ function compileSurgeProfile(input) {
|
|
|
2284
2289
|
function conditionOptions(c) {
|
|
2285
2290
|
return [
|
|
2286
2291
|
...c.noResolve ? ["no-resolve"] : [],
|
|
2287
|
-
...
|
|
2292
|
+
..."includeSniffed" in c && c.includeSniffed ? ["extended-matching"] : [],
|
|
2288
2293
|
...c.type === "ruleSet" && c.intervalSeconds !== void 0 ? [`update-interval=${c.intervalSeconds}`] : []
|
|
2289
2294
|
];
|
|
2290
2295
|
}
|
|
@@ -2523,7 +2528,7 @@ function surgeCondition$1(condition, depth = 0) {
|
|
|
2523
2528
|
url: value.url,
|
|
2524
2529
|
...value.intervalSeconds !== void 0 ? { intervalSeconds: value.intervalSeconds } : {},
|
|
2525
2530
|
...value.noResolve !== void 0 ? { noResolve: value.noResolve } : {},
|
|
2526
|
-
...value.
|
|
2531
|
+
...value.includeSniffed !== void 0 ? { includeSniffed: value.includeSniffed } : {}
|
|
2527
2532
|
};
|
|
2528
2533
|
}
|
|
2529
2534
|
if (condition.type === "all" || condition.type === "any") {
|
|
@@ -2552,6 +2557,25 @@ function compileProfile(input) {
|
|
|
2552
2557
|
try {
|
|
2553
2558
|
const profile = defineProfile(input);
|
|
2554
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);
|
|
2555
2579
|
const nodes = profile.proxies.filter((proxy) => !isEndpoint(proxy));
|
|
2556
2580
|
const endpoints = profile.proxies.filter(isEndpoint);
|
|
2557
2581
|
if (profile.target.engine === "surge") {
|
|
@@ -2715,15 +2739,18 @@ function dnsRule(pattern, server) {
|
|
|
2715
2739
|
if (!checked.success) throw new ProfileDefinitionError("INVALID_DNS_RULE");
|
|
2716
2740
|
return batch ? checked.data : checked.data[0];
|
|
2717
2741
|
}
|
|
2718
|
-
const ruleSet = (definition) =>
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2742
|
+
const ruleSet = (definition) => {
|
|
2743
|
+
inspectDefinition(definition);
|
|
2744
|
+
exactDefinition(definition, ["id", "when"]);
|
|
2745
|
+
return snapshotDefinition({
|
|
2746
|
+
...definition,
|
|
2747
|
+
type: "ruleSet"
|
|
2748
|
+
});
|
|
2749
|
+
};
|
|
2722
2750
|
function options(value, keys) {
|
|
2723
2751
|
inspectDefinition(value);
|
|
2724
2752
|
exactDefinition(value, keys);
|
|
2725
|
-
if (
|
|
2726
|
-
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");
|
|
2727
2754
|
return snapshotDefinition(value);
|
|
2728
2755
|
}
|
|
2729
2756
|
const match = {
|
|
@@ -2738,12 +2765,12 @@ const match = {
|
|
|
2738
2765
|
domain: (value, opts = {}) => ({
|
|
2739
2766
|
type: "domain",
|
|
2740
2767
|
value,
|
|
2741
|
-
...options(opts, ["
|
|
2768
|
+
...options(opts, ["includeSniffed"])
|
|
2742
2769
|
}),
|
|
2743
2770
|
domainSuffix: (value, opts = {}) => ({
|
|
2744
2771
|
type: "domainSuffix",
|
|
2745
2772
|
value,
|
|
2746
|
-
...options(opts, ["
|
|
2773
|
+
...options(opts, ["includeSniffed"])
|
|
2747
2774
|
}),
|
|
2748
2775
|
ipCidr: (value, opts = {}) => ({
|
|
2749
2776
|
type: "ipCidr",
|
|
@@ -2791,7 +2818,7 @@ function nativeConstructor(engine) {
|
|
|
2791
2818
|
"format",
|
|
2792
2819
|
"intervalSeconds",
|
|
2793
2820
|
"noResolve",
|
|
2794
|
-
"
|
|
2821
|
+
"includeSniffed",
|
|
2795
2822
|
"behavior",
|
|
2796
2823
|
"to"
|
|
2797
2824
|
]);
|
|
@@ -2802,7 +2829,7 @@ function nativeConstructor(engine) {
|
|
|
2802
2829
|
"url",
|
|
2803
2830
|
"format",
|
|
2804
2831
|
"intervalSeconds",
|
|
2805
|
-
...engine === "surge" ? ["noResolve", "
|
|
2832
|
+
...engine === "surge" ? ["noResolve", "includeSniffed"] : engine === "mihomo" ? ["behavior"] : []
|
|
2806
2833
|
]);
|
|
2807
2834
|
const parsed = nativeRuleSetSchema.safeParse({
|
|
2808
2835
|
...engine === "surge" ? { format: "rule-set" } : {},
|
|
@@ -3102,7 +3129,7 @@ function surgeOptions(condition) {
|
|
|
3102
3129
|
return [
|
|
3103
3130
|
...condition.type === "ipCidr" && condition.noResolve !== false ? ["no-resolve"] : [],
|
|
3104
3131
|
...condition.type === "nativeRuleSet" && condition.engine === "surge" && condition.noResolve ? ["no-resolve"] : [],
|
|
3105
|
-
..."
|
|
3132
|
+
..."includeSniffed" in condition && condition.includeSniffed ? ["extended-matching"] : []
|
|
3106
3133
|
].map((value) => `,${value}`).join("");
|
|
3107
3134
|
}
|
|
3108
3135
|
function surgeCondition(condition) {
|
package/package.json
CHANGED