proxylang 0.3.0 → 0.5.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 { Q as requestSchema, R as compile, U as targetCatalog, i as buildToDirectory, n as profileBuildFailure, q as StaticRuleSetUnknownError, r as runBuild, z as explain } from "./profile-build-CA9qC6N2.js";
2
+ import { K as requestSchema, L as targetCatalog, M as compile, N as explain, V as StaticRuleSetUnknownError, i as buildToDirectory, n as profileBuildFailure, r as runBuild } from "./profile-build-Cokl8MBF.js";
3
3
  import { open } from "node:fs/promises";
4
4
  import { resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
package/dist/index.d.ts CHANGED
@@ -14,6 +14,8 @@ export type NativeRuleSet = {
14
14
  readonly engine: "surge";
15
15
  readonly format: "rule-set" | "domain-set";
16
16
  readonly intervalSeconds?: number;
17
+ readonly noResolve?: boolean;
18
+ readonly extendedMatching?: boolean;
17
19
  } | {
18
20
  readonly engine: "sing-box";
19
21
  readonly format: "source" | "binary";
@@ -25,7 +27,15 @@ export type NativeRuleSet = {
25
27
  readonly intervalSeconds: number;
26
28
  });
27
29
  export type Match = NamedRuleSet | NativeRuleSet | {
28
- readonly type: "domain" | "domainSuffix" | "ipCidr" | "sourceIp";
30
+ readonly type: "domain" | "domainSuffix";
31
+ readonly extendedMatching?: boolean;
32
+ readonly value: string;
33
+ } | {
34
+ readonly type: "ipCidr";
35
+ readonly value: string;
36
+ readonly noResolve?: boolean;
37
+ } | {
38
+ readonly type: "sourceIp" | "processName";
29
39
  readonly value: string;
30
40
  } | {
31
41
  readonly type: "port" | "sourcePort";
@@ -225,7 +235,12 @@ export type Group = Exclude<ConcreteGroup, {
225
235
  readonly type: "surge-smart";
226
236
  }> | Strategy;
227
237
  export type Engine = "surge" | "sing-box" | "mihomo" | "stash";
238
+ export type DnsRule = {
239
+ readonly pattern: string;
240
+ readonly server: string;
241
+ };
228
242
  export type Program = {
243
+ readonly dns?: readonly DnsRule[];
229
244
  readonly engine: Engine;
230
245
  readonly nodes: readonly ProxyNode[];
231
246
  readonly endpoints?: readonly TailscaleEndpoint[];
@@ -248,8 +263,11 @@ export type Target = {
248
263
  export type Request = {
249
264
  readonly network: Network;
250
265
  readonly domain?: string;
266
+ readonly tlsSni?: string;
267
+ readonly httpHost?: string;
251
268
  readonly ip?: string;
252
269
  readonly sourceIp?: string;
270
+ readonly processName?: string;
253
271
  readonly port?: number;
254
272
  readonly sourcePort?: number;
255
273
  };
@@ -447,6 +465,7 @@ type SurgeCondition = ConditionOptions & ({
447
465
  readonly format: "rule-set" | "domain-set";
448
466
  readonly url?: string;
449
467
  readonly builtin?: "LAN" | "SYSTEM";
468
+ readonly intervalSeconds?: number;
450
469
  });
451
470
  type SurgeRule = {
452
471
  readonly when: SurgeCondition;
@@ -660,6 +679,7 @@ type SurgeConfig = DeepReadonly<Pick<SurgeProfileInput, "managed" | "names">> &
660
679
  readonly hosts?: Fragments<DeepReadonly<SurgeHost>>;
661
680
  };
662
681
  type ProfileDefinition = {
682
+ readonly dns?: Fragments<DnsRule>;
663
683
  readonly target: SurgeProfileInput["target"] | {
664
684
  readonly engine: "sing-box";
665
685
  readonly platform: "macos" | "linux";
@@ -678,7 +698,8 @@ type ProfileDefinition = {
678
698
  };
679
699
  };
680
700
  };
681
- type Profile = DeepReadonly<Omit<ProfileDefinition, "proxies" | "groups" | "routes" | "surge"> & {
701
+ type Profile = DeepReadonly<Omit<ProfileDefinition, "proxies" | "groups" | "routes" | "surge" | "dns"> & {
702
+ readonly dns?: readonly DnsRule[];
682
703
  readonly proxies: readonly ProfileProxy[];
683
704
  readonly groups: readonly ProxyGroupDefinition[];
684
705
  readonly routes: readonly RouteDefinition[];
@@ -716,18 +737,72 @@ declare function proxyBuilder<N extends ProxyNode>(node: N): ProxyBuilder<Extrac
716
737
  //#endregion
717
738
  //#region src/dsl.d.ts
718
739
  export declare const ruleSet: (definition: Omit<NamedRuleSet, "type">) => NamedRuleSet;
740
+ type DomainOptions = {
741
+ readonly extendedMatching?: boolean;
742
+ };
743
+ type IpOptions = {
744
+ readonly noResolve?: boolean;
745
+ };
719
746
  export declare const match: {
720
- ruleSet: (set: NamedRuleSet) => Match;
721
- domain: (value: string) => Match;
722
- domainSuffix: (value: string) => Match;
723
- ipCidr: (value: string) => Match;
724
- sourceIp: (value: string) => Match;
725
- port: (from: number, to?: number) => Match;
726
- sourcePort: (from: number, to?: number) => Match;
727
- network: (value: Network) => Match;
728
- all: (...conditions: readonly Match[]) => Match;
729
- any: (...conditions: readonly Match[]) => Match;
730
- not: (condition: Match) => Match;
747
+ processName: (value: string) => {
748
+ readonly type: "processName";
749
+ readonly value: string;
750
+ };
751
+ ruleSet: (set: NamedRuleSet) => NamedRuleSet;
752
+ domain: (value: string, opts?: DomainOptions) => {
753
+ extendedMatching?: boolean;
754
+ type: "domain";
755
+ value: string;
756
+ };
757
+ domainSuffix: (value: string, opts?: DomainOptions) => {
758
+ extendedMatching?: boolean;
759
+ type: "domainSuffix";
760
+ value: string;
761
+ };
762
+ ipCidr: (value: string, opts?: IpOptions) => {
763
+ noResolve?: boolean;
764
+ type: "ipCidr";
765
+ value: string;
766
+ };
767
+ sourceIp: (value: string) => {
768
+ type: "sourceIp";
769
+ value: string;
770
+ };
771
+ port: (from: number, to?: number) => {
772
+ type: "port";
773
+ from: number;
774
+ to: number;
775
+ };
776
+ sourcePort: (from: number, to?: number) => {
777
+ type: "sourcePort";
778
+ from: number;
779
+ to: number;
780
+ };
781
+ network: (value: Network) => {
782
+ type: "network";
783
+ value: Network;
784
+ };
785
+ all: <const C extends readonly ProfileCondition[]>(...conditions: C) => {
786
+ type: "all";
787
+ conditions: C;
788
+ };
789
+ any: <const C extends readonly ProfileCondition[]>(...conditions: C) => {
790
+ type: "any";
791
+ conditions: C;
792
+ };
793
+ not: <const C extends ProfileCondition>(condition: C) => {
794
+ type: "not";
795
+ condition: C;
796
+ };
797
+ };
798
+ type NativeFor<E extends NativeRuleSet["engine"]> = Extract<NativeRuleSet, {
799
+ engine: E;
800
+ }>;
801
+ type NativeInput<E extends NativeRuleSet["engine"]> = Omit<NativeFor<E>, "type" | "engine" | "id"> & {
802
+ readonly id?: string;
803
+ };
804
+ type SurgeSetInput = Omit<NativeInput<"surge">, "format"> & {
805
+ readonly format?: "rule-set" | "domain-set";
731
806
  };
732
807
  export declare const direct: () => Action;
733
808
  export declare const reject: () => Action;
@@ -837,16 +912,78 @@ export declare const surge: {
837
912
  smart: () => Extract<GroupAlgorithm, {
838
913
  type: "surge-smart";
839
914
  }>;
840
- ruleSet: (options: Omit<Extract<NativeRuleSet, {
841
- engine: "surge";
842
- }>, "type" | "engine" | "format"> & {
843
- format?: "rule-set" | "domain-set";
844
- }) => NativeRuleSet;
915
+ ruleSet: {
916
+ (input: Omit<NativeInput<"surge">, "format"> & {
917
+ readonly format?: "rule-set" | "domain-set";
918
+ } & {
919
+ readonly to: ProfileDestination;
920
+ }): RouteDefinition;
921
+ (input: SurgeSetInput): {
922
+ readonly type: "nativeRuleSet";
923
+ readonly id: string;
924
+ readonly url: string;
925
+ } & {
926
+ readonly engine: "surge";
927
+ readonly format: "rule-set" | "domain-set";
928
+ readonly intervalSeconds?: number;
929
+ readonly noResolve?: boolean;
930
+ readonly extendedMatching?: boolean;
931
+ };
932
+ };
845
933
  };
846
934
  export declare const mihomo: {
847
- ruleProvider: (options: Omit<Extract<NativeRuleSet, {
848
- engine: "mihomo";
849
- }>, "type" | "engine">) => NativeRuleSet;
935
+ ruleSet: {
936
+ (input: Omit<{
937
+ readonly type: "nativeRuleSet";
938
+ readonly id: string;
939
+ readonly url: string;
940
+ } & {
941
+ readonly engine: "mihomo";
942
+ readonly format: "yaml" | "text";
943
+ readonly behavior: "domain" | "ipcidr" | "classical";
944
+ readonly intervalSeconds: number;
945
+ }, "engine" | "id" | "type"> & {
946
+ readonly id?: string;
947
+ } & {
948
+ readonly to: ProfileDestination;
949
+ }): RouteDefinition;
950
+ (input: NativeInput<"mihomo">): {
951
+ readonly type: "nativeRuleSet";
952
+ readonly id: string;
953
+ readonly url: string;
954
+ } & {
955
+ readonly engine: "mihomo";
956
+ readonly format: "yaml" | "text";
957
+ readonly behavior: "domain" | "ipcidr" | "classical";
958
+ readonly intervalSeconds: number;
959
+ };
960
+ };
961
+ ruleProvider: {
962
+ (input: Omit<{
963
+ readonly type: "nativeRuleSet";
964
+ readonly id: string;
965
+ readonly url: string;
966
+ } & {
967
+ readonly engine: "mihomo";
968
+ readonly format: "yaml" | "text";
969
+ readonly behavior: "domain" | "ipcidr" | "classical";
970
+ readonly intervalSeconds: number;
971
+ }, "engine" | "id" | "type"> & {
972
+ readonly id?: string;
973
+ } & {
974
+ readonly to: ProfileDestination;
975
+ }): RouteDefinition;
976
+ (input: NativeInput<"mihomo">): {
977
+ readonly type: "nativeRuleSet";
978
+ readonly id: string;
979
+ readonly url: string;
980
+ } & {
981
+ readonly engine: "mihomo";
982
+ readonly format: "yaml" | "text";
983
+ readonly behavior: "domain" | "ipcidr" | "classical";
984
+ readonly intervalSeconds: number;
985
+ };
986
+ };
850
987
  };
851
988
  export declare const proxy: {
852
989
  builder: typeof proxyBuilder;
@@ -858,9 +995,30 @@ export declare const proxy: {
858
995
  vless: (options: Omit<VLESSNode, "type">) => VLESSNode;
859
996
  };
860
997
  export declare const singbox: {
861
- ruleSet: (options: Omit<Extract<NativeRuleSet, {
862
- engine: "sing-box";
863
- }>, "type" | "engine">) => NativeRuleSet;
998
+ ruleSet: {
999
+ (input: Omit<{
1000
+ readonly type: "nativeRuleSet";
1001
+ readonly id: string;
1002
+ readonly url: string;
1003
+ } & {
1004
+ readonly engine: "sing-box";
1005
+ readonly format: "source" | "binary";
1006
+ readonly intervalSeconds: number;
1007
+ }, "engine" | "id" | "type"> & {
1008
+ readonly id?: string;
1009
+ } & {
1010
+ readonly to: ProfileDestination;
1011
+ }): RouteDefinition;
1012
+ (input: NativeInput<"sing-box">): {
1013
+ readonly type: "nativeRuleSet";
1014
+ readonly id: string;
1015
+ readonly url: string;
1016
+ } & {
1017
+ readonly engine: "sing-box";
1018
+ readonly format: "source" | "binary";
1019
+ readonly intervalSeconds: number;
1020
+ };
1021
+ };
864
1022
  tailscale: (options: Omit<TailscaleEndpoint, "type">) => TailscaleEndpoint;
865
1023
  };
866
1024
  //#endregion
@@ -983,4 +1141,8 @@ export declare function runBuild(input: BuildDefinition, output: string, options
983
1141
  readonly validation?: boolean;
984
1142
  }): Promise<ProfileBuildResult>;
985
1143
  //#endregion
1144
+ //#region src/proxy-id.d.ts
1145
+ /** Stable identity independent of engine and mutable metadata. */
1146
+ export declare function proxyId(provider: string, label: string): string;
1147
+ //#endregion
986
1148
  export type { Artifact, BuildContext, BuildDefinition, BuildResult, CaseResult, Compilation, DeepReadonly, Fragments, Profile, ProfileBuildResult, 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 };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import { A as defineRoute, B as compileStrategyGroups, C as strategy, D as defineProfile, E as compileProfile, F as renderSurgeProfile, G as surgeProxy, H as nativeNameSchema, I as renderSurgeProfiles, J as assertData, K as validateProxyOptions, L as secretReader, M as outbound, N as selectProxies, O as ProfileDefinitionError, P as compileSurgeProfile, R as compile, S as slot, T as use, U as targetCatalog, V as isReservedNativeName, W as RenderError, X as idSchema, Y as deepFreeze, Z as nodeSchema, _ 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 defineRoutes, k as defineProxyGroup, l as group, m as reject, o as block, p as proxy, q as StaticRuleSetUnknownError, r as runBuild, s as defineConfig, t as defineBuild, u as match, v as secret, w as surge, x as singbox, y as selectNodes, z as explain } from "./profile-build-CA9qC6N2.js";
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, o as block, p as proxy, q as ProfileDefinitionError, r as runBuild, s as defineConfig, t as defineBuild, u as match, v as secret, w as surge, x as singbox, y as selectNodes, z as surgeProxy } from "./profile-build-Cokl8MBF.js";
2
+ import { createHash } from "node:crypto";
2
3
  import { z } from "zod";
3
4
  //#region src/proxy-fragments.ts
4
5
  const inputSchema = z.strictObject({
@@ -129,4 +130,11 @@ function renderProxyNodes(compilation, resolveSecret) {
129
130
  });
130
131
  }
131
132
  //#endregion
132
- export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildToDirectory, compile, compileProfile, compileProxyNodes, compileStrategyGroups, compileSurgeProfile, defineBuild, defineConfig, defineProfile, defineProxyGroup, defineRoute, defineRoutes, direct, explain, group, match, mihomo, outbound, policy, proxy, reject, render, renderProxyNodes, renderSurgeProfile, renderSurgeProfiles, route, rule, ruleSet, runBuild, secret, selectNodes, selectProxies, sequence, singbox, slot, strategy, surge, targetCatalog, use };
133
+ //#region src/proxy-id.ts
134
+ /** Stable identity independent of engine and mutable metadata. */
135
+ function proxyId(provider, label) {
136
+ if (typeof provider !== "string" || !provider.length || typeof label !== "string" || !label.length) throw new Error("INVALID_PROXY_ID_INPUT");
137
+ return `node-${createHash("sha256").update(JSON.stringify([provider, label])).digest("hex").slice(0, 16)}`;
138
+ }
139
+ //#endregion
140
+ export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildToDirectory, 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 };