proxylang 0.6.1 → 0.7.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/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
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";
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-EO6TsFJ-.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 extendedMatching?: boolean;
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 extendedMatching?: boolean;
32
+ readonly sources?: readonly DomainSource[];
32
33
  readonly value: string;
33
34
  } | {
34
35
  readonly type: "ipCidr";
@@ -443,7 +444,7 @@ declare const groupSchema: z.ZodObject<{
443
444
  type SurgeGroup = z.infer<typeof groupSchema>;
444
445
  type ConditionOptions = {
445
446
  readonly noResolve?: boolean;
446
- readonly extendedMatching?: boolean;
447
+ readonly sources?: readonly DomainSource[];
447
448
  };
448
449
  type SurgeCondition = ConditionOptions & ({
449
450
  readonly type: "domain" | "domainSuffix" | "ipCidr" | "ipCidr6" | "sourceIp" | "processName" | "macAddress";
@@ -663,12 +664,12 @@ type ProfileCondition = Exclude<Match | SurgeCondition, {
663
664
  readonly type: "all" | "any";
664
665
  readonly conditions: readonly ProfileCondition[];
665
666
  readonly noResolve?: boolean;
666
- readonly extendedMatching?: boolean;
667
+ readonly sources?: readonly DomainSource[];
667
668
  } | {
668
669
  readonly type: "not";
669
670
  readonly condition: ProfileCondition;
670
671
  readonly noResolve?: boolean;
671
- readonly extendedMatching?: boolean;
672
+ readonly sources?: readonly DomainSource[];
672
673
  };
673
674
  type ProfileDestination = string | ProxyNode | ProxyGroupDefinition | SurgeTunnel | TailscaleEndpoint | {
674
675
  readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
@@ -741,7 +742,7 @@ export declare function dnsRule(pattern: string, server: string): DnsRule;
741
742
  export declare function dnsRule(patterns: readonly string[], server: string): DnsRule[];
742
743
  export declare const ruleSet: (definition: Omit<NamedRuleSet, "type">) => NamedRuleSet;
743
744
  type DomainOptions = {
744
- readonly extendedMatching?: boolean;
745
+ readonly sources?: readonly DomainSource[];
745
746
  };
746
747
  type IpOptions = {
747
748
  readonly noResolve?: boolean;
@@ -753,12 +754,12 @@ export declare const match: {
753
754
  };
754
755
  ruleSet: (set: NamedRuleSet) => NamedRuleSet;
755
756
  domain: (value: string, opts?: DomainOptions) => {
756
- extendedMatching?: boolean;
757
+ sources?: readonly DomainSource[];
757
758
  type: "domain";
758
759
  value: string;
759
760
  };
760
761
  domainSuffix: (value: string, opts?: DomainOptions) => {
761
- extendedMatching?: boolean;
762
+ sources?: readonly DomainSource[];
762
763
  type: "domainSuffix";
763
764
  value: string;
764
765
  };
@@ -858,55 +859,55 @@ export declare const surge: {
858
859
  match: {
859
860
  domain: (value: string, options?: {
860
861
  readonly noResolve?: boolean;
861
- readonly extendedMatching?: boolean;
862
+ readonly sources?: readonly DomainSource[];
862
863
  }) => SurgeCondition;
863
864
  domainSuffix: (value: string, options?: {
864
865
  readonly noResolve?: boolean;
865
- readonly extendedMatching?: boolean;
866
+ readonly sources?: readonly DomainSource[];
866
867
  }) => SurgeCondition;
867
868
  ipCidr: (value: string, options?: {
868
869
  readonly noResolve?: boolean;
869
- readonly extendedMatching?: boolean;
870
+ readonly sources?: readonly DomainSource[];
870
871
  }) => SurgeCondition;
871
872
  ipCidr6: (value: string, options?: {
872
873
  readonly noResolve?: boolean;
873
- readonly extendedMatching?: boolean;
874
+ readonly sources?: readonly DomainSource[];
874
875
  }) => SurgeCondition;
875
876
  sourceIp: (value: string, options?: {
876
877
  readonly noResolve?: boolean;
877
- readonly extendedMatching?: boolean;
878
+ readonly sources?: readonly DomainSource[];
878
879
  }) => SurgeCondition;
879
880
  processName: (value: string, options?: {
880
881
  readonly noResolve?: boolean;
881
- readonly extendedMatching?: boolean;
882
+ readonly sources?: readonly DomainSource[];
882
883
  }) => SurgeCondition;
883
884
  macAddress: (value: string, options?: {
884
885
  readonly noResolve?: boolean;
885
- readonly extendedMatching?: boolean;
886
+ readonly sources?: readonly DomainSource[];
886
887
  }) => SurgeCondition;
887
888
  network: (value: "tcp" | "udp", options?: {
888
889
  readonly noResolve?: boolean;
889
- readonly extendedMatching?: boolean;
890
+ readonly sources?: readonly DomainSource[];
890
891
  }) => SurgeCondition;
891
892
  port: (from: number, to?: number, options?: {
892
893
  readonly noResolve?: boolean;
893
- readonly extendedMatching?: boolean;
894
+ readonly sources?: readonly DomainSource[];
894
895
  }) => SurgeCondition;
895
896
  sourcePort: (from: number, to?: number, options?: {
896
897
  readonly noResolve?: boolean;
897
- readonly extendedMatching?: boolean;
898
+ readonly sources?: readonly DomainSource[];
898
899
  }) => SurgeCondition;
899
900
  all: (conditions: readonly SurgeCondition[], options?: {
900
901
  readonly noResolve?: boolean;
901
- readonly extendedMatching?: boolean;
902
+ readonly sources?: readonly DomainSource[];
902
903
  }) => SurgeCondition;
903
904
  any: (conditions: readonly SurgeCondition[], options?: {
904
905
  readonly noResolve?: boolean;
905
- readonly extendedMatching?: boolean;
906
+ readonly sources?: readonly DomainSource[];
906
907
  }) => SurgeCondition;
907
908
  not: (value: SurgeCondition, options?: {
908
909
  readonly noResolve?: boolean;
909
- readonly extendedMatching?: boolean;
910
+ readonly sources?: readonly DomainSource[];
910
911
  }) => SurgeCondition;
911
912
  ruleSet: (options: Omit<Extract<SurgeCondition, {
912
913
  type: "ruleSet";
@@ -930,7 +931,7 @@ export declare const surge: {
930
931
  readonly format: "rule-set" | "domain-set";
931
932
  readonly intervalSeconds?: number;
932
933
  readonly noResolve?: boolean;
933
- readonly extendedMatching?: boolean;
934
+ readonly sources?: readonly DomainSource[];
934
935
  };
935
936
  };
936
937
  };
@@ -1145,7 +1146,7 @@ type BuildDefinition = {
1145
1146
  readonly outDir?: string;
1146
1147
  readonly profiles: Readonly<Record<string, Profile | ProfileDefinition>>;
1147
1148
  readonly preflight?: () => readonly string[];
1148
- readonly resolveSecret?: (token: Secret, context: BuildContext) => string | undefined;
1149
+ readonly secrets?: (token: Secret, context: BuildContext) => string | undefined;
1149
1150
  };
1150
1151
  type ProfileBuildResult = BuildResult & {
1151
1152
  readonly warnings: Readonly<Record<string, number>>;
@@ -1163,4 +1164,13 @@ export declare function runBuild(input: BuildDefinition, output: string, options
1163
1164
  /** Stable identity independent of engine and mutable metadata. */
1164
1165
  export declare function proxyId(provider: string, label: string): string;
1165
1166
  //#endregion
1166
- export type { Artifact, BuildContext, BuildDefinition, BuildResult, CaseResult, Compilation, DeepReadonly, Fragments, Profile, ProfileBuildResult, ProfileCheckResult, ProfileCompilation, ProfileCondition, ProfileDefinition, ProfileDestination, ProfileProxy, ProxyBuilder, ProxyGroupDefinition, ProxyNodeArtifact, ProxyNodeCompilation, ProxyNodeInput, RouteDefinition, StrategyGroupCompilation, StrategyGroupInput, SurgeCondition, SurgeConfig, SurgeGeneral, SurgeGroup, SurgeHost, SurgePolicy, SurgeProfileArtifact, SurgeProfileCompilation, SurgeProfileInput, SurgeRule, SurgeTunnel, TargetPlan };
1167
+ //#region src/secret-inputs.d.ts
1168
+ type SecretsInput = {
1169
+ readonly values?: Readonly<Record<string, string>>;
1170
+ readonly env?: readonly string[];
1171
+ readonly validation?: Readonly<Record<string, string>>;
1172
+ };
1173
+ /** Capture declarations now; read only referenced, allowed environment names at render time. */
1174
+ export declare function secrets(input: SecretsInput, environment?: Readonly<Record<string, string | undefined>>): (token: Secret, context?: BuildContext) => string | undefined;
1175
+ //#endregion
1176
+ 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 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";
1
+ import { $ as inspectDefinition, 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 exactDefinition, 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, et as outbound, 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, tt as selectProxies, u as group, v as ruleSet, w as strategy, x as sequence, y as secret, z as RenderError } from "./profile-build-EO6TsFJ-.js";
2
2
  import { z } from "zod";
3
3
  import { createHash } from "node:crypto";
4
4
  //#region src/proxy-fragments.ts
@@ -137,4 +137,58 @@ 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, 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 };
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, selectNodes, selectProxies, 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) {
@@ -430,7 +452,7 @@ const nativeRuleSetSchema = z.discriminatedUnion("engine", [
430
452
  format: z.enum(["rule-set", "domain-set"]),
431
453
  intervalSeconds: updateInterval.optional(),
432
454
  noResolve: z.boolean().optional(),
433
- extendedMatching: z.boolean().optional()
455
+ sources: domainSourcesSchema.optional()
434
456
  }),
435
457
  z.strictObject({
436
458
  ...remoteBase,
@@ -460,12 +482,12 @@ const matchSchema = z.lazy(() => z.discriminatedUnion("type", [
460
482
  z.strictObject({
461
483
  type: z.literal("domain"),
462
484
  value: domain$1,
463
- extendedMatching: z.boolean().optional()
485
+ sources: domainSourcesSchema.optional()
464
486
  }),
465
487
  z.strictObject({
466
488
  type: z.literal("domainSuffix"),
467
489
  value: domain$1,
468
- extendedMatching: z.boolean().optional()
490
+ sources: domainSourcesSchema.optional()
469
491
  }),
470
492
  z.strictObject({
471
493
  type: z.literal("ipCidr"),
@@ -787,7 +809,7 @@ function deepFreeze(value) {
787
809
  //#region src/rulesets.ts
788
810
  function canonical(value) {
789
811
  if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
790
- if (value && typeof value === "object") return `{${Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
812
+ if (value && typeof value === "object") return `{${domainIdentityFields(value).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
791
813
  return JSON.stringify(value);
792
814
  }
793
815
  function validateRuleSets(entries, engine, diagnostics, path) {
@@ -1008,11 +1030,7 @@ function evaluate(condition, request) {
1008
1030
  switch (condition.type) {
1009
1031
  case "domain":
1010
1032
  case "domainSuffix": {
1011
- const domains = condition.extendedMatching ? [
1012
- request.domain,
1013
- request.tlsSni,
1014
- request.httpHost
1015
- ] : [request.domain];
1033
+ const domains = (condition.sources ?? ["destination"]).map((source) => source === "destination" ? request.domain : request[source]);
1016
1034
  present = domains.some((value) => value !== void 0);
1017
1035
  matched = domains.some((value) => value !== void 0 && (value === condition.value || condition.type === "domainSuffix" && value.endsWith(`.${condition.value}`)));
1018
1036
  break;
@@ -1811,7 +1829,7 @@ function compile(input) {
1811
1829
  for (const rule of rules) if (logicalDepth(rule.when) > 10) error("LOGICAL_DEPTH", rule.id, "Surge 逻辑条件最多嵌套 10 层", target.id);
1812
1830
  }
1813
1831
  const checkOptions = (condition) => {
1814
- if ("extendedMatching" in condition && condition.extendedMatching === true && target.engine !== "surge" || condition.type === "ipCidr" && condition.noResolve !== void 0 && target.engine === "sing-box") error("MATCH_OPTION_UNSUPPORTED", path, "目标无法等价实现显式匹配选项", target.id);
1832
+ 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
1833
  if (condition.type === "all" || condition.type === "any") condition.conditions.forEach(checkOptions);
1816
1834
  else if (condition.type === "not") checkOptions(condition.condition);
1817
1835
  else if (condition.type === "ruleSet") checkOptions(condition.when);
@@ -2064,7 +2082,7 @@ const groupSchema = z.strictObject({
2064
2082
  });
2065
2083
  const options$1 = {
2066
2084
  noResolve: z.boolean().optional(),
2067
- extendedMatching: z.boolean().optional()
2085
+ sources: domainSourcesSchema.optional()
2068
2086
  };
2069
2087
  const atom = (type, value) => z.strictObject({
2070
2088
  type: z.literal(type),
@@ -2239,11 +2257,12 @@ function compileSurgeProfile(input) {
2239
2257
  "ipCidr6",
2240
2258
  "ruleSet"
2241
2259
  ].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
2242
- if (c.extendedMatching !== void 0 && ![
2260
+ if (c.sources !== void 0 && ![
2243
2261
  "domain",
2244
2262
  "domainSuffix",
2245
2263
  "ruleSet"
2246
2264
  ].includes(c.type)) error("RULE_OPTION_UNSUPPORTED");
2265
+ if (c.sources !== void 0 && !supportsDomainSources(c.sources, "surge")) error("MATCH_OPTION_UNSUPPORTED");
2247
2266
  if (p.target.platform === "ios" && ["processName", "macAddress"].includes(c.type)) error("PLATFORM_RULE_UNSUPPORTED");
2248
2267
  if (c.type === "all" || c.type === "any") for (const child of c.conditions) checkCondition(child, depth + 1);
2249
2268
  if (c.type === "not") checkCondition(c.condition, depth + 1);
@@ -2282,7 +2301,7 @@ function compileSurgeProfile(input) {
2282
2301
  function conditionOptions(c) {
2283
2302
  return [
2284
2303
  ...c.noResolve ? ["no-resolve"] : [],
2285
- ...c.extendedMatching ? ["extended-matching"] : [],
2304
+ ...extendedDomainSources(c.sources) ? ["extended-matching"] : [],
2286
2305
  ...c.type === "ruleSet" && c.intervalSeconds !== void 0 ? [`update-interval=${c.intervalSeconds}`] : []
2287
2306
  ];
2288
2307
  }
@@ -2521,7 +2540,7 @@ function surgeCondition$1(condition, depth = 0) {
2521
2540
  url: value.url,
2522
2541
  ...value.intervalSeconds !== void 0 ? { intervalSeconds: value.intervalSeconds } : {},
2523
2542
  ...value.noResolve !== void 0 ? { noResolve: value.noResolve } : {},
2524
- ...value.extendedMatching !== void 0 ? { extendedMatching: value.extendedMatching } : {}
2543
+ ...value.sources !== void 0 ? { sources: value.sources } : {}
2525
2544
  };
2526
2545
  }
2527
2546
  if (condition.type === "all" || condition.type === "any") {
@@ -2720,8 +2739,9 @@ const ruleSet = (definition) => ({
2720
2739
  function options(value, keys) {
2721
2740
  inspectDefinition(value);
2722
2741
  exactDefinition(value, keys);
2723
- if (Object.values(value).some((v) => v !== void 0 && typeof v !== "boolean")) throw new ProfileDefinitionError("INVALID_MATCH_OPTIONS");
2724
- return { ...value };
2742
+ if ("sources" in value && value.sources !== void 0 && !domainSourcesSchema.safeParse(value.sources).success) throw new ProfileDefinitionError("INVALID_DOMAIN_SOURCES");
2743
+ if (Object.entries(value).some(([key, v]) => key !== "sources" && v !== void 0 && typeof v !== "boolean")) throw new ProfileDefinitionError("INVALID_MATCH_OPTIONS");
2744
+ return snapshotDefinition(value);
2725
2745
  }
2726
2746
  const match = {
2727
2747
  processName: (value) => {
@@ -2735,12 +2755,12 @@ const match = {
2735
2755
  domain: (value, opts = {}) => ({
2736
2756
  type: "domain",
2737
2757
  value,
2738
- ...options(opts, ["extendedMatching"])
2758
+ ...options(opts, ["sources"])
2739
2759
  }),
2740
2760
  domainSuffix: (value, opts = {}) => ({
2741
2761
  type: "domainSuffix",
2742
2762
  value,
2743
- ...options(opts, ["extendedMatching"])
2763
+ ...options(opts, ["sources"])
2744
2764
  }),
2745
2765
  ipCidr: (value, opts = {}) => ({
2746
2766
  type: "ipCidr",
@@ -2788,7 +2808,7 @@ function nativeConstructor(engine) {
2788
2808
  "format",
2789
2809
  "intervalSeconds",
2790
2810
  "noResolve",
2791
- "extendedMatching",
2811
+ "sources",
2792
2812
  "behavior",
2793
2813
  "to"
2794
2814
  ]);
@@ -2799,7 +2819,7 @@ function nativeConstructor(engine) {
2799
2819
  "url",
2800
2820
  "format",
2801
2821
  "intervalSeconds",
2802
- ...engine === "surge" ? ["noResolve", "extendedMatching"] : engine === "mihomo" ? ["behavior"] : []
2822
+ ...engine === "surge" ? ["noResolve", "sources"] : engine === "mihomo" ? ["behavior"] : []
2803
2823
  ]);
2804
2824
  const parsed = nativeRuleSetSchema.safeParse({
2805
2825
  ...engine === "surge" ? { format: "rule-set" } : {},
@@ -2810,7 +2830,7 @@ function nativeConstructor(engine) {
2810
2830
  });
2811
2831
  if (!parsed.success) throw new ProfileDefinitionError("INVALID_NATIVE_RULESET");
2812
2832
  const { id: _id, type: _type, ...fields } = parsed.data;
2813
- const id = resource.id ?? `ruleset-${createHash("sha256").update(JSON.stringify(Object.entries(fields).filter(([, value]) => value !== void 0).sort(([a], [b]) => a.localeCompare(b)))).digest("hex").slice(0, 16)}`;
2833
+ const id = resource.id ?? `ruleset-${createHash("sha256").update(JSON.stringify(domainIdentityFields(fields))).digest("hex").slice(0, 16)}`;
2814
2834
  const when = snapshotDefinition({
2815
2835
  ...parsed.data,
2816
2836
  id
@@ -3103,7 +3123,7 @@ function surgeOptions(condition) {
3103
3123
  return [
3104
3124
  ...condition.type === "ipCidr" && condition.noResolve !== false ? ["no-resolve"] : [],
3105
3125
  ...condition.type === "nativeRuleSet" && condition.engine === "surge" && condition.noResolve ? ["no-resolve"] : [],
3106
- ..."extendedMatching" in condition && condition.extendedMatching ? ["extended-matching"] : []
3126
+ ..."sources" in condition && extendedDomainSources(condition.sources) ? ["extended-matching"] : []
3107
3127
  ].map((value) => `,${value}`).join("");
3108
3128
  }
3109
3129
  function surgeCondition(condition) {
@@ -3456,7 +3476,7 @@ function checkBuild(input) {
3456
3476
  }))
3457
3477
  };
3458
3478
  }
3459
- async function publish(profiles, output, resolver) {
3479
+ async function publish(profiles, output, readSecret) {
3460
3480
  try {
3461
3481
  const checked = compileBatch(profiles, output);
3462
3482
  if (!checked.ok) return {
@@ -3465,7 +3485,7 @@ async function publish(profiles, output, resolver) {
3465
3485
  code: checked.code
3466
3486
  };
3467
3487
  const { entries, compiled } = checked;
3468
- const read = secretReader(resolver);
3488
+ const read = secretReader(readSecret);
3469
3489
  const files = /* @__PURE__ */ new Map();
3470
3490
  for (const [index, profile] of compiled.entries()) {
3471
3491
  if (profile.engine === "invalid") throw new Error();
@@ -3507,17 +3527,17 @@ function defineBuild(input) {
3507
3527
  record(input, [
3508
3528
  "profiles",
3509
3529
  "preflight",
3510
- "resolveSecret",
3530
+ "secrets",
3511
3531
  "outDir"
3512
3532
  ]);
3513
3533
  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
3534
  record(input.profiles);
3515
- for (const callback of [input.preflight, input.resolveSecret]) if (callback !== void 0 && typeof callback !== "function") throw new Error();
3535
+ for (const callback of [input.preflight, input.secrets]) if (callback !== void 0 && typeof callback !== "function") throw new Error();
3516
3536
  return Object.freeze({
3517
3537
  ...input.outDir === void 0 ? {} : { outDir: input.outDir },
3518
3538
  profiles: snapshotProfile(input.profiles),
3519
3539
  ...input.preflight === void 0 ? {} : { preflight: input.preflight },
3520
- ...input.resolveSecret === void 0 ? {} : { resolveSecret: input.resolveSecret }
3540
+ ...input.secrets === void 0 ? {} : { secrets: input.secrets }
3521
3541
  });
3522
3542
  } catch {
3523
3543
  throw new ProfileDefinitionError("INVALID_BUILD_DEFINITION");
@@ -3554,7 +3574,7 @@ async function runBuild(input, output, options = {}) {
3554
3574
  const failure = (code) => profileBuildFailure(code, validation, profileCount);
3555
3575
  if (typeof output !== "string" || !output.trim()) return failure("INVALID_OUTPUT_DIRECTORY");
3556
3576
  output = resolve(root, output);
3557
- if (validation && !definition.resolveSecret) return failure("VALIDATION_RESOLVER_REQUIRED");
3577
+ if (validation && !definition.secrets) return failure("VALIDATION_SECRETS_REQUIRED");
3558
3578
  let codes;
3559
3579
  try {
3560
3580
  codes = definition.preflight ? definition.preflight() : [];
@@ -3570,13 +3590,13 @@ async function runBuild(input, output, options = {}) {
3570
3590
  const warnings = {};
3571
3591
  for (const code of codes) warnings[code] = (warnings[code] ?? 0) + 1;
3572
3592
  const context = Object.freeze({ validation });
3573
- const resolver = definition.resolveSecret;
3593
+ const readSecret = definition.secrets;
3574
3594
  return {
3575
- ...await publish(definition.profiles, output, resolver ? (token) => resolver(token, context) : (token) => process.env[token.name]),
3595
+ ...await publish(definition.profiles, output, readSecret ? (token) => readSecret(token, context) : (token) => process.env[token.name]),
3576
3596
  warnings,
3577
3597
  validation,
3578
3598
  profileCount
3579
3599
  };
3580
3600
  }
3581
3601
  //#endregion
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 };
3602
+ export { inspectDefinition 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, exactDefinition 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, outbound as et, 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, selectProxies as tt, 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.1",
3
+ "version": "0.7.0",
4
4
  "description": "Composable routing policies in TypeScript with explicit platform targets",
5
5
  "homepage": "https://github.com/CorrectRoadH/proxylang#readme",
6
6
  "bugs": {