proxylang 0.6.1 → 0.8.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 +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +35 -40
- package/dist/index.js +59 -5
- package/dist/{profile-build-oexsfBwW.js → profile-build-DuHp9nQt.js} +56 -57
- 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
|
|
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-DuHp9nQt.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,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
//#region src/types.d.ts
|
|
3
|
+
export type DomainSource = "destination" | "tlsSni" | "httpHost";
|
|
3
4
|
export type Network = "tcp" | "udp";
|
|
4
5
|
export type NamedRuleSet = {
|
|
5
6
|
readonly type: "ruleSet";
|
|
@@ -15,7 +16,7 @@ export type NativeRuleSet = {
|
|
|
15
16
|
readonly format: "rule-set" | "domain-set";
|
|
16
17
|
readonly intervalSeconds?: number;
|
|
17
18
|
readonly noResolve?: boolean;
|
|
18
|
-
readonly
|
|
19
|
+
readonly sources?: readonly DomainSource[];
|
|
19
20
|
} | {
|
|
20
21
|
readonly engine: "sing-box";
|
|
21
22
|
readonly format: "source" | "binary";
|
|
@@ -28,7 +29,7 @@ export type NativeRuleSet = {
|
|
|
28
29
|
});
|
|
29
30
|
export type Match = NamedRuleSet | NativeRuleSet | {
|
|
30
31
|
readonly type: "domain" | "domainSuffix";
|
|
31
|
-
readonly
|
|
32
|
+
readonly sources?: readonly DomainSource[];
|
|
32
33
|
readonly value: string;
|
|
33
34
|
} | {
|
|
34
35
|
readonly type: "ipCidr";
|
|
@@ -97,9 +98,6 @@ export type ProxyBase = {
|
|
|
97
98
|
readonly via?: string;
|
|
98
99
|
readonly tcpFastOpen?: boolean;
|
|
99
100
|
readonly label?: string;
|
|
100
|
-
readonly region?: string;
|
|
101
|
-
readonly provider?: string;
|
|
102
|
-
readonly tags?: readonly string[];
|
|
103
101
|
};
|
|
104
102
|
export type ProxyTLS = {
|
|
105
103
|
readonly serverName: string;
|
|
@@ -443,7 +441,7 @@ declare const groupSchema: z.ZodObject<{
|
|
|
443
441
|
type SurgeGroup = z.infer<typeof groupSchema>;
|
|
444
442
|
type ConditionOptions = {
|
|
445
443
|
readonly noResolve?: boolean;
|
|
446
|
-
readonly
|
|
444
|
+
readonly sources?: readonly DomainSource[];
|
|
447
445
|
};
|
|
448
446
|
type SurgeCondition = ConditionOptions & ({
|
|
449
447
|
readonly type: "domain" | "domainSuffix" | "ipCidr" | "ipCidr6" | "sourceIp" | "processName" | "macAddress";
|
|
@@ -648,12 +646,6 @@ export declare function defineRoutes(input: {
|
|
|
648
646
|
readonly when: readonly ProfileCondition[];
|
|
649
647
|
readonly to: ProfileDestination;
|
|
650
648
|
}): RouteDefinition[];
|
|
651
|
-
export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
|
|
652
|
-
ids?: readonly string[];
|
|
653
|
-
regions?: readonly string[];
|
|
654
|
-
providers?: readonly string[];
|
|
655
|
-
tags?: readonly string[];
|
|
656
|
-
}): ProxyNode[];
|
|
657
649
|
//#endregion
|
|
658
650
|
//#region src/profile.d.ts
|
|
659
651
|
type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
|
|
@@ -663,12 +655,12 @@ type ProfileCondition = Exclude<Match | SurgeCondition, {
|
|
|
663
655
|
readonly type: "all" | "any";
|
|
664
656
|
readonly conditions: readonly ProfileCondition[];
|
|
665
657
|
readonly noResolve?: boolean;
|
|
666
|
-
readonly
|
|
658
|
+
readonly sources?: readonly DomainSource[];
|
|
667
659
|
} | {
|
|
668
660
|
readonly type: "not";
|
|
669
661
|
readonly condition: ProfileCondition;
|
|
670
662
|
readonly noResolve?: boolean;
|
|
671
|
-
readonly
|
|
663
|
+
readonly sources?: readonly DomainSource[];
|
|
672
664
|
};
|
|
673
665
|
type ProfileDestination = string | ProxyNode | ProxyGroupDefinition | SurgeTunnel | TailscaleEndpoint | {
|
|
674
666
|
readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
|
|
@@ -741,7 +733,7 @@ export declare function dnsRule(pattern: string, server: string): DnsRule;
|
|
|
741
733
|
export declare function dnsRule(patterns: readonly string[], server: string): DnsRule[];
|
|
742
734
|
export declare const ruleSet: (definition: Omit<NamedRuleSet, "type">) => NamedRuleSet;
|
|
743
735
|
type DomainOptions = {
|
|
744
|
-
readonly
|
|
736
|
+
readonly sources?: readonly DomainSource[];
|
|
745
737
|
};
|
|
746
738
|
type IpOptions = {
|
|
747
739
|
readonly noResolve?: boolean;
|
|
@@ -753,12 +745,12 @@ export declare const match: {
|
|
|
753
745
|
};
|
|
754
746
|
ruleSet: (set: NamedRuleSet) => NamedRuleSet;
|
|
755
747
|
domain: (value: string, opts?: DomainOptions) => {
|
|
756
|
-
|
|
748
|
+
sources?: readonly DomainSource[];
|
|
757
749
|
type: "domain";
|
|
758
750
|
value: string;
|
|
759
751
|
};
|
|
760
752
|
domainSuffix: (value: string, opts?: DomainOptions) => {
|
|
761
|
-
|
|
753
|
+
sources?: readonly DomainSource[];
|
|
762
754
|
type: "domainSuffix";
|
|
763
755
|
value: string;
|
|
764
756
|
};
|
|
@@ -832,12 +824,6 @@ export declare const defineConfig: <const T extends Config>(config: T & {
|
|
|
832
824
|
readonly program: string extends NonNullable<NoInfer<T>["cases"]>[number]["program"] ? string : keyof NoInfer<T>["programs"] & string;
|
|
833
825
|
})[];
|
|
834
826
|
}) => T;
|
|
835
|
-
/** Filtering is stable: catalogue order determines initial selector order. */
|
|
836
|
-
export declare function selectNodes(nodes: readonly ProxyNode[], query?: {
|
|
837
|
-
regions?: readonly string[];
|
|
838
|
-
providers?: readonly string[];
|
|
839
|
-
tags?: readonly string[];
|
|
840
|
-
}): string[];
|
|
841
827
|
/** A shared strategy declares an algorithm or explicitly selects native implementations. */
|
|
842
828
|
export declare const strategy: (definition: StrategyDefinition) => Strategy;
|
|
843
829
|
export declare const group: {
|
|
@@ -858,55 +844,55 @@ export declare const surge: {
|
|
|
858
844
|
match: {
|
|
859
845
|
domain: (value: string, options?: {
|
|
860
846
|
readonly noResolve?: boolean;
|
|
861
|
-
readonly
|
|
847
|
+
readonly sources?: readonly DomainSource[];
|
|
862
848
|
}) => SurgeCondition;
|
|
863
849
|
domainSuffix: (value: string, options?: {
|
|
864
850
|
readonly noResolve?: boolean;
|
|
865
|
-
readonly
|
|
851
|
+
readonly sources?: readonly DomainSource[];
|
|
866
852
|
}) => SurgeCondition;
|
|
867
853
|
ipCidr: (value: string, options?: {
|
|
868
854
|
readonly noResolve?: boolean;
|
|
869
|
-
readonly
|
|
855
|
+
readonly sources?: readonly DomainSource[];
|
|
870
856
|
}) => SurgeCondition;
|
|
871
857
|
ipCidr6: (value: string, options?: {
|
|
872
858
|
readonly noResolve?: boolean;
|
|
873
|
-
readonly
|
|
859
|
+
readonly sources?: readonly DomainSource[];
|
|
874
860
|
}) => SurgeCondition;
|
|
875
861
|
sourceIp: (value: string, options?: {
|
|
876
862
|
readonly noResolve?: boolean;
|
|
877
|
-
readonly
|
|
863
|
+
readonly sources?: readonly DomainSource[];
|
|
878
864
|
}) => SurgeCondition;
|
|
879
865
|
processName: (value: string, options?: {
|
|
880
866
|
readonly noResolve?: boolean;
|
|
881
|
-
readonly
|
|
867
|
+
readonly sources?: readonly DomainSource[];
|
|
882
868
|
}) => SurgeCondition;
|
|
883
869
|
macAddress: (value: string, options?: {
|
|
884
870
|
readonly noResolve?: boolean;
|
|
885
|
-
readonly
|
|
871
|
+
readonly sources?: readonly DomainSource[];
|
|
886
872
|
}) => SurgeCondition;
|
|
887
873
|
network: (value: "tcp" | "udp", options?: {
|
|
888
874
|
readonly noResolve?: boolean;
|
|
889
|
-
readonly
|
|
875
|
+
readonly sources?: readonly DomainSource[];
|
|
890
876
|
}) => SurgeCondition;
|
|
891
877
|
port: (from: number, to?: number, options?: {
|
|
892
878
|
readonly noResolve?: boolean;
|
|
893
|
-
readonly
|
|
879
|
+
readonly sources?: readonly DomainSource[];
|
|
894
880
|
}) => SurgeCondition;
|
|
895
881
|
sourcePort: (from: number, to?: number, options?: {
|
|
896
882
|
readonly noResolve?: boolean;
|
|
897
|
-
readonly
|
|
883
|
+
readonly sources?: readonly DomainSource[];
|
|
898
884
|
}) => SurgeCondition;
|
|
899
885
|
all: (conditions: readonly SurgeCondition[], options?: {
|
|
900
886
|
readonly noResolve?: boolean;
|
|
901
|
-
readonly
|
|
887
|
+
readonly sources?: readonly DomainSource[];
|
|
902
888
|
}) => SurgeCondition;
|
|
903
889
|
any: (conditions: readonly SurgeCondition[], options?: {
|
|
904
890
|
readonly noResolve?: boolean;
|
|
905
|
-
readonly
|
|
891
|
+
readonly sources?: readonly DomainSource[];
|
|
906
892
|
}) => SurgeCondition;
|
|
907
893
|
not: (value: SurgeCondition, options?: {
|
|
908
894
|
readonly noResolve?: boolean;
|
|
909
|
-
readonly
|
|
895
|
+
readonly sources?: readonly DomainSource[];
|
|
910
896
|
}) => SurgeCondition;
|
|
911
897
|
ruleSet: (options: Omit<Extract<SurgeCondition, {
|
|
912
898
|
type: "ruleSet";
|
|
@@ -930,7 +916,7 @@ export declare const surge: {
|
|
|
930
916
|
readonly format: "rule-set" | "domain-set";
|
|
931
917
|
readonly intervalSeconds?: number;
|
|
932
918
|
readonly noResolve?: boolean;
|
|
933
|
-
readonly
|
|
919
|
+
readonly sources?: readonly DomainSource[];
|
|
934
920
|
};
|
|
935
921
|
};
|
|
936
922
|
};
|
|
@@ -1145,7 +1131,7 @@ type BuildDefinition = {
|
|
|
1145
1131
|
readonly outDir?: string;
|
|
1146
1132
|
readonly profiles: Readonly<Record<string, Profile | ProfileDefinition>>;
|
|
1147
1133
|
readonly preflight?: () => readonly string[];
|
|
1148
|
-
readonly
|
|
1134
|
+
readonly secrets?: (token: Secret, context: BuildContext) => string | undefined;
|
|
1149
1135
|
};
|
|
1150
1136
|
type ProfileBuildResult = BuildResult & {
|
|
1151
1137
|
readonly warnings: Readonly<Record<string, number>>;
|
|
@@ -1161,6 +1147,15 @@ export declare function runBuild(input: BuildDefinition, output: string, options
|
|
|
1161
1147
|
//#endregion
|
|
1162
1148
|
//#region src/proxy-id.d.ts
|
|
1163
1149
|
/** Stable identity independent of engine and mutable metadata. */
|
|
1164
|
-
export declare function proxyId(
|
|
1150
|
+
export declare function proxyId(namespace: string, label: string): string;
|
|
1165
1151
|
//#endregion
|
|
1166
|
-
|
|
1152
|
+
//#region src/secret-inputs.d.ts
|
|
1153
|
+
type SecretsInput = {
|
|
1154
|
+
readonly values?: Readonly<Record<string, string>>;
|
|
1155
|
+
readonly env?: readonly string[];
|
|
1156
|
+
readonly validation?: Readonly<Record<string, string>>;
|
|
1157
|
+
};
|
|
1158
|
+
/** Capture declarations now; read only referenced, allowed environment names at render time. */
|
|
1159
|
+
export declare function secrets(input: SecretsInput, environment?: Readonly<Record<string, string | undefined>>): (token: Secret, context?: BuildContext) => string | undefined;
|
|
1160
|
+
//#endregion
|
|
1161
|
+
export type { Artifact, BuildContext, BuildDefinition, BuildResult, CaseResult, Compilation, DeepReadonly, Fragments, Profile, ProfileBuildResult, ProfileCheckResult, ProfileCompilation, ProfileCondition, ProfileDefinition, ProfileDestination, ProfileProxy, ProxyBuilder, ProxyGroupDefinition, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, RouteDefinition, SecretsInput, StrategyGroupCompilation, StrategyGroupInput, SurgeCondition, SurgeConfig, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };
|
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-DuHp9nQt.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
//#region src/proxy-fragments.ts
|
|
@@ -132,9 +132,63 @@ 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
|
|
141
|
+
/** Capture declarations now; read only referenced, allowed environment names at render time. */
|
|
142
|
+
function secrets(input, environment = process.env) {
|
|
143
|
+
let values;
|
|
144
|
+
let validation;
|
|
145
|
+
let env;
|
|
146
|
+
try {
|
|
147
|
+
inspectDefinition(input);
|
|
148
|
+
exactDefinition(input, [
|
|
149
|
+
"values",
|
|
150
|
+
"env",
|
|
151
|
+
"validation"
|
|
152
|
+
]);
|
|
153
|
+
if (!environment || typeof environment !== "object") throw new Error();
|
|
154
|
+
let total = 0;
|
|
155
|
+
const name = /^[A-Z][A-Z0-9_]{0,127}$/;
|
|
156
|
+
const entries = (record) => {
|
|
157
|
+
if (record === void 0) return [];
|
|
158
|
+
exactDefinition(record, Object.keys(record));
|
|
159
|
+
const fields = Object.entries(record);
|
|
160
|
+
if (fields.length > 2e3) throw new Error();
|
|
161
|
+
for (const [key, value] of fields) {
|
|
162
|
+
if (!name.test(key) || typeof value !== "string" || !value.length || value.length > 65536) throw new Error();
|
|
163
|
+
total += value.length;
|
|
164
|
+
if (total > 1048576) throw new Error();
|
|
165
|
+
}
|
|
166
|
+
return fields;
|
|
167
|
+
};
|
|
168
|
+
const fixed = entries(input.values);
|
|
169
|
+
const substitutes = entries(input.validation);
|
|
170
|
+
const allowed = input.env === void 0 ? [] : input.env;
|
|
171
|
+
if (!Array.isArray(allowed) || allowed.length > 2e3 || Array.from(allowed).some((key) => typeof key !== "string" || !name.test(key))) throw new Error();
|
|
172
|
+
values = new Map(fixed);
|
|
173
|
+
validation = new Map(substitutes);
|
|
174
|
+
env = new Set(allowed);
|
|
175
|
+
if (env.size !== allowed.length || [...env].some((key) => values.has(key)) || [...validation.keys()].some((key) => !values.has(key) && !env.has(key))) throw new Error();
|
|
176
|
+
} catch {
|
|
177
|
+
throw new ProfileDefinitionError("INVALID_SECRETS_DEFINITION");
|
|
178
|
+
}
|
|
179
|
+
return (token, context = { validation: false }) => {
|
|
180
|
+
if (context.validation && validation.has(token.name)) return validation.get(token.name);
|
|
181
|
+
if (values.has(token.name)) return values.get(token.name);
|
|
182
|
+
if (!env.has(token.name)) return void 0;
|
|
183
|
+
try {
|
|
184
|
+
const descriptor = Object.getOwnPropertyDescriptor(environment, token.name);
|
|
185
|
+
if (!descriptor) return void 0;
|
|
186
|
+
if (!("value" in descriptor) || descriptor.value !== void 0 && typeof descriptor.value !== "string") throw new Error();
|
|
187
|
+
return descriptor.value;
|
|
188
|
+
} catch {
|
|
189
|
+
throw new RenderError("SECRET_RESOLUTION_FAILED");
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
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, sequence, singbox, slot, strategy, surge, targetCatalog, use };
|
|
@@ -1,10 +1,32 @@
|
|
|
1
|
-
import { isIP } from "node:net";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { isIP } from "node:net";
|
|
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/domain-sources.ts
|
|
9
|
+
const order = [
|
|
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. */
|
|
22
|
+
function domainIdentityFields(value) {
|
|
23
|
+
return Object.entries(value).map(([key, field]) => {
|
|
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));
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
8
30
|
//#region src/dns.ts
|
|
9
31
|
const domain$2 = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
10
32
|
function dohUrl(value) {
|
|
@@ -190,21 +212,6 @@ function defineRoutes(input) {
|
|
|
190
212
|
to: input.to
|
|
191
213
|
}));
|
|
192
214
|
}
|
|
193
|
-
function selectProxies(nodes, query = {}) {
|
|
194
|
-
inspectDefinition({
|
|
195
|
-
nodes,
|
|
196
|
-
query
|
|
197
|
-
});
|
|
198
|
-
exactDefinition(query, [
|
|
199
|
-
"ids",
|
|
200
|
-
"regions",
|
|
201
|
-
"providers",
|
|
202
|
-
"tags"
|
|
203
|
-
]);
|
|
204
|
-
if (!Array.isArray(nodes) || nodes.some((node) => !node || typeof node !== "object")) fail$1("DEFINITION_NOT_DATA");
|
|
205
|
-
for (const values of Object.values(query)) if (values !== void 0 && !Array.isArray(values)) fail$1("DEFINITION_NOT_DATA");
|
|
206
|
-
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))));
|
|
207
|
-
}
|
|
208
215
|
function lowerSurgeProfile(input) {
|
|
209
216
|
inspectDefinition(input);
|
|
210
217
|
exactDefinition(input, [
|
|
@@ -430,7 +437,7 @@ const nativeRuleSetSchema = z.discriminatedUnion("engine", [
|
|
|
430
437
|
format: z.enum(["rule-set", "domain-set"]),
|
|
431
438
|
intervalSeconds: updateInterval.optional(),
|
|
432
439
|
noResolve: z.boolean().optional(),
|
|
433
|
-
|
|
440
|
+
sources: domainSourcesSchema.optional()
|
|
434
441
|
}),
|
|
435
442
|
z.strictObject({
|
|
436
443
|
...remoteBase,
|
|
@@ -460,12 +467,12 @@ const matchSchema = z.lazy(() => z.discriminatedUnion("type", [
|
|
|
460
467
|
z.strictObject({
|
|
461
468
|
type: z.literal("domain"),
|
|
462
469
|
value: domain$1,
|
|
463
|
-
|
|
470
|
+
sources: domainSourcesSchema.optional()
|
|
464
471
|
}),
|
|
465
472
|
z.strictObject({
|
|
466
473
|
type: z.literal("domainSuffix"),
|
|
467
474
|
value: domain$1,
|
|
468
|
-
|
|
475
|
+
sources: domainSourcesSchema.optional()
|
|
469
476
|
}),
|
|
470
477
|
z.strictObject({
|
|
471
478
|
type: z.literal("ipCidr"),
|
|
@@ -543,10 +550,7 @@ const nodeBase = {
|
|
|
543
550
|
port: port$1,
|
|
544
551
|
via: idSchema.optional(),
|
|
545
552
|
tcpFastOpen: z.boolean().optional(),
|
|
546
|
-
label: z.string().min(1).max(256).optional()
|
|
547
|
-
region: z.string().regex(/^[A-Z]{2}$/).optional(),
|
|
548
|
-
provider: idSchema.optional(),
|
|
549
|
-
tags: z.array(idSchema).refine(unique).optional()
|
|
553
|
+
label: z.string().min(1).max(256).optional()
|
|
550
554
|
};
|
|
551
555
|
const tlsSchema = z.strictObject({
|
|
552
556
|
serverName: domain$1,
|
|
@@ -768,8 +772,9 @@ function assertData(value) {
|
|
|
768
772
|
if (typeof v !== "object" || ancestors.has(v)) throw new Error("INPUT_GRAPH");
|
|
769
773
|
if (!Array.isArray(v) && Object.getPrototypeOf(v) !== Object.prototype && Object.getPrototypeOf(v) !== null) throw new Error("INPUT_OBJECT");
|
|
770
774
|
ancestors.add(v);
|
|
771
|
-
for (const
|
|
772
|
-
|
|
775
|
+
for (const key of Reflect.ownKeys(v)) {
|
|
776
|
+
const descriptor = Object.getOwnPropertyDescriptor(v, key);
|
|
777
|
+
if (typeof key !== "string" || !("value" in descriptor) || !descriptor.enumerable && !(Array.isArray(v) && key === "length")) throw new Error("INPUT_OBJECT");
|
|
773
778
|
visit(descriptor.value, depth + 1);
|
|
774
779
|
}
|
|
775
780
|
ancestors.delete(v);
|
|
@@ -787,7 +792,7 @@ function deepFreeze(value) {
|
|
|
787
792
|
//#region src/rulesets.ts
|
|
788
793
|
function canonical(value) {
|
|
789
794
|
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
790
|
-
if (value && typeof value === "object") return `{${
|
|
795
|
+
if (value && typeof value === "object") return `{${domainIdentityFields(value).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
791
796
|
return JSON.stringify(value);
|
|
792
797
|
}
|
|
793
798
|
function validateRuleSets(entries, engine, diagnostics, path) {
|
|
@@ -1008,11 +1013,7 @@ function evaluate(condition, request) {
|
|
|
1008
1013
|
switch (condition.type) {
|
|
1009
1014
|
case "domain":
|
|
1010
1015
|
case "domainSuffix": {
|
|
1011
|
-
const domains = condition.
|
|
1012
|
-
request.domain,
|
|
1013
|
-
request.tlsSni,
|
|
1014
|
-
request.httpHost
|
|
1015
|
-
] : [request.domain];
|
|
1016
|
+
const domains = (condition.sources ?? ["destination"]).map((source) => source === "destination" ? request.domain : request[source]);
|
|
1016
1017
|
present = domains.some((value) => value !== void 0);
|
|
1017
1018
|
matched = domains.some((value) => value !== void 0 && (value === condition.value || condition.type === "domainSuffix" && value.endsWith(`.${condition.value}`)));
|
|
1018
1019
|
break;
|
|
@@ -1811,7 +1812,7 @@ function compile(input) {
|
|
|
1811
1812
|
for (const rule of rules) if (logicalDepth(rule.when) > 10) error("LOGICAL_DEPTH", rule.id, "Surge 逻辑条件最多嵌套 10 层", target.id);
|
|
1812
1813
|
}
|
|
1813
1814
|
const checkOptions = (condition) => {
|
|
1814
|
-
if ("
|
|
1815
|
+
if ("sources" in condition && !supportsDomainSources(condition.sources, target.engine) || condition.type === "ipCidr" && condition.noResolve !== void 0 && target.engine === "sing-box") error("MATCH_OPTION_UNSUPPORTED", path, "目标无法等价实现显式匹配选项", target.id);
|
|
1815
1816
|
if (condition.type === "all" || condition.type === "any") condition.conditions.forEach(checkOptions);
|
|
1816
1817
|
else if (condition.type === "not") checkOptions(condition.condition);
|
|
1817
1818
|
else if (condition.type === "ruleSet") checkOptions(condition.when);
|
|
@@ -2064,7 +2065,7 @@ const groupSchema = z.strictObject({
|
|
|
2064
2065
|
});
|
|
2065
2066
|
const options$1 = {
|
|
2066
2067
|
noResolve: z.boolean().optional(),
|
|
2067
|
-
|
|
2068
|
+
sources: domainSourcesSchema.optional()
|
|
2068
2069
|
};
|
|
2069
2070
|
const atom = (type, value) => z.strictObject({
|
|
2070
2071
|
type: z.literal(type),
|
|
@@ -2239,11 +2240,12 @@ function compileSurgeProfile(input) {
|
|
|
2239
2240
|
"ipCidr6",
|
|
2240
2241
|
"ruleSet"
|
|
2241
2242
|
].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
|
|
2242
|
-
if (c.
|
|
2243
|
+
if (c.sources !== void 0 && ![
|
|
2243
2244
|
"domain",
|
|
2244
2245
|
"domainSuffix",
|
|
2245
2246
|
"ruleSet"
|
|
2246
2247
|
].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
|
|
2248
|
+
if (c.sources !== void 0 && !supportsDomainSources(c.sources, "surge")) error("MATCH_OPTION_UNSUPPORTED");
|
|
2247
2249
|
if (p.target.platform === "ios" && ["processName", "macAddress"].includes(c.type)) error("PLATFORM_RULE_UNSUPPORTED");
|
|
2248
2250
|
if (c.type === "all" || c.type === "any") for (const child of c.conditions) checkCondition(child, depth + 1);
|
|
2249
2251
|
if (c.type === "not") checkCondition(c.condition, depth + 1);
|
|
@@ -2282,7 +2284,7 @@ function compileSurgeProfile(input) {
|
|
|
2282
2284
|
function conditionOptions(c) {
|
|
2283
2285
|
return [
|
|
2284
2286
|
...c.noResolve ? ["no-resolve"] : [],
|
|
2285
|
-
...c.
|
|
2287
|
+
...extendedDomainSources(c.sources) ? ["extended-matching"] : [],
|
|
2286
2288
|
...c.type === "ruleSet" && c.intervalSeconds !== void 0 ? [`update-interval=${c.intervalSeconds}`] : []
|
|
2287
2289
|
];
|
|
2288
2290
|
}
|
|
@@ -2521,7 +2523,7 @@ function surgeCondition$1(condition, depth = 0) {
|
|
|
2521
2523
|
url: value.url,
|
|
2522
2524
|
...value.intervalSeconds !== void 0 ? { intervalSeconds: value.intervalSeconds } : {},
|
|
2523
2525
|
...value.noResolve !== void 0 ? { noResolve: value.noResolve } : {},
|
|
2524
|
-
...value.
|
|
2526
|
+
...value.sources !== void 0 ? { sources: value.sources } : {}
|
|
2525
2527
|
};
|
|
2526
2528
|
}
|
|
2527
2529
|
if (condition.type === "all" || condition.type === "any") {
|
|
@@ -2720,8 +2722,9 @@ const ruleSet = (definition) => ({
|
|
|
2720
2722
|
function options(value, keys) {
|
|
2721
2723
|
inspectDefinition(value);
|
|
2722
2724
|
exactDefinition(value, keys);
|
|
2723
|
-
if (
|
|
2724
|
-
|
|
2725
|
+
if ("sources" in value && value.sources !== void 0 && !domainSourcesSchema.safeParse(value.sources).success) throw new ProfileDefinitionError("INVALID_DOMAIN_SOURCES");
|
|
2726
|
+
if (Object.entries(value).some(([key, v]) => key !== "sources" && v !== void 0 && typeof v !== "boolean")) throw new ProfileDefinitionError("INVALID_MATCH_OPTIONS");
|
|
2727
|
+
return snapshotDefinition(value);
|
|
2725
2728
|
}
|
|
2726
2729
|
const match = {
|
|
2727
2730
|
processName: (value) => {
|
|
@@ -2735,12 +2738,12 @@ const match = {
|
|
|
2735
2738
|
domain: (value, opts = {}) => ({
|
|
2736
2739
|
type: "domain",
|
|
2737
2740
|
value,
|
|
2738
|
-
...options(opts, ["
|
|
2741
|
+
...options(opts, ["sources"])
|
|
2739
2742
|
}),
|
|
2740
2743
|
domainSuffix: (value, opts = {}) => ({
|
|
2741
2744
|
type: "domainSuffix",
|
|
2742
2745
|
value,
|
|
2743
|
-
...options(opts, ["
|
|
2746
|
+
...options(opts, ["sources"])
|
|
2744
2747
|
}),
|
|
2745
2748
|
ipCidr: (value, opts = {}) => ({
|
|
2746
2749
|
type: "ipCidr",
|
|
@@ -2788,7 +2791,7 @@ function nativeConstructor(engine) {
|
|
|
2788
2791
|
"format",
|
|
2789
2792
|
"intervalSeconds",
|
|
2790
2793
|
"noResolve",
|
|
2791
|
-
"
|
|
2794
|
+
"sources",
|
|
2792
2795
|
"behavior",
|
|
2793
2796
|
"to"
|
|
2794
2797
|
]);
|
|
@@ -2799,7 +2802,7 @@ function nativeConstructor(engine) {
|
|
|
2799
2802
|
"url",
|
|
2800
2803
|
"format",
|
|
2801
2804
|
"intervalSeconds",
|
|
2802
|
-
...engine === "surge" ? ["noResolve", "
|
|
2805
|
+
...engine === "surge" ? ["noResolve", "sources"] : engine === "mihomo" ? ["behavior"] : []
|
|
2803
2806
|
]);
|
|
2804
2807
|
const parsed = nativeRuleSetSchema.safeParse({
|
|
2805
2808
|
...engine === "surge" ? { format: "rule-set" } : {},
|
|
@@ -2810,7 +2813,7 @@ function nativeConstructor(engine) {
|
|
|
2810
2813
|
});
|
|
2811
2814
|
if (!parsed.success) throw new ProfileDefinitionError("INVALID_NATIVE_RULESET");
|
|
2812
2815
|
const { id: _id, type: _type, ...fields } = parsed.data;
|
|
2813
|
-
const id = resource.id ?? `ruleset-${createHash("sha256").update(JSON.stringify(
|
|
2816
|
+
const id = resource.id ?? `ruleset-${createHash("sha256").update(JSON.stringify(domainIdentityFields(fields))).digest("hex").slice(0, 16)}`;
|
|
2814
2817
|
const when = snapshotDefinition({
|
|
2815
2818
|
...parsed.data,
|
|
2816
2819
|
id
|
|
@@ -2869,10 +2872,6 @@ const use = (definition, options) => ({
|
|
|
2869
2872
|
});
|
|
2870
2873
|
const sequence = (...parts) => parts.flatMap((part) => Array.isArray(part) ? part : [part]);
|
|
2871
2874
|
const defineConfig = (config) => config;
|
|
2872
|
-
/** Filtering is stable: catalogue order determines initial selector order. */
|
|
2873
|
-
function selectNodes(nodes, query = {}) {
|
|
2874
|
-
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);
|
|
2875
|
-
}
|
|
2876
2875
|
/** A shared strategy declares an algorithm or explicitly selects native implementations. */
|
|
2877
2876
|
const strategy = (definition) => ({
|
|
2878
2877
|
type: "strategy",
|
|
@@ -3103,7 +3102,7 @@ function surgeOptions(condition) {
|
|
|
3103
3102
|
return [
|
|
3104
3103
|
...condition.type === "ipCidr" && condition.noResolve !== false ? ["no-resolve"] : [],
|
|
3105
3104
|
...condition.type === "nativeRuleSet" && condition.engine === "surge" && condition.noResolve ? ["no-resolve"] : [],
|
|
3106
|
-
..."
|
|
3105
|
+
..."sources" in condition && extendedDomainSources(condition.sources) ? ["extended-matching"] : []
|
|
3107
3106
|
].map((value) => `,${value}`).join("");
|
|
3108
3107
|
}
|
|
3109
3108
|
function surgeCondition(condition) {
|
|
@@ -3456,7 +3455,7 @@ function checkBuild(input) {
|
|
|
3456
3455
|
}))
|
|
3457
3456
|
};
|
|
3458
3457
|
}
|
|
3459
|
-
async function publish(profiles, output,
|
|
3458
|
+
async function publish(profiles, output, readSecret) {
|
|
3460
3459
|
try {
|
|
3461
3460
|
const checked = compileBatch(profiles, output);
|
|
3462
3461
|
if (!checked.ok) return {
|
|
@@ -3465,7 +3464,7 @@ async function publish(profiles, output, resolver) {
|
|
|
3465
3464
|
code: checked.code
|
|
3466
3465
|
};
|
|
3467
3466
|
const { entries, compiled } = checked;
|
|
3468
|
-
const read = secretReader(
|
|
3467
|
+
const read = secretReader(readSecret);
|
|
3469
3468
|
const files = /* @__PURE__ */ new Map();
|
|
3470
3469
|
for (const [index, profile] of compiled.entries()) {
|
|
3471
3470
|
if (profile.engine === "invalid") throw new Error();
|
|
@@ -3507,17 +3506,17 @@ function defineBuild(input) {
|
|
|
3507
3506
|
record(input, [
|
|
3508
3507
|
"profiles",
|
|
3509
3508
|
"preflight",
|
|
3510
|
-
"
|
|
3509
|
+
"secrets",
|
|
3511
3510
|
"outDir"
|
|
3512
3511
|
]);
|
|
3513
3512
|
if (input.outDir !== void 0 && (typeof input.outDir !== "string" || !input.outDir.trim() || input.outDir.trim() !== input.outDir || input.outDir.includes("\0"))) throw new Error();
|
|
3514
3513
|
record(input.profiles);
|
|
3515
|
-
for (const callback of [input.preflight, input.
|
|
3514
|
+
for (const callback of [input.preflight, input.secrets]) if (callback !== void 0 && typeof callback !== "function") throw new Error();
|
|
3516
3515
|
return Object.freeze({
|
|
3517
3516
|
...input.outDir === void 0 ? {} : { outDir: input.outDir },
|
|
3518
3517
|
profiles: snapshotProfile(input.profiles),
|
|
3519
3518
|
...input.preflight === void 0 ? {} : { preflight: input.preflight },
|
|
3520
|
-
...input.
|
|
3519
|
+
...input.secrets === void 0 ? {} : { secrets: input.secrets }
|
|
3521
3520
|
});
|
|
3522
3521
|
} catch {
|
|
3523
3522
|
throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
|
|
@@ -3554,7 +3553,7 @@ async function runBuild(input, output, options = {}) {
|
|
|
3554
3553
|
const failure = (code) => profileBuildFailure(code, validation, profileCount);
|
|
3555
3554
|
if (typeof output !== "string" || !output.trim()) return failure("INVALID_OUTPUT_DIRECTORY");
|
|
3556
3555
|
output = resolve(root, output);
|
|
3557
|
-
if (validation && !definition.
|
|
3556
|
+
if (validation && !definition.secrets) return failure("VALIDATION_SECRETS_REQUIRED");
|
|
3558
3557
|
let codes;
|
|
3559
3558
|
try {
|
|
3560
3559
|
codes = definition.preflight ? definition.preflight() : [];
|
|
@@ -3570,13 +3569,13 @@ async function runBuild(input, output, options = {}) {
|
|
|
3570
3569
|
const warnings = {};
|
|
3571
3570
|
for (const code of codes) warnings[code] = (warnings[code] ?? 0) + 1;
|
|
3572
3571
|
const context = Object.freeze({ validation });
|
|
3573
|
-
const
|
|
3572
|
+
const readSecret = definition.secrets;
|
|
3574
3573
|
return {
|
|
3575
|
-
...await publish(definition.profiles, output,
|
|
3574
|
+
...await publish(definition.profiles, output, readSecret ? (token) => readSecret(token, context) : (token) => process.env[token.name]),
|
|
3576
3575
|
warnings,
|
|
3577
3576
|
validation,
|
|
3578
3577
|
profileCount
|
|
3579
3578
|
};
|
|
3580
3579
|
}
|
|
3581
3580
|
//#endregion
|
|
3582
|
-
export {
|
|
3581
|
+
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