proxylang 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -417,3 +417,17 @@ Stash 当前拒绝来源 IP/端口、端口范围和组级 URLTest。完整配
417
417
  - [多设备配置与请求案例](examples/home/proxylang.config.ts):节点筛选、代理链和路由回归案例。
418
418
  - [设计与使用文档](docs/README.md):规则组合、平台机制、CLI 与构建边界。
419
419
  - [开发工作流](docs/engineering/development/README.md):Concord 管理 Feature 与 Use Case,`vp` 负责构建和测试。
420
+
421
+ ### 按域名指定 DNS
422
+
423
+ 同一服务器的多个域名可以一起声明,Profile 的 `dns` 支持数组片段组合:
424
+
425
+ ```ts
426
+ import { dnsRule } from "proxylang";
427
+
428
+ const domestic = dnsRule(["*.example.cn", "example.cn"], "https://223.5.5.5/dns-query");
429
+ const tailnet = dnsRule("*.ts.net", "100.100.100.100");
430
+ // defineProfile({ ..., dns: [domestic, tailnet] })
431
+ ```
432
+
433
+ `*.example.cn` 仅匹配子域,根域需单独列出。函数保留输入顺序,沿用既有 DNS 冲突检查;`DnsRule` 类型仍可用于类型标注。
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-DX7t23HZ.js";
2
+ import { H as StaticRuleSetUnknownError, N as compile, P as explain, R as targetCatalog, i as buildToDirectory, n as defineBuild, q as requestSchema, r as runBuild, t as checkBuild } from "./profile-build-oexsfBwW.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
@@ -737,6 +737,8 @@ declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<Extrac
737
737
  }>>;
738
738
  //#endregion
739
739
  //#region src/dsl.d.ts
740
+ export declare function dnsRule(pattern: string, server: string): DnsRule;
741
+ export declare function dnsRule(patterns: readonly string[], server: string): DnsRule[];
740
742
  export declare const ruleSet: (definition: Omit<NamedRuleSet, "type">) => NamedRuleSet;
741
743
  type DomainOptions = {
742
744
  readonly extendedMatching?: boolean;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { 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 selectProxies, 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 outbound, _ as ruleSet, a as render, b as sequence, c as direct, d as mihomo, f as policy, g as rule, h as route, i as buildToDirectory, j as secretReader, k as renderSurgeProfile, l as group, m as reject, n as defineBuild, o as block, p as proxy, q as ProfileDefinitionError, r as runBuild, s as defineConfig, t as checkBuild, u as match, v as secret, w as surge, x as singbox, y as selectNodes, z as surgeProxy } from "./profile-build-DX7t23HZ.js";
2
- import { createHash } from "node:crypto";
1
+ import { $ as selectProxies, A as renderSurgeProfile, B as surgeProxy, C as slot, D as compileProfile, E as use, F as compileStrategyGroups, G as idSchema, H as StaticRuleSetUnknownError, I as isReservedNativeName, J as ProfileDefinitionError, K as nodeSchema, L as nativeNameSchema, M as secretReader, N as compile, O as defineProfile, P as explain, Q as outbound, R as targetCatalog, S as singbox, T as surge, U as assertData, V as validateProxyOptions, W as deepFreeze, X as defineRoute, Y as defineProxyGroup, Z as defineRoutes, _ as rule, a as render, b as selectNodes, c as direct, d as match, f as mihomo, g as route, h as reject, i as buildToDirectory, j as renderSurgeProfiles, k as compileSurgeProfile, l as dnsRule, m as proxy, n as defineBuild, o as block, p as policy, r as runBuild, s as defineConfig, t as checkBuild, u as group, v as ruleSet, w as strategy, x as sequence, y as secret, z as RenderError } from "./profile-build-oexsfBwW.js";
3
2
  import { z } from "zod";
3
+ import { createHash } from "node:crypto";
4
4
  //#region src/proxy-fragments.ts
5
5
  const inputSchema = z.strictObject({
6
6
  target: z.strictObject({
@@ -137,4 +137,4 @@ function proxyId(provider, label) {
137
137
  return `node-${createHash("sha256").update(JSON.stringify([provider, label])).digest("hex").slice(0, 16)}`;
138
138
  }
139
139
  //#endregion
140
- export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildToDirectory, checkBuild, compile, compileProfile, compileProxyNodes, compileStrategyGroups, compileSurgeProfile, defineBuild, defineConfig, defineProfile, defineProxyGroup, defineRoute, defineRoutes, direct, explain, group, match, mihomo, outbound, policy, proxy, proxyId, reject, render, renderProxyNodes, renderSurgeProfile, renderSurgeProfiles, route, rule, ruleSet, runBuild, secret, selectNodes, selectProxies, sequence, singbox, slot, strategy, surge, targetCatalog, use };
140
+ 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, selectNodes, selectProxies, sequence, singbox, slot, strategy, surge, targetCatalog, use };
@@ -1,10 +1,56 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
1
  import { isIP } from "node:net";
3
2
  import { z } from "zod";
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/dns.ts
9
+ 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
+ function dohUrl(value) {
11
+ const url = new URL(value);
12
+ if (!/^https:\/\/[^/]+\//.test(value)) url.pathname = "/dns-query";
13
+ return url;
14
+ }
15
+ const server = z.string().max(2048).refine((value) => {
16
+ if (isIP(value) && !value.includes("%")) return true;
17
+ if (!value.startsWith("https://") || /[\s\p{C},()\\"'?#]/u.test(value)) return false;
18
+ try {
19
+ const url = new URL(value);
20
+ const authority = value.slice(8).split("/")[0];
21
+ const path = value.slice(8 + authority.length);
22
+ return !url.username && !url.password && !authority.endsWith(":") && !!url.hostname && (!path || url.pathname === path);
23
+ } catch {
24
+ return false;
25
+ }
26
+ });
27
+ const dnsRulesSchema = z.array(z.strictObject({
28
+ pattern: z.string().min(1).max(253).refine((value) => domain$2.test(value.startsWith("*.") ? value.slice(2) : value)),
29
+ server
30
+ })).max(2e3).superRefine((rules, ctx) => {
31
+ if (rules.length > 2e3 || rules.some((rule) => rule.pattern.length > 253 || rule.server.length > 2048)) return;
32
+ for (let i = 0; i < rules.length; i++) for (let j = 0; j < i; j++) {
33
+ const a = rules[i], b = rules[j];
34
+ const x = a.pattern.toLowerCase(), y = b.pattern.toLowerCase();
35
+ if (x === y || overlap(x, y) && a.server !== b.server) {
36
+ ctx.addIssue({
37
+ code: "custom",
38
+ message: "DNS_RULE_CONFLICT"
39
+ });
40
+ return;
41
+ }
42
+ }
43
+ });
44
+ function overlap(a, b) {
45
+ const wildA = a.startsWith("*."), wildB = b.startsWith("*.");
46
+ if (wildA && wildB) return a.slice(1).endsWith(b.slice(1)) || b.slice(1).endsWith(a.slice(1));
47
+ return wildA ? b.endsWith(a.slice(1)) : wildB && a.endsWith(b.slice(1));
48
+ }
49
+ function dnsCondition(rule) {
50
+ const pattern = rule.pattern.toLowerCase();
51
+ return pattern.startsWith("*.") ? { domain_regex: [`^.+\\.${pattern.slice(2).replaceAll(".", "\\.")}$`] } : { domain: [pattern] };
52
+ }
53
+ //#endregion
8
54
  //#region src/surge-definitions.ts
9
55
  var ProfileDefinitionError = class extends Error {
10
56
  code;
@@ -343,52 +389,6 @@ const surgeMatch = {
343
389
  }
344
390
  };
345
391
  //#endregion
346
- //#region src/dns.ts
347
- 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;
348
- function dohUrl(value) {
349
- const url = new URL(value);
350
- if (!/^https:\/\/[^/]+\//.test(value)) url.pathname = "/dns-query";
351
- return url;
352
- }
353
- const server = z.string().max(2048).refine((value) => {
354
- if (isIP(value) && !value.includes("%")) return true;
355
- if (!value.startsWith("https://") || /[\s\p{C},()\\"'?#]/u.test(value)) return false;
356
- try {
357
- const url = new URL(value);
358
- const authority = value.slice(8).split("/")[0];
359
- const path = value.slice(8 + authority.length);
360
- return !url.username && !url.password && !authority.endsWith(":") && !!url.hostname && (!path || url.pathname === path);
361
- } catch {
362
- return false;
363
- }
364
- });
365
- const dnsRulesSchema = z.array(z.strictObject({
366
- pattern: z.string().min(1).max(253).refine((value) => domain$2.test(value.startsWith("*.") ? value.slice(2) : value)),
367
- server
368
- })).max(2e3).superRefine((rules, ctx) => {
369
- if (rules.length > 2e3 || rules.some((rule) => rule.pattern.length > 253 || rule.server.length > 2048)) return;
370
- for (let i = 0; i < rules.length; i++) for (let j = 0; j < i; j++) {
371
- const a = rules[i], b = rules[j];
372
- const x = a.pattern.toLowerCase(), y = b.pattern.toLowerCase();
373
- if (x === y || overlap(x, y) && a.server !== b.server) {
374
- ctx.addIssue({
375
- code: "custom",
376
- message: "DNS_RULE_CONFLICT"
377
- });
378
- return;
379
- }
380
- }
381
- });
382
- function overlap(a, b) {
383
- const wildA = a.startsWith("*."), wildB = b.startsWith("*.");
384
- if (wildA && wildB) return a.slice(1).endsWith(b.slice(1)) || b.slice(1).endsWith(a.slice(1));
385
- return wildA ? b.endsWith(a.slice(1)) : wildB && a.endsWith(b.slice(1));
386
- }
387
- function dnsCondition(rule) {
388
- const pattern = rule.pattern.toLowerCase();
389
- return pattern.startsWith("*.") ? { domain_regex: [`^.+\\.${pattern.slice(2).replaceAll(".", "\\.")}$`] } : { domain: [pattern] };
390
- }
391
- //#endregion
392
392
  //#region src/schema.ts
393
393
  const idSchema = z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/).refine((x) => !x.startsWith("pl-"));
394
394
  const domain$1 = z.string().max(253).regex(/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/);
@@ -2698,6 +2698,21 @@ function proxyBuilder(node) {
2698
2698
  }
2699
2699
  //#endregion
2700
2700
  //#region src/dsl.ts
2701
+ function dnsRule(pattern, server) {
2702
+ inspectDefinition({
2703
+ pattern,
2704
+ server
2705
+ });
2706
+ const batch = Array.isArray(pattern);
2707
+ const patterns = batch ? pattern : [pattern];
2708
+ if (patterns.length > 2e3) throw new ProfileDefinitionError("INVALID_DNS_RULE");
2709
+ const checked = dnsRulesSchema.safeParse(patterns.map((value) => ({
2710
+ pattern: value,
2711
+ server
2712
+ })));
2713
+ if (!checked.success) throw new ProfileDefinitionError("INVALID_DNS_RULE");
2714
+ return batch ? checked.data : checked.data[0];
2715
+ }
2701
2716
  const ruleSet = (definition) => ({
2702
2717
  ...definition,
2703
2718
  type: "ruleSet"
@@ -3564,4 +3579,4 @@ async function runBuild(input, output, options = {}) {
3564
3579
  };
3565
3580
  }
3566
3581
  //#endregion
3567
- export { 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, selectProxies 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, outbound as Z, ruleSet as _, render as a, sequence as b, direct as c, mihomo as d, policy as f, rule as g, route as h, buildToDirectory as i, secretReader as j, renderSurgeProfile as k, group as l, reject as m, defineBuild as n, block as o, proxy as p, ProfileDefinitionError as q, runBuild as r, defineConfig as s, checkBuild as t, match as u, secret as v, surge$1 as w, singbox$1 as x, selectNodes as y, surgeProxy as z };
3582
+ export { selectProxies as $, renderSurgeProfile as A, surgeProxy as B, slot as C, compileProfile as D, use as E, compileStrategyGroups as F, idSchema as G, StaticRuleSetUnknownError as H, isReservedNativeName as I, ProfileDefinitionError as J, nodeSchema as K, nativeNameSchema as L, secretReader as M, compile as N, defineProfile as O, explain as P, outbound as Q, targetCatalog as R, singbox$1 as S, surge$1 as T, assertData as U, validateProxyOptions as V, deepFreeze as W, defineRoute as X, defineProxyGroup as Y, defineRoutes as Z, rule as _, render as a, selectNodes as b, direct as c, match as d, mihomo as f, route as g, reject as h, buildToDirectory as i, renderSurgeProfiles as j, compileSurgeProfile as k, dnsRule as l, proxy as m, defineBuild as n, block as o, policy as p, requestSchema as q, runBuild as r, defineConfig as s, checkBuild as t, group as u, ruleSet as v, strategy as w, sequence as x, secret as y, RenderError as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proxylang",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Composable routing policies in TypeScript with explicit platform targets",
5
5
  "homepage": "https://github.com/CorrectRoadH/proxylang#readme",
6
6
  "bugs": {