proxylang 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-TmM3uIDQ.js → build-H0uxqVRQ.js} +61 -12
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +13 -5
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -200,7 +200,7 @@ function unsafeTunResolvers(model) {
|
|
|
200
200
|
const networks = model.tun.address.map((value) => ipaddr.parseCIDR(value));
|
|
201
201
|
return [
|
|
202
202
|
...model.listener ? [model.listener.resolver] : [],
|
|
203
|
-
...(model.dns ?? []).
|
|
203
|
+
...(model.dns ?? []).flatMap(({ server }) => typeof server === "string" ? [isIP(server) ? server : new URL(server).hostname.replace(/^\[|\]$/g, "")] : []),
|
|
204
204
|
...(model.endpoints ?? []).map((endpoint) => endpoint.bootstrapResolver)
|
|
205
205
|
].filter((value) => {
|
|
206
206
|
if (!isIP(value)) return false;
|
|
@@ -422,7 +422,10 @@ const endpointSchema = z.strictObject({
|
|
|
422
422
|
type: z.literal("sing-box-tailscale"),
|
|
423
423
|
id: idSchema,
|
|
424
424
|
hostname: domain$3.refine((x) => !x.includes(".")),
|
|
425
|
-
stateDirectory: z.string().max(4096).refine((
|
|
425
|
+
stateDirectory: z.string().max(4096).refine((value) => {
|
|
426
|
+
if (/[\p{C}$\\]/u.test(value) || /^(?:~|[a-z]:)/i.test(value)) return false;
|
|
427
|
+
return (value.startsWith("/") ? value.slice(1) : value).split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
428
|
+
}),
|
|
426
429
|
acceptRoutes: z.boolean(),
|
|
427
430
|
bootstrapResolver: ip$2,
|
|
428
431
|
authKey: secretSchema.optional(),
|
|
@@ -770,7 +773,7 @@ function dohUrl(value) {
|
|
|
770
773
|
if (!/^https:\/\/[^/]+\//.test(value)) url.pathname = "/dns-query";
|
|
771
774
|
return url;
|
|
772
775
|
}
|
|
773
|
-
const
|
|
776
|
+
const address = z.string().max(2048).refine((value) => {
|
|
774
777
|
if (isIP(value) && !value.includes("%")) return true;
|
|
775
778
|
if (!value.startsWith("https://") || /[\s\p{C},()\\"'?#]/u.test(value)) return false;
|
|
776
779
|
try {
|
|
@@ -782,15 +785,19 @@ const server = z.string().max(2048).refine((value) => {
|
|
|
782
785
|
return false;
|
|
783
786
|
}
|
|
784
787
|
});
|
|
788
|
+
const tailscale = z.strictObject({
|
|
789
|
+
endpoint: z.custom((value) => kindOf(value) === "endpoint"),
|
|
790
|
+
acceptDefaultResolvers: z.boolean().optional()
|
|
791
|
+
});
|
|
785
792
|
const dnsRulesSchema = z.array(z.strictObject({
|
|
786
793
|
pattern: z.string().min(1).max(253).refine((value) => domain$1.test(value.startsWith("*.") ? value.slice(2) : value)),
|
|
787
|
-
server
|
|
794
|
+
server: z.union([address, tailscale])
|
|
788
795
|
})).max(2e3).superRefine((rules, ctx) => {
|
|
789
|
-
if (rules.length > 2e3 || rules.some((
|
|
796
|
+
if (rules.length > 2e3 || rules.some(({ pattern, server }) => pattern.length > 253 || typeof server === "string" && server.length > 2048)) return;
|
|
790
797
|
for (let i = 0; i < rules.length; i++) for (let j = 0; j < i; j++) {
|
|
791
798
|
const a = rules[i], b = rules[j];
|
|
792
799
|
const x = a.pattern.toLowerCase(), y = b.pattern.toLowerCase();
|
|
793
|
-
if (x === y || overlap(x, y) && a.server
|
|
800
|
+
if (x === y || overlap(x, y) && !sameServer(a.server, b.server)) {
|
|
794
801
|
ctx.addIssue({
|
|
795
802
|
code: "custom",
|
|
796
803
|
message: "DNS_RULE_CONFLICT"
|
|
@@ -799,6 +806,10 @@ const dnsRulesSchema = z.array(z.strictObject({
|
|
|
799
806
|
}
|
|
800
807
|
}
|
|
801
808
|
});
|
|
809
|
+
function sameServer(a, b) {
|
|
810
|
+
if (typeof a === "string" || typeof b === "string") return a === b;
|
|
811
|
+
return a.endpoint === b.endpoint && (a.acceptDefaultResolvers ?? false) === (b.acceptDefaultResolvers ?? false);
|
|
812
|
+
}
|
|
802
813
|
function overlap(a, b) {
|
|
803
814
|
const wildA = a.startsWith("*."), wildB = b.startsWith("*.");
|
|
804
815
|
if (wildA && wildB) return a.slice(1).endsWith(b.slice(1)) || b.slice(1).endsWith(a.slice(1));
|
|
@@ -1435,13 +1446,24 @@ function inspectProfile(profile, key, secrets, checkSecrets = true) {
|
|
|
1435
1446
|
if (kindOf(exit) !== "builtin" && !listed.has(exit)) error("UNLISTED_EXIT", path, owner);
|
|
1436
1447
|
if (profile.target.engine !== "surge" && "builtin" in exit && !["DIRECT", "REJECT"].includes(exit.builtin)) error("EXIT_UNSUPPORTED", path, owner);
|
|
1437
1448
|
};
|
|
1449
|
+
const tailscaleDnsDefaults = /* @__PURE__ */ new Map();
|
|
1450
|
+
profile.dns?.forEach((rule, i) => {
|
|
1451
|
+
if (typeof rule.server === "string") return;
|
|
1452
|
+
const { endpoint, acceptDefaultResolvers = false } = rule.server;
|
|
1453
|
+
const path = `dns[${i}].server`;
|
|
1454
|
+
reference(endpoint, `${path}.endpoint`, rule);
|
|
1455
|
+
if (profile.target.engine !== "sing-box" || profile.singBox?.mode === "fragment") error("DNS_UNSUPPORTED", path, rule, "Tailscale DNS requires sing-box standalone");
|
|
1456
|
+
const previous = tailscaleDnsDefaults.get(endpoint);
|
|
1457
|
+
if (previous === void 0) tailscaleDnsDefaults.set(endpoint, acceptDefaultResolvers);
|
|
1458
|
+
else if (previous !== acceptDefaultResolvers) error("TAILSCALE_DNS_OPTIONS_CONFLICT", `${path}.acceptDefaultResolvers`, rule);
|
|
1459
|
+
});
|
|
1438
1460
|
const edges = /* @__PURE__ */ new Map();
|
|
1439
1461
|
for (const resource of resources) {
|
|
1440
1462
|
const path = resource.type === "proxy-group" ? `groups.${resource.id}` : `proxies.${resource.id}`;
|
|
1441
1463
|
if (resource.type === "proxy-group") {
|
|
1442
1464
|
resource.members.forEach((m, i) => {
|
|
1443
1465
|
reference(m, `${path}.members[${i}]`, resource);
|
|
1444
|
-
if (kindOf(m) === "endpoint") error("MEMBER_TYPE_UNSUPPORTED", `${path}.members[${i}]`, resource);
|
|
1466
|
+
if (kindOf(m) === "endpoint" && (profile.target.engine !== "sing-box" || profile.singBox?.mode === "fragment" || resource.algorithm.type !== "select")) error("MEMBER_TYPE_UNSUPPORTED", `${path}.members[${i}]`, resource);
|
|
1445
1467
|
});
|
|
1446
1468
|
edges.set(resource, resource.members.filter((m) => kindOf(m) !== "builtin"));
|
|
1447
1469
|
if (resource.algorithm.type === "auto" && profile.target.engine !== "stash") selections.push({
|
|
@@ -1753,7 +1775,13 @@ function normalizeProfile(profile) {
|
|
|
1753
1775
|
};
|
|
1754
1776
|
}),
|
|
1755
1777
|
fallback: destination(profile.fallback),
|
|
1756
|
-
...profile.dns === void 0 ? {} : { dns: profile.dns }
|
|
1778
|
+
...profile.dns === void 0 ? {} : { dns: profile.dns.map(({ pattern, server }) => ({
|
|
1779
|
+
pattern,
|
|
1780
|
+
server: typeof server === "string" ? server : {
|
|
1781
|
+
...server,
|
|
1782
|
+
endpoint: server.endpoint.id
|
|
1783
|
+
}
|
|
1784
|
+
})) },
|
|
1757
1785
|
...extension
|
|
1758
1786
|
}));
|
|
1759
1787
|
}
|
|
@@ -2269,10 +2297,14 @@ function normalizeSurgeProfile(p) {
|
|
|
2269
2297
|
const tunnels = p.proxies.filter((x) => ["tailscale", "wireguard"].includes(x.type));
|
|
2270
2298
|
if (p.proxies.some((x) => x.type === "sing-box-tailscale")) throw new ProfileDefinitionError("PROFILE_ENDPOINT_UNSUPPORTED");
|
|
2271
2299
|
const groups = p.groups;
|
|
2300
|
+
const dns = p.dns?.flatMap(({ pattern, server }) => typeof server === "string" ? [{
|
|
2301
|
+
pattern,
|
|
2302
|
+
server
|
|
2303
|
+
}] : []);
|
|
2272
2304
|
return lowerSurgeProfile({
|
|
2273
2305
|
target: p.target,
|
|
2274
2306
|
...p.surge,
|
|
2275
|
-
...
|
|
2307
|
+
...dns?.length ? { hosts: [...dns, ...p.surge?.hosts ?? []] } : {},
|
|
2276
2308
|
nodes: nodes.map((n) => {
|
|
2277
2309
|
const { name: _name, ...rest } = n;
|
|
2278
2310
|
return {
|
|
@@ -2566,9 +2598,25 @@ function singbox(plan, secret) {
|
|
|
2566
2598
|
server: "127.0.0.1",
|
|
2567
2599
|
server_port: model.listener.port
|
|
2568
2600
|
});
|
|
2601
|
+
const tailscaleDnsTags = /* @__PURE__ */ new Map();
|
|
2569
2602
|
dns.rules = model.dns.map((rule, index) => {
|
|
2570
2603
|
const tag = `pl-domain-dns-${index}`;
|
|
2571
|
-
|
|
2604
|
+
const condition = dnsCondition(rule);
|
|
2605
|
+
if (typeof rule.server !== "string") {
|
|
2606
|
+
const { endpoint, acceptDefaultResolvers } = rule.server;
|
|
2607
|
+
const existing = tailscaleDnsTags.get(endpoint);
|
|
2608
|
+
if (existing !== void 0) return {
|
|
2609
|
+
...condition,
|
|
2610
|
+
server: existing
|
|
2611
|
+
};
|
|
2612
|
+
tailscaleDnsTags.set(endpoint, tag);
|
|
2613
|
+
dns.servers.push({
|
|
2614
|
+
type: "tailscale",
|
|
2615
|
+
tag,
|
|
2616
|
+
endpoint: name(endpoint),
|
|
2617
|
+
...acceptDefaultResolvers === void 0 ? {} : { accept_default_resolvers: acceptDefaultResolvers }
|
|
2618
|
+
});
|
|
2619
|
+
} else if (isIP(rule.server)) dns.servers.push({
|
|
2572
2620
|
type: "udp",
|
|
2573
2621
|
tag,
|
|
2574
2622
|
server: rule.server,
|
|
@@ -2590,7 +2638,7 @@ function singbox(plan, secret) {
|
|
|
2590
2638
|
});
|
|
2591
2639
|
}
|
|
2592
2640
|
return {
|
|
2593
|
-
...
|
|
2641
|
+
...condition,
|
|
2594
2642
|
server: tag
|
|
2595
2643
|
};
|
|
2596
2644
|
});
|
|
@@ -3046,6 +3094,7 @@ const targetCatalog = deepFreeze([
|
|
|
3046
3094
|
//#endregion
|
|
3047
3095
|
//#region src/model/paths.ts
|
|
3048
3096
|
function pathsOverlap(a, b) {
|
|
3097
|
+
if (a.startsWith("/") !== b.startsWith("/")) return false;
|
|
3049
3098
|
return a === b || a.startsWith(b.endsWith("/") ? b : `${b}/`) || b.startsWith(a.endsWith("/") ? a : `${a}/`);
|
|
3050
3099
|
}
|
|
3051
3100
|
//#endregion
|
|
@@ -3073,7 +3122,7 @@ function checkTarget(model, checks) {
|
|
|
3073
3122
|
for (const [id, refs] of edges) for (const [index, ref] of refs.entries()) {
|
|
3074
3123
|
const path = registry.get(id)?.type === "select" || registry.get(id)?.type === "urltest" ? `groups.${id}.members[${index}]` : `proxies.${id}.via`;
|
|
3075
3124
|
if (!registry.has(ref) && !["DIRECT", "REJECT"].includes(ref)) error("MISSING_REFERENCE", path);
|
|
3076
|
-
if (registry.get(ref)?.type === "sing-box-tailscale") error("ENDPOINT_REFERENCE_UNSUPPORTED", path);
|
|
3125
|
+
if (registry.get(ref)?.type === "sing-box-tailscale" && (t.engine !== "sing-box" || t.mode !== "standalone" || registry.get(id)?.type !== "select")) error("ENDPOINT_REFERENCE_UNSUPPORTED", path);
|
|
3077
3126
|
}
|
|
3078
3127
|
const state = /* @__PURE__ */ new Map(), tcp = /* @__PURE__ */ new Map();
|
|
3079
3128
|
const visit = (id) => {
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as definitionDiagnostic, i as targetCatalog } from "./build-
|
|
2
|
+
import { C as definitionDiagnostic, i as targetCatalog } from "./build-H0uxqVRQ.js";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { lstat, open, stat } from "node:fs/promises";
|
package/dist/index.d.ts
CHANGED
|
@@ -165,9 +165,13 @@ type GroupAlgorithm = {
|
|
|
165
165
|
readonly intervalSeconds?: number;
|
|
166
166
|
readonly toleranceMs?: number;
|
|
167
167
|
};
|
|
168
|
-
type DnsRule = {
|
|
168
|
+
type DnsRule<Server = string> = {
|
|
169
169
|
readonly pattern: string;
|
|
170
|
-
readonly server:
|
|
170
|
+
readonly server: Server;
|
|
171
|
+
};
|
|
172
|
+
type TailscaleDnsServer<Endpoint> = {
|
|
173
|
+
readonly endpoint: Endpoint;
|
|
174
|
+
readonly acceptDefaultResolvers?: boolean;
|
|
171
175
|
};
|
|
172
176
|
type Tun = {
|
|
173
177
|
readonly address: readonly string[];
|
|
@@ -480,6 +484,8 @@ type SurgeTunnel = PublicSecrets<SurgeTunnel$1> & {
|
|
|
480
484
|
type SingBoxEndpoint = PublicSecrets<TailscaleEndpoint> & {
|
|
481
485
|
readonly name?: string;
|
|
482
486
|
} & SDK<"endpoint">;
|
|
487
|
+
type TailscaleDnsOptions = TailscaleDnsServer<SingBoxEndpoint>;
|
|
488
|
+
type ProfileDnsRule = DnsRule<string | TailscaleDnsOptions>;
|
|
483
489
|
type Builtin = {
|
|
484
490
|
readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
|
|
485
491
|
} & SDK<"builtin">;
|
|
@@ -549,7 +555,7 @@ type SingBoxOptions = {
|
|
|
549
555
|
};
|
|
550
556
|
type Common = {
|
|
551
557
|
readonly cases?: Fragments<RouteCase>;
|
|
552
|
-
readonly dns?: Fragments<
|
|
558
|
+
readonly dns?: Fragments<ProfileDnsRule>;
|
|
553
559
|
readonly proxies: Fragments<ProfileProxy>;
|
|
554
560
|
readonly routes: Fragments<Route>;
|
|
555
561
|
readonly fallback: Exit;
|
|
@@ -603,7 +609,7 @@ type FlattenedProfile<D extends ProfileDefinition> = D extends ProfileDefinition
|
|
|
603
609
|
};
|
|
604
610
|
} ? ProxyGroup : ProxyGroup<Portable>)[];
|
|
605
611
|
readonly routes: readonly Route[];
|
|
606
|
-
readonly dns: readonly
|
|
612
|
+
readonly dns: readonly ProfileDnsRule[];
|
|
607
613
|
readonly cases: readonly RouteCase[];
|
|
608
614
|
readonly surge?: D extends {
|
|
609
615
|
target: {
|
|
@@ -658,6 +664,8 @@ declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<N>;
|
|
|
658
664
|
//#region src/authoring/constructors.d.ts
|
|
659
665
|
export declare function dnsRule(pattern: string, server: string): DnsRule;
|
|
660
666
|
export declare function dnsRule(pattern: readonly string[], server: string): DnsRule[];
|
|
667
|
+
export declare function dnsRule(pattern: string, server: TailscaleDnsOptions): DnsRule<TailscaleDnsOptions>;
|
|
668
|
+
export declare function dnsRule(pattern: readonly string[], server: TailscaleDnsOptions): DnsRule<TailscaleDnsOptions>[];
|
|
661
669
|
type DomainOptions = {
|
|
662
670
|
readonly includeSniffed?: boolean;
|
|
663
671
|
};
|
|
@@ -1236,4 +1244,4 @@ export declare function runBuild(definition: BuildDefinition, options?: {
|
|
|
1236
1244
|
readonly validation?: boolean;
|
|
1237
1245
|
}): Promise<BuildResult>;
|
|
1238
1246
|
//#endregion
|
|
1239
|
-
export type { Assumptions, BuildDefinition, BuildResult, CaseResult, CheckResult, Condition, ProfileDiagnostic as Diagnostic, DnsRule, Exit, ExplainResult, Explanation, Fragments, GroupAlgorithm, Need, Origin, Profile, ProfileDefinition, ProxyBuilder, ProxyGroup, ProxyNode, Route, RouteCase, RouteRequest, RuleSet, SecretRef, Secrets, Selection, SingBoxEndpoint, SurgeGeneral, SurgeHost, SurgeTunnel, Target };
|
|
1247
|
+
export type { Assumptions, BuildDefinition, BuildResult, CaseResult, CheckResult, Condition, ProfileDiagnostic as Diagnostic, DnsRule, Exit, ExplainResult, Explanation, Fragments, GroupAlgorithm, Need, Origin, Profile, ProfileDefinition, ProxyBuilder, ProxyGroup, ProxyNode, Route, RouteCase, RouteRequest, RuleSet, SecretRef, Secrets, Selection, SingBoxEndpoint, SurgeGeneral, SurgeHost, SurgeTunnel, TailscaleDnsOptions, Target };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as ProfileDefinitionError, T as inspectDefinition, _ as endpointSchema, a as defineBuild, b as nativeRuleSetSchema, c as dnsRulesSchema, d as tunnelSchema, f as created, g as requireKind, h as parsed, l as conditionSchema, m as inspectRecord, n as runBuild, o as secretSources, p as flatten, r as explainProfile, s as defineProfile, t as checkBuild, u as groupTestSchema, v as idSchema, w as exactDefinition, x as nodeSchema, y as matchSchema } from "./build-
|
|
1
|
+
import { S as ProfileDefinitionError, T as inspectDefinition, _ as endpointSchema, a as defineBuild, b as nativeRuleSetSchema, c as dnsRulesSchema, d as tunnelSchema, f as created, g as requireKind, h as parsed, l as conditionSchema, m as inspectRecord, n as runBuild, o as secretSources, p as flatten, r as explainProfile, s as defineProfile, t as checkBuild, u as groupTestSchema, v as idSchema, w as exactDefinition, x as nodeSchema, y as matchSchema } from "./build-H0uxqVRQ.js";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
//#region src/authoring/resources.ts
|
|
4
4
|
const builtin = (builtin) => created({ builtin }, "builtin");
|
package/package.json
CHANGED