proxylang 0.1.6 → 0.2.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 +7 -7
- package/dist/index.d.ts +210 -173
- package/dist/index.js +2 -21
- package/dist/{surge-build-DbQ9Ddhc.js → profile-build-jJlIs97b.js} +1737 -1510
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
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-jJlIs97b.js";
|
|
3
3
|
import { open } from "node:fs/promises";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
@@ -15,7 +15,7 @@ const failure = (code) => {
|
|
|
15
15
|
return 1;
|
|
16
16
|
};
|
|
17
17
|
const usages = {
|
|
18
|
-
"
|
|
18
|
+
"profile-build": ["proxylang profile-build config.ts --out DIRECTORY [--validation]"],
|
|
19
19
|
targets: ["proxylang targets"],
|
|
20
20
|
check: ["proxylang check config.ts"],
|
|
21
21
|
explain: ["proxylang explain config.ts --target ID --request JSON", "proxylang explain config.ts --target ID --request-file FILE"],
|
|
@@ -84,7 +84,7 @@ async function main(args) {
|
|
|
84
84
|
});
|
|
85
85
|
return 0;
|
|
86
86
|
}
|
|
87
|
-
if (command === "
|
|
87
|
+
if (command === "profile-build") return profileBuildCommand(file, rest);
|
|
88
88
|
if (![
|
|
89
89
|
"check",
|
|
90
90
|
"explain",
|
|
@@ -165,9 +165,9 @@ async function main(args) {
|
|
|
165
165
|
});
|
|
166
166
|
return built.exitCode;
|
|
167
167
|
}
|
|
168
|
-
async function
|
|
168
|
+
async function profileBuildCommand(file, args) {
|
|
169
169
|
const invalid = () => {
|
|
170
|
-
print(
|
|
170
|
+
print(profileBuildFailure("INVALID_ARGUMENTS"));
|
|
171
171
|
return 1;
|
|
172
172
|
};
|
|
173
173
|
if (!file?.trim() || file.startsWith("-")) return invalid();
|
|
@@ -191,10 +191,10 @@ async function surgeBuildCommand(file, args) {
|
|
|
191
191
|
const loaded = await tsImport(pathToFileURL(resolve(file)).href, import.meta.url);
|
|
192
192
|
config = loaded.default?.__esModule === true ? loaded.default.default : loaded.default;
|
|
193
193
|
} catch {
|
|
194
|
-
print(
|
|
194
|
+
print(profileBuildFailure("PROFILE_DEFINITION_FAILED", validation));
|
|
195
195
|
return 1;
|
|
196
196
|
}
|
|
197
|
-
const result = await
|
|
197
|
+
const result = await runBuild(config, output, { validation });
|
|
198
198
|
print(result);
|
|
199
199
|
return result.exitCode;
|
|
200
200
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -494,6 +494,205 @@ export declare function compileSurgeProfile(input: unknown): SurgeProfileCompila
|
|
|
494
494
|
export declare function renderSurgeProfile(compilation: SurgeProfileCompilation, resolveSecret: (token: Secret) => string | undefined): SurgeProfileArtifact;
|
|
495
495
|
export declare function renderSurgeProfiles(compilations: readonly SurgeProfileCompilation[], resolveSecret: (token: Secret) => string | undefined): readonly SurgeProfileArtifact[];
|
|
496
496
|
//#endregion
|
|
497
|
+
//#region src/targets.d.ts
|
|
498
|
+
export declare const targetCatalog: readonly [{
|
|
499
|
+
readonly engine: "sing-box";
|
|
500
|
+
readonly version: "1.11.0";
|
|
501
|
+
readonly autoGroup: "urltest";
|
|
502
|
+
readonly platforms: readonly ["linux", "macos"];
|
|
503
|
+
readonly protocols: readonly ["trojan", "http", "shadowsocks", "vmess", "vless"];
|
|
504
|
+
readonly endpoints: readonly [];
|
|
505
|
+
readonly groups: readonly ["select", "urltest"];
|
|
506
|
+
readonly nativeRuleSets: readonly ["source", "binary"];
|
|
507
|
+
readonly dns: "legacy";
|
|
508
|
+
}, {
|
|
509
|
+
readonly engine: "sing-box";
|
|
510
|
+
readonly version: "1.12.0";
|
|
511
|
+
readonly autoGroup: "urltest";
|
|
512
|
+
readonly platforms: readonly ["linux", "macos"];
|
|
513
|
+
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
|
|
514
|
+
readonly endpoints: readonly ["sing-box-tailscale"];
|
|
515
|
+
readonly groups: readonly ["select", "urltest"];
|
|
516
|
+
readonly nativeRuleSets: readonly ["source", "binary"];
|
|
517
|
+
readonly dns: "typed";
|
|
518
|
+
}, {
|
|
519
|
+
readonly engine: "surge";
|
|
520
|
+
readonly version: "6.10.0";
|
|
521
|
+
readonly autoGroup: "surge-smart";
|
|
522
|
+
readonly platforms: readonly ["macos"];
|
|
523
|
+
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
|
|
524
|
+
readonly endpoints: readonly [];
|
|
525
|
+
readonly groups: readonly ["select", "surge-smart"];
|
|
526
|
+
readonly nativeRuleSets: readonly ["rule-set", "domain-set"];
|
|
527
|
+
readonly dns: "general";
|
|
528
|
+
}, {
|
|
529
|
+
readonly engine: "mihomo";
|
|
530
|
+
readonly version: "1.19.32";
|
|
531
|
+
readonly autoGroup: "urltest";
|
|
532
|
+
readonly platforms: readonly ["linux", "macos"];
|
|
533
|
+
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
|
|
534
|
+
readonly endpoints: readonly [];
|
|
535
|
+
readonly groups: readonly ["select", "urltest"];
|
|
536
|
+
readonly nativeRuleSets: readonly ["yaml", "text"];
|
|
537
|
+
readonly dns: "clash";
|
|
538
|
+
}, {
|
|
539
|
+
readonly engine: "stash";
|
|
540
|
+
readonly version: "4.2.1";
|
|
541
|
+
readonly autoGroup: null;
|
|
542
|
+
readonly platforms: readonly ["macos"];
|
|
543
|
+
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
|
|
544
|
+
readonly endpoints: readonly [];
|
|
545
|
+
readonly groups: readonly ["select"];
|
|
546
|
+
readonly nativeRuleSets: readonly [];
|
|
547
|
+
readonly dns: "external";
|
|
548
|
+
}];
|
|
549
|
+
//#endregion
|
|
550
|
+
//#region src/compiler.d.ts
|
|
551
|
+
type TargetPlan = {
|
|
552
|
+
readonly target: Target;
|
|
553
|
+
readonly program: Omit<Program, "groups"> & {
|
|
554
|
+
readonly groups: readonly ConcreteGroup[];
|
|
555
|
+
};
|
|
556
|
+
readonly nativeRuleSets: readonly NativeRuleSet[];
|
|
557
|
+
readonly strategySelections: readonly StrategySelection[];
|
|
558
|
+
readonly rules: readonly ExpandedRule[];
|
|
559
|
+
readonly sourceMap: readonly {
|
|
560
|
+
readonly rule: string;
|
|
561
|
+
readonly nativeIndex: number;
|
|
562
|
+
readonly origin: readonly string[];
|
|
563
|
+
}[];
|
|
564
|
+
readonly preconditions: readonly string[];
|
|
565
|
+
readonly nativeValidation: "not-run";
|
|
566
|
+
};
|
|
567
|
+
type Compilation = {
|
|
568
|
+
readonly ok: boolean;
|
|
569
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
570
|
+
readonly plans: readonly TargetPlan[];
|
|
571
|
+
readonly cases: readonly CaseResult[];
|
|
572
|
+
};
|
|
573
|
+
type CaseResult = {
|
|
574
|
+
readonly id: string;
|
|
575
|
+
readonly passed: boolean;
|
|
576
|
+
readonly actual: {
|
|
577
|
+
readonly rule: string;
|
|
578
|
+
readonly action: Action;
|
|
579
|
+
};
|
|
580
|
+
} | {
|
|
581
|
+
readonly id: string;
|
|
582
|
+
readonly passed: false;
|
|
583
|
+
readonly code: "CASE_INDETERMINATE";
|
|
584
|
+
};
|
|
585
|
+
export declare function compile(input: unknown): Compilation;
|
|
586
|
+
export declare function explain(compilation: Compilation, target: string, request: Request): Explanation;
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/surge-definitions.d.ts
|
|
589
|
+
interface ProxyGroupDefinition {
|
|
590
|
+
readonly type: "proxy-group";
|
|
591
|
+
readonly id: string;
|
|
592
|
+
readonly name: string;
|
|
593
|
+
readonly algorithm: GroupAlgorithm;
|
|
594
|
+
readonly members: readonly ProfileDestination[];
|
|
595
|
+
readonly url?: string;
|
|
596
|
+
readonly intervalSeconds?: number;
|
|
597
|
+
readonly timeoutSeconds?: number;
|
|
598
|
+
}
|
|
599
|
+
type RouteDefinition = {
|
|
600
|
+
readonly type: "route";
|
|
601
|
+
readonly when: ProfileCondition;
|
|
602
|
+
readonly to: ProfileDestination;
|
|
603
|
+
};
|
|
604
|
+
export declare class ProfileDefinitionError extends Error {
|
|
605
|
+
readonly code: string;
|
|
606
|
+
constructor(code: string);
|
|
607
|
+
}
|
|
608
|
+
export declare const outbound: {
|
|
609
|
+
direct: Readonly<{
|
|
610
|
+
readonly builtin: "DIRECT";
|
|
611
|
+
}>;
|
|
612
|
+
reject: Readonly<{
|
|
613
|
+
readonly builtin: "REJECT";
|
|
614
|
+
}>;
|
|
615
|
+
rejectDrop: Readonly<{
|
|
616
|
+
readonly builtin: "REJECT-DROP";
|
|
617
|
+
}>;
|
|
618
|
+
rejectNoDrop: Readonly<{
|
|
619
|
+
readonly builtin: "REJECT-NO-DROP";
|
|
620
|
+
}>;
|
|
621
|
+
rejectTinyGif: Readonly<{
|
|
622
|
+
readonly builtin: "REJECT-TINYGIF";
|
|
623
|
+
}>;
|
|
624
|
+
};
|
|
625
|
+
export declare function defineProxyGroup(input: Omit<ProxyGroupDefinition, "type">): ProxyGroupDefinition;
|
|
626
|
+
export declare function defineRoute(input: Omit<RouteDefinition, "type">): RouteDefinition;
|
|
627
|
+
export declare function defineRoutes(input: {
|
|
628
|
+
readonly when: readonly ProfileCondition[];
|
|
629
|
+
readonly to: ProfileDestination;
|
|
630
|
+
}): RouteDefinition[];
|
|
631
|
+
export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
|
|
632
|
+
ids?: readonly string[];
|
|
633
|
+
regions?: readonly string[];
|
|
634
|
+
providers?: readonly string[];
|
|
635
|
+
tags?: readonly string[];
|
|
636
|
+
}): ProxyNode[];
|
|
637
|
+
//#endregion
|
|
638
|
+
//#region src/profile.d.ts
|
|
639
|
+
type DeepReadonly<T> = T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
|
|
640
|
+
type ProfileCondition = Exclude<Match | SurgeCondition, {
|
|
641
|
+
type: "all" | "any" | "not";
|
|
642
|
+
}> | {
|
|
643
|
+
readonly type: "all" | "any";
|
|
644
|
+
readonly conditions: readonly ProfileCondition[];
|
|
645
|
+
readonly noResolve?: boolean;
|
|
646
|
+
readonly extendedMatching?: boolean;
|
|
647
|
+
} | {
|
|
648
|
+
readonly type: "not";
|
|
649
|
+
readonly condition: ProfileCondition;
|
|
650
|
+
readonly noResolve?: boolean;
|
|
651
|
+
readonly extendedMatching?: boolean;
|
|
652
|
+
};
|
|
653
|
+
type ProfileDestination = ProxyNode | ProxyGroupDefinition | SurgeTunnel | TailscaleEndpoint | {
|
|
654
|
+
readonly builtin: "DIRECT" | "REJECT" | "REJECT-DROP" | "REJECT-NO-DROP" | "REJECT-TINYGIF";
|
|
655
|
+
};
|
|
656
|
+
type SurgeConfig = Pick<SurgeProfileInput, "managed" | "general" | "hosts" | "names">;
|
|
657
|
+
type ProfileDefinition = {
|
|
658
|
+
readonly target: SurgeProfileInput["target"] | {
|
|
659
|
+
readonly engine: "sing-box";
|
|
660
|
+
readonly platform: "macos" | "linux";
|
|
661
|
+
readonly version: string;
|
|
662
|
+
};
|
|
663
|
+
readonly nodes: readonly ProxyNode[];
|
|
664
|
+
readonly groups: readonly ProxyGroupDefinition[];
|
|
665
|
+
readonly routes: readonly RouteDefinition[];
|
|
666
|
+
readonly fallback: ProfileDestination;
|
|
667
|
+
readonly endpoints?: readonly (SurgeTunnel | TailscaleEndpoint)[];
|
|
668
|
+
readonly surge?: DeepReadonly<SurgeConfig>;
|
|
669
|
+
readonly singBox?: {
|
|
670
|
+
readonly mode: "fragment" | "standalone";
|
|
671
|
+
readonly listener?: {
|
|
672
|
+
readonly port: number;
|
|
673
|
+
readonly resolver: string;
|
|
674
|
+
};
|
|
675
|
+
};
|
|
676
|
+
};
|
|
677
|
+
type Profile = DeepReadonly<ProfileDefinition>;
|
|
678
|
+
type ProfileCompilation = {
|
|
679
|
+
readonly engine: "surge";
|
|
680
|
+
readonly ok: boolean;
|
|
681
|
+
readonly compilation: SurgeProfileCompilation;
|
|
682
|
+
} | {
|
|
683
|
+
readonly engine: "sing-box";
|
|
684
|
+
readonly ok: boolean;
|
|
685
|
+
readonly compilation: Compilation;
|
|
686
|
+
} | {
|
|
687
|
+
readonly engine: "invalid";
|
|
688
|
+
readonly ok: false;
|
|
689
|
+
readonly code: string;
|
|
690
|
+
};
|
|
691
|
+
declare function surgeConfig(input: SurgeConfig): DeepReadonly<SurgeConfig>;
|
|
692
|
+
export declare function defineProfile(input: ProfileDefinition | Profile): Profile;
|
|
693
|
+
/** No secrets or I/O. All engine adaptations retain strict validation. */
|
|
694
|
+
export declare function compileProfile(input: ProfileDefinition | Profile): ProfileCompilation;
|
|
695
|
+
//#endregion
|
|
497
696
|
//#region src/proxy-builder.d.ts
|
|
498
697
|
type ProxyBuilder<N extends ProxyNode> = {
|
|
499
698
|
readonly via: (id: string) => ProxyBuilder<N>;
|
|
@@ -568,6 +767,7 @@ export declare const group: {
|
|
|
568
767
|
}>;
|
|
569
768
|
};
|
|
570
769
|
export declare const surge: {
|
|
770
|
+
config: typeof surgeConfig;
|
|
571
771
|
match: {
|
|
572
772
|
domain: (value: string, options?: {
|
|
573
773
|
readonly noResolve?: boolean;
|
|
@@ -655,97 +855,6 @@ export declare const singbox: {
|
|
|
655
855
|
tailscale: (options: Omit<TailscaleEndpoint, "type">) => TailscaleEndpoint;
|
|
656
856
|
};
|
|
657
857
|
//#endregion
|
|
658
|
-
//#region src/targets.d.ts
|
|
659
|
-
export declare const targetCatalog: readonly [{
|
|
660
|
-
readonly engine: "sing-box";
|
|
661
|
-
readonly version: "1.11.0";
|
|
662
|
-
readonly autoGroup: "urltest";
|
|
663
|
-
readonly platforms: readonly ["linux", "macos"];
|
|
664
|
-
readonly protocols: readonly ["trojan", "http", "shadowsocks", "vmess", "vless"];
|
|
665
|
-
readonly endpoints: readonly [];
|
|
666
|
-
readonly groups: readonly ["select", "urltest"];
|
|
667
|
-
readonly nativeRuleSets: readonly ["source", "binary"];
|
|
668
|
-
readonly dns: "legacy";
|
|
669
|
-
}, {
|
|
670
|
-
readonly engine: "sing-box";
|
|
671
|
-
readonly version: "1.12.0";
|
|
672
|
-
readonly autoGroup: "urltest";
|
|
673
|
-
readonly platforms: readonly ["linux", "macos"];
|
|
674
|
-
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
|
|
675
|
-
readonly endpoints: readonly ["sing-box-tailscale"];
|
|
676
|
-
readonly groups: readonly ["select", "urltest"];
|
|
677
|
-
readonly nativeRuleSets: readonly ["source", "binary"];
|
|
678
|
-
readonly dns: "typed";
|
|
679
|
-
}, {
|
|
680
|
-
readonly engine: "surge";
|
|
681
|
-
readonly version: "6.10.0";
|
|
682
|
-
readonly autoGroup: "surge-smart";
|
|
683
|
-
readonly platforms: readonly ["macos"];
|
|
684
|
-
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
|
|
685
|
-
readonly endpoints: readonly [];
|
|
686
|
-
readonly groups: readonly ["select", "surge-smart"];
|
|
687
|
-
readonly nativeRuleSets: readonly ["rule-set", "domain-set"];
|
|
688
|
-
readonly dns: "general";
|
|
689
|
-
}, {
|
|
690
|
-
readonly engine: "mihomo";
|
|
691
|
-
readonly version: "1.19.32";
|
|
692
|
-
readonly autoGroup: "urltest";
|
|
693
|
-
readonly platforms: readonly ["linux", "macos"];
|
|
694
|
-
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess", "vless"];
|
|
695
|
-
readonly endpoints: readonly [];
|
|
696
|
-
readonly groups: readonly ["select", "urltest"];
|
|
697
|
-
readonly nativeRuleSets: readonly ["yaml", "text"];
|
|
698
|
-
readonly dns: "clash";
|
|
699
|
-
}, {
|
|
700
|
-
readonly engine: "stash";
|
|
701
|
-
readonly version: "4.2.1";
|
|
702
|
-
readonly autoGroup: null;
|
|
703
|
-
readonly platforms: readonly ["macos"];
|
|
704
|
-
readonly protocols: readonly ["trojan", "http", "anytls", "shadowsocks", "vmess"];
|
|
705
|
-
readonly endpoints: readonly [];
|
|
706
|
-
readonly groups: readonly ["select"];
|
|
707
|
-
readonly nativeRuleSets: readonly [];
|
|
708
|
-
readonly dns: "external";
|
|
709
|
-
}];
|
|
710
|
-
//#endregion
|
|
711
|
-
//#region src/compiler.d.ts
|
|
712
|
-
type TargetPlan = {
|
|
713
|
-
readonly target: Target;
|
|
714
|
-
readonly program: Omit<Program, "groups"> & {
|
|
715
|
-
readonly groups: readonly ConcreteGroup[];
|
|
716
|
-
};
|
|
717
|
-
readonly nativeRuleSets: readonly NativeRuleSet[];
|
|
718
|
-
readonly strategySelections: readonly StrategySelection[];
|
|
719
|
-
readonly rules: readonly ExpandedRule[];
|
|
720
|
-
readonly sourceMap: readonly {
|
|
721
|
-
readonly rule: string;
|
|
722
|
-
readonly nativeIndex: number;
|
|
723
|
-
readonly origin: readonly string[];
|
|
724
|
-
}[];
|
|
725
|
-
readonly preconditions: readonly string[];
|
|
726
|
-
readonly nativeValidation: "not-run";
|
|
727
|
-
};
|
|
728
|
-
type Compilation = {
|
|
729
|
-
readonly ok: boolean;
|
|
730
|
-
readonly diagnostics: readonly Diagnostic[];
|
|
731
|
-
readonly plans: readonly TargetPlan[];
|
|
732
|
-
readonly cases: readonly CaseResult[];
|
|
733
|
-
};
|
|
734
|
-
type CaseResult = {
|
|
735
|
-
readonly id: string;
|
|
736
|
-
readonly passed: boolean;
|
|
737
|
-
readonly actual: {
|
|
738
|
-
readonly rule: string;
|
|
739
|
-
readonly action: Action;
|
|
740
|
-
};
|
|
741
|
-
} | {
|
|
742
|
-
readonly id: string;
|
|
743
|
-
readonly passed: false;
|
|
744
|
-
readonly code: "CASE_INDETERMINATE";
|
|
745
|
-
};
|
|
746
|
-
export declare function compile(input: unknown): Compilation;
|
|
747
|
-
export declare function explain(compilation: Compilation, target: string, request: Request): Explanation;
|
|
748
|
-
//#endregion
|
|
749
858
|
//#region src/proxies.d.ts
|
|
750
859
|
export declare class RenderError extends Error {
|
|
751
860
|
readonly code: string;
|
|
@@ -844,97 +953,25 @@ type ProxyNodeArtifact = {
|
|
|
844
953
|
export declare function compileProxyNodes(input: unknown): ProxyNodeCompilation;
|
|
845
954
|
export declare function renderProxyNodes(compilation: ProxyNodeCompilation, resolveSecret: (token: Secret) => string | undefined): ProxyNodeArtifact;
|
|
846
955
|
//#endregion
|
|
847
|
-
//#region src/
|
|
848
|
-
|
|
849
|
-
export declare function surgeProfile(input: SurgeProfileInput, names?: Readonly<Record<string, string>>): SurgeProfileInput;
|
|
850
|
-
/** Stable queries produce native-profile policy references without consumer mapping code. */
|
|
851
|
-
export declare function surgeMembers(nodes: readonly ProxyNode[], query?: Parameters<typeof selectNodes>[1]): SurgePolicy[];
|
|
852
|
-
//#endregion
|
|
853
|
-
//#region src/surge-host.d.ts
|
|
854
|
-
/** Complete-profile batches use the out symlink protocol; the Program host remains unchanged. */
|
|
855
|
-
export declare function buildSurgeProfilesToDirectory(profiles: Readonly<Record<string, SurgeProfileInput>>, output: string, resolveSecret?: (token: Secret) => string | undefined): Promise<BuildResult>;
|
|
856
|
-
//#endregion
|
|
857
|
-
//#region src/surge-definitions.d.ts
|
|
858
|
-
type Builtin = Extract<SurgePolicy, {
|
|
859
|
-
builtin: string;
|
|
860
|
-
}>;
|
|
861
|
-
type Destination = ProxyNode | ProxyGroupDefinition | SurgeTunnel | Builtin;
|
|
862
|
-
type ProxyGroupDefinition = {
|
|
863
|
-
readonly type: "proxy-group";
|
|
864
|
-
readonly id: string;
|
|
865
|
-
readonly name: string;
|
|
866
|
-
readonly algorithm: Extract<GroupAlgorithm, {
|
|
867
|
-
type: "select" | "surge-smart";
|
|
868
|
-
}>;
|
|
869
|
-
readonly members: readonly Destination[];
|
|
870
|
-
readonly url?: string;
|
|
871
|
-
readonly intervalSeconds?: number;
|
|
872
|
-
readonly timeoutSeconds?: number;
|
|
873
|
-
};
|
|
874
|
-
type RouteDefinition = {
|
|
875
|
-
readonly type: "route";
|
|
876
|
-
readonly when: SurgeCondition;
|
|
877
|
-
readonly to: Destination;
|
|
878
|
-
};
|
|
879
|
-
type SurgeProfileDefinition = Omit<SurgeProfileInput, "groups" | "rules" | "fallback"> & {
|
|
880
|
-
readonly groups: readonly ProxyGroupDefinition[];
|
|
881
|
-
readonly routes: readonly RouteDefinition[];
|
|
882
|
-
readonly fallback: Destination;
|
|
883
|
-
};
|
|
884
|
-
export declare class ProfileDefinitionError extends Error {
|
|
885
|
-
readonly code: string;
|
|
886
|
-
constructor(code: string);
|
|
887
|
-
}
|
|
888
|
-
export declare const outbound: {
|
|
889
|
-
direct: Readonly<{
|
|
890
|
-
readonly builtin: "DIRECT";
|
|
891
|
-
}>;
|
|
892
|
-
reject: Readonly<{
|
|
893
|
-
readonly builtin: "REJECT";
|
|
894
|
-
}>;
|
|
895
|
-
rejectDrop: Readonly<{
|
|
896
|
-
readonly builtin: "REJECT-DROP";
|
|
897
|
-
}>;
|
|
898
|
-
rejectNoDrop: Readonly<{
|
|
899
|
-
readonly builtin: "REJECT-NO-DROP";
|
|
900
|
-
}>;
|
|
901
|
-
rejectTinyGif: Readonly<{
|
|
902
|
-
readonly builtin: "REJECT-TINYGIF";
|
|
903
|
-
}>;
|
|
904
|
-
};
|
|
905
|
-
export declare function defineProxyGroup(input: Omit<ProxyGroupDefinition, "type">): ProxyGroupDefinition;
|
|
906
|
-
export declare function defineRoute(input: Omit<RouteDefinition, "type">): RouteDefinition;
|
|
907
|
-
export declare function defineRoutes(input: {
|
|
908
|
-
readonly when: readonly SurgeCondition[];
|
|
909
|
-
readonly to: Destination;
|
|
910
|
-
}): RouteDefinition[];
|
|
911
|
-
export declare function selectProxies(nodes: readonly ProxyNode[], query?: {
|
|
912
|
-
ids?: readonly string[];
|
|
913
|
-
regions?: readonly string[];
|
|
914
|
-
providers?: readonly string[];
|
|
915
|
-
tags?: readonly string[];
|
|
916
|
-
}): ProxyNode[];
|
|
917
|
-
export declare function defineSurgeProfile(input: SurgeProfileDefinition): SurgeProfileInput;
|
|
918
|
-
//#endregion
|
|
919
|
-
//#region src/surge-build.d.ts
|
|
920
|
-
type SurgeBuildContext = {
|
|
956
|
+
//#region src/profile-build.d.ts
|
|
957
|
+
type BuildContext = {
|
|
921
958
|
readonly validation: boolean;
|
|
922
959
|
};
|
|
923
|
-
type
|
|
924
|
-
readonly profiles: Readonly<Record<string,
|
|
960
|
+
type BuildDefinition = {
|
|
961
|
+
readonly profiles: Readonly<Record<string, Profile>>;
|
|
925
962
|
readonly preflight?: () => readonly string[];
|
|
926
|
-
readonly resolveSecret?: (token: Secret, context:
|
|
963
|
+
readonly resolveSecret?: (token: Secret, context: BuildContext) => string | undefined;
|
|
927
964
|
};
|
|
928
|
-
type
|
|
965
|
+
type ProfileBuildResult = BuildResult & {
|
|
929
966
|
readonly warnings: Readonly<Record<string, number>>;
|
|
930
967
|
readonly validation: boolean;
|
|
931
968
|
readonly profileCount: number;
|
|
932
969
|
};
|
|
933
970
|
/** Capture data and callback references before application preflight can change its source. */
|
|
934
|
-
export declare function
|
|
971
|
+
export declare function defineBuild(input: BuildDefinition): BuildDefinition;
|
|
935
972
|
/** Pure orchestration result; the CLI owns stdout and process exit status. */
|
|
936
|
-
export declare function
|
|
973
|
+
export declare function runBuild(input: BuildDefinition, output: string, options?: {
|
|
937
974
|
readonly validation?: boolean;
|
|
938
|
-
}): Promise<
|
|
975
|
+
}): Promise<ProfileBuildResult>;
|
|
939
976
|
//#endregion
|
|
940
|
-
export type { Artifact, BuildResult, CaseResult, Compilation,
|
|
977
|
+
export type { Artifact, BuildContext, BuildDefinition, BuildResult, CaseResult, Compilation, DeepReadonly, Profile, ProfileBuildResult, ProfileCompilation, ProfileCondition, ProfileDefinition, ProfileDestination, 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,4 @@
|
|
|
1
|
-
import { A as
|
|
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-jJlIs97b.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/proxy-fragments.ts
|
|
4
4
|
const inputSchema = z.strictObject({
|
|
@@ -129,23 +129,4 @@ function renderProxyNodes(compilation, resolveSecret) {
|
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
//#endregion
|
|
132
|
-
|
|
133
|
-
/** Bind shared names only for included resources; explicit input mappings remain compiler-checked. */
|
|
134
|
-
function surgeProfile(input, names = {}) {
|
|
135
|
-
const bindings = {};
|
|
136
|
-
for (const node of input.nodes) bindings[node.id] = names[node.id] ?? node.label ?? node.id;
|
|
137
|
-
for (const resource of [...input.tunnels ?? [], ...input.groups]) bindings[resource.id] = names[resource.id] ?? resource.id;
|
|
138
|
-
return {
|
|
139
|
-
...input,
|
|
140
|
-
names: {
|
|
141
|
-
...bindings,
|
|
142
|
-
...input.names
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
/** Stable queries produce native-profile policy references without consumer mapping code. */
|
|
147
|
-
function surgeMembers(nodes, query = {}) {
|
|
148
|
-
return selectNodes(nodes, query).map((ref) => ({ ref }));
|
|
149
|
-
}
|
|
150
|
-
//#endregion
|
|
151
|
-
export { ProfileDefinitionError, RenderError, StaticRuleSetUnknownError, block, buildSurgeProfilesToDirectory, buildToDirectory, compile, compileProxyNodes, compileStrategyGroups, compileSurgeProfile, defineConfig, defineProxyGroup, defineRoute, defineRoutes, defineSurgeBuild, defineSurgeProfile, direct, explain, group, match, mihomo, outbound, policy, proxy, reject, render, renderProxyNodes, renderSurgeProfile, renderSurgeProfiles, route, rule, ruleSet, runSurgeBuild, secret, selectNodes, selectProxies, sequence, singbox, slot, strategy, surge, surgeMembers, surgeProfile, targetCatalog, use };
|
|
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 };
|