proxylang 0.9.0 → 0.9.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/dist/cli.js +12 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +1 -1
- package/dist/{profile-build-Dg7xfQbi.js → profile-build-Cyrem-0-.js} +105 -13
- package/package.json +1 -1
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-
|
|
2
|
+
import { K as requestSchema, L as targetCatalog, M as compile, N as explain, V as StaticRuleSetUnknownError, Z as definitionDiagnostic, i as buildToDirectory, n as defineBuild, r as runBuild, t as checkBuild } from "./profile-build-Cyrem-0-.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";
|
|
@@ -41,6 +41,17 @@ async function readRequestFile(path) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
function loadFailure(cause) {
|
|
44
|
+
const diagnostic = definitionDiagnostic(cause);
|
|
45
|
+
if (diagnostic) {
|
|
46
|
+
print({
|
|
47
|
+
ok: false,
|
|
48
|
+
code: "CONFIG_LOAD_FAILED",
|
|
49
|
+
reason: "INVALID_CONFIGURATION",
|
|
50
|
+
diagnostic,
|
|
51
|
+
hint: "检查配置字段与库定义约束"
|
|
52
|
+
});
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
44
55
|
let code;
|
|
45
56
|
let name;
|
|
46
57
|
try {
|
package/dist/index.d.ts
CHANGED
|
@@ -626,7 +626,8 @@ type RouteDefinition = {
|
|
|
626
626
|
};
|
|
627
627
|
export declare class ProfileDefinitionError extends Error {
|
|
628
628
|
readonly code: string;
|
|
629
|
-
|
|
629
|
+
readonly paths?: readonly string[];
|
|
630
|
+
constructor(code: string, paths?: readonly string[]);
|
|
630
631
|
}
|
|
631
632
|
export declare const outbound: {
|
|
632
633
|
direct: Readonly<{
|
|
@@ -713,6 +714,7 @@ type ProfileCompilation = {
|
|
|
713
714
|
readonly engine: "invalid";
|
|
714
715
|
readonly ok: false;
|
|
715
716
|
readonly code: string;
|
|
717
|
+
readonly paths?: readonly string[];
|
|
716
718
|
};
|
|
717
719
|
declare function surgeConfig(input: SurgeConfig): SurgeConfig;
|
|
718
720
|
export declare function defineProfile(input: ProfileDefinition | Profile): Profile;
|
|
@@ -1029,11 +1031,18 @@ type Artifact = {
|
|
|
1029
1031
|
/** Secret resolution is once per token per batch, including across providers. */
|
|
1030
1032
|
export declare function render(compilation: Compilation, resolveSecret: (token: Secret) => string | undefined): readonly Artifact[];
|
|
1031
1033
|
//#endregion
|
|
1034
|
+
//#region src/secrets.d.ts
|
|
1035
|
+
type SecretFailure = {
|
|
1036
|
+
readonly secretName?: string;
|
|
1037
|
+
readonly secretReason?: "MISSING" | "RESOLUTION_FAILED";
|
|
1038
|
+
};
|
|
1039
|
+
//#endregion
|
|
1032
1040
|
//#region src/host.d.ts
|
|
1033
|
-
type BuildResult = {
|
|
1041
|
+
type BuildResult = SecretFailure & {
|
|
1034
1042
|
readonly published: boolean;
|
|
1035
1043
|
readonly exitCode: 0 | 1 | 2;
|
|
1036
1044
|
readonly code: string;
|
|
1045
|
+
readonly paths?: readonly string[];
|
|
1037
1046
|
readonly active?: string;
|
|
1038
1047
|
readonly generation?: string;
|
|
1039
1048
|
readonly reason?: "ACCESS_DENIED" | "NO_SPACE" | "READ_ONLY" | "INVALID_DIRECTORY" | "IO_ERROR";
|
|
@@ -1123,6 +1132,7 @@ type ProfileCheckResult = {
|
|
|
1123
1132
|
readonly engine: "surge" | "sing-box" | "invalid";
|
|
1124
1133
|
readonly ok: boolean;
|
|
1125
1134
|
readonly code?: string;
|
|
1135
|
+
readonly paths?: readonly string[];
|
|
1126
1136
|
readonly diagnostics: readonly Diagnostic[];
|
|
1127
1137
|
}[];
|
|
1128
1138
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as inspectDefinition, 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 exactDefinition, R as RenderError, S as slot, T as use, U as deepFreeze, V as StaticRuleSetUnknownError, W as idSchema, X as defineRoutes, Y as defineRoute, _ as rule, a as render, b as sequence, c as direct, d as match, et as outbound, f as mihomo, g as route, h as reject, i as buildToDirectory, j as secretReader, k as renderSurgeProfile, l as dnsRule, m as proxy, n as defineBuild, o as block, p as policy, q as ProfileDefinitionError, r as runBuild, s as defineConfig, t as checkBuild, u as group, v as ruleSet, w as surge, x as singbox, y as secret, z as surgeProxy } from "./profile-build-Cyrem-0-.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
//#region src/proxy-fragments.ts
|
|
@@ -58,12 +58,75 @@ function dnsCondition(rule) {
|
|
|
58
58
|
}
|
|
59
59
|
//#endregion
|
|
60
60
|
//#region src/surge-definitions.ts
|
|
61
|
+
const definitionCodes = /* @__PURE__ */ new Set([
|
|
62
|
+
"DEFINITION_CYCLE",
|
|
63
|
+
"DEFINITION_DEPTH_EXCEEDED",
|
|
64
|
+
"DEFINITION_EDGE_BUDGET_EXCEEDED",
|
|
65
|
+
"DEFINITION_NOT_DATA",
|
|
66
|
+
"DEFINITION_OBJECT_BUDGET_EXCEEDED",
|
|
67
|
+
"DEFINITION_OUTPUT_BUDGET_EXCEEDED",
|
|
68
|
+
"DEFINITION_UNKNOWN_FIELD",
|
|
69
|
+
"DNS_HOSTS_CONFLICT",
|
|
70
|
+
"DNS_RULE_CONFLICT",
|
|
71
|
+
"DUPLICATE_RESOURCE_ID",
|
|
72
|
+
"GROUP_NAME_CONFLICT",
|
|
73
|
+
"INVALID_BUILD_DEFINITION",
|
|
74
|
+
"INVALID_DESTINATION",
|
|
75
|
+
"INVALID_DNS_RULE",
|
|
76
|
+
"INVALID_DNS_RULES",
|
|
77
|
+
"INVALID_GROUP_DEFINITION",
|
|
78
|
+
"INVALID_MATCH_OPTIONS",
|
|
79
|
+
"INVALID_NATIVE_RULESET",
|
|
80
|
+
"INVALID_PROFILE_DEFINITION",
|
|
81
|
+
"INVALID_RESOURCE_DEFINITION",
|
|
82
|
+
"INVALID_ROUTE_DEFINITION",
|
|
83
|
+
"INVALID_SECRETS_DEFINITION",
|
|
84
|
+
"INVALID_SURGE_GENERAL",
|
|
85
|
+
"INVALID_SURGE_HOSTS",
|
|
86
|
+
"LOGICAL_DEPTH_EXCEEDED",
|
|
87
|
+
"PROFILE_CONDITION_UNSUPPORTED",
|
|
88
|
+
"PROFILE_DESTINATION_UNSUPPORTED",
|
|
89
|
+
"PROFILE_ENDPOINT_UNSUPPORTED",
|
|
90
|
+
"PROFILE_EXTENSION_UNSUPPORTED",
|
|
91
|
+
"PROFILE_GROUP_MEMBER_UNSUPPORTED",
|
|
92
|
+
"PROFILE_GROUP_OPTIONS_UNSUPPORTED",
|
|
93
|
+
"PROFILE_TARGET_UNSUPPORTED",
|
|
94
|
+
"RULESET_COMPOSITION_UNSUPPORTED",
|
|
95
|
+
"UNKNOWN_DESTINATION_ID",
|
|
96
|
+
"UNREGISTERED_DESTINATION_INSTANCE",
|
|
97
|
+
"UNSUPPORTED_GROUP_ALGORITHM"
|
|
98
|
+
]);
|
|
99
|
+
function validDiagnosticPath(path) {
|
|
100
|
+
return typeof path === "string" && /^(dns|surge\.hosts)\[\d{1,4}\]$/.test(path);
|
|
101
|
+
}
|
|
102
|
+
function definitionDiagnostic(error) {
|
|
103
|
+
try {
|
|
104
|
+
if (!error || typeof error !== "object") return;
|
|
105
|
+
const name = Object.getOwnPropertyDescriptor(error, "name")?.value;
|
|
106
|
+
const code = Object.getOwnPropertyDescriptor(error, "code")?.value;
|
|
107
|
+
if (name !== "ProfileDefinitionError" || typeof code !== "string" || !definitionCodes.has(code)) return;
|
|
108
|
+
const paths = Object.getOwnPropertyDescriptor(error, "paths")?.value;
|
|
109
|
+
if (code === "DNS_HOSTS_CONFLICT" && Array.isArray(paths) && Object.getOwnPropertyDescriptor(paths, "length")?.value === 2) {
|
|
110
|
+
const first = Object.getOwnPropertyDescriptor(paths, "0")?.value;
|
|
111
|
+
const second = Object.getOwnPropertyDescriptor(paths, "1")?.value;
|
|
112
|
+
if (validDiagnosticPath(first) && validDiagnosticPath(second)) return {
|
|
113
|
+
code,
|
|
114
|
+
paths: [first, second]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return { code };
|
|
118
|
+
} catch {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
61
122
|
var ProfileDefinitionError = class extends Error {
|
|
62
123
|
code;
|
|
63
|
-
|
|
124
|
+
paths;
|
|
125
|
+
constructor(code, paths) {
|
|
64
126
|
super(code);
|
|
65
127
|
this.code = code;
|
|
66
128
|
this.name = "ProfileDefinitionError";
|
|
129
|
+
if (paths?.length === 2 && paths.every(validDiagnosticPath)) this.paths = Object.freeze([...paths]);
|
|
67
130
|
}
|
|
68
131
|
};
|
|
69
132
|
const fail$1 = (code) => {
|
|
@@ -1910,6 +1973,18 @@ function explain(compilation, target, request) {
|
|
|
1910
1973
|
}
|
|
1911
1974
|
//#endregion
|
|
1912
1975
|
//#region src/secrets.ts
|
|
1976
|
+
const failures = /* @__PURE__ */ new WeakMap();
|
|
1977
|
+
function secretFailure(error) {
|
|
1978
|
+
return error !== null && typeof error === "object" ? failures.get(error) ?? {} : {};
|
|
1979
|
+
}
|
|
1980
|
+
function failure(code, name, reason) {
|
|
1981
|
+
const error = new RenderError(code);
|
|
1982
|
+
if (/^[A-Z][A-Z0-9_]{0,127}$/.test(name)) failures.set(error, Object.freeze({
|
|
1983
|
+
secretName: name,
|
|
1984
|
+
secretReason: reason
|
|
1985
|
+
}));
|
|
1986
|
+
return error;
|
|
1987
|
+
}
|
|
1913
1988
|
/** One reader per rendering batch; exceptions and missing values never disclose credentials. */
|
|
1914
1989
|
function secretReader(resolveSecret) {
|
|
1915
1990
|
const values = /* @__PURE__ */ new Map();
|
|
@@ -1918,10 +1993,11 @@ function secretReader(resolveSecret) {
|
|
|
1918
1993
|
let value;
|
|
1919
1994
|
try {
|
|
1920
1995
|
value = resolveSecret(token);
|
|
1921
|
-
} catch {
|
|
1922
|
-
|
|
1996
|
+
} catch (error) {
|
|
1997
|
+
const nested = secretFailure(error);
|
|
1998
|
+
throw failure("SECRET_RESOLUTION_FAILED", token.name, nested.secretName === token.name && nested.secretReason === "MISSING" ? "MISSING" : "RESOLUTION_FAILED");
|
|
1923
1999
|
}
|
|
1924
|
-
if (typeof value !== "string" || value.length === 0) throw
|
|
2000
|
+
if (typeof value !== "string" || value.length === 0) throw failure("SECRET_MISSING", token.name, "MISSING");
|
|
1925
2001
|
values.set(token.name, value);
|
|
1926
2002
|
return value;
|
|
1927
2003
|
};
|
|
@@ -2495,7 +2571,15 @@ function defineProfile(input) {
|
|
|
2495
2571
|
...input.surge.hosts === void 0 ? {} : { hosts: flatten(input.surge.hosts) }
|
|
2496
2572
|
};
|
|
2497
2573
|
}
|
|
2498
|
-
if (dns?.length && surge?.hosts?.length)
|
|
2574
|
+
if (dns?.length && surge?.hosts?.length) {
|
|
2575
|
+
if (dns.length + surge.hosts.length > 2e3) fail("INVALID_SURGE_HOSTS");
|
|
2576
|
+
const patterns = new Map(dns.map((entry, index) => [entry.pattern.toLowerCase(), index]));
|
|
2577
|
+
for (const [index, host] of surge.hosts.entries()) {
|
|
2578
|
+
if (typeof host?.pattern !== "string") fail("INVALID_SURGE_HOSTS");
|
|
2579
|
+
const dnsIndex = patterns.get(host.pattern.toLowerCase());
|
|
2580
|
+
if (dnsIndex !== void 0) throw new ProfileDefinitionError("DNS_HOSTS_CONFLICT", [`dns[${dnsIndex}]`, `surge.hosts[${index}]`]);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2499
2583
|
const { dns: _dns, surge: _surge, proxies: _proxies, groups: _groups, routes: _routes, ...rest } = input;
|
|
2500
2584
|
return snapshotProfile({
|
|
2501
2585
|
...rest,
|
|
@@ -2584,7 +2668,7 @@ function compileProfile(input) {
|
|
|
2584
2668
|
const compilation = compileSurgeProfile(lowerSurgeProfile({
|
|
2585
2669
|
target: profile.target,
|
|
2586
2670
|
...profile.surge,
|
|
2587
|
-
...profile.dns?.length ? { hosts: profile.dns } : {},
|
|
2671
|
+
...profile.dns?.length ? { hosts: [...profile.dns, ...profile.surge?.hosts ?? []] } : {},
|
|
2588
2672
|
nodes,
|
|
2589
2673
|
tunnels: endpoints,
|
|
2590
2674
|
groups: profile.groups,
|
|
@@ -2701,7 +2785,8 @@ function compileProfile(input) {
|
|
|
2701
2785
|
return {
|
|
2702
2786
|
engine: "invalid",
|
|
2703
2787
|
ok: false,
|
|
2704
|
-
code: error instanceof ProfileDefinitionError ? error.code : "INVALID_PROFILE_DEFINITION"
|
|
2788
|
+
code: error instanceof ProfileDefinitionError ? error.code : "INVALID_PROFILE_DEFINITION",
|
|
2789
|
+
...error instanceof ProfileDefinitionError && error.paths ? { paths: error.paths } : {}
|
|
2705
2790
|
};
|
|
2706
2791
|
}
|
|
2707
2792
|
}
|
|
@@ -3299,7 +3384,10 @@ async function buildToDirectory(compilation, output, resolveSecret = (token) =>
|
|
|
3299
3384
|
code = "PUBLISHED";
|
|
3300
3385
|
} catch (error) {
|
|
3301
3386
|
code = error instanceof RenderError ? error.code : "OUTPUT_FAILED";
|
|
3302
|
-
detail = error instanceof RenderError ? {
|
|
3387
|
+
detail = error instanceof RenderError ? {
|
|
3388
|
+
hint: buildHints[code],
|
|
3389
|
+
...secretFailure(error)
|
|
3390
|
+
} : outputFailure(error);
|
|
3303
3391
|
} finally {
|
|
3304
3392
|
if (locked) {
|
|
3305
3393
|
try {
|
|
@@ -3434,7 +3522,8 @@ function compileBatch(profiles, output) {
|
|
|
3434
3522
|
const entries = Object.entries(profiles);
|
|
3435
3523
|
const compiled = [];
|
|
3436
3524
|
let outputDirectoryChecked = false;
|
|
3437
|
-
const result = (code) => ({
|
|
3525
|
+
const result = (code, paths) => ({
|
|
3526
|
+
...paths ? { paths } : {},
|
|
3438
3527
|
ok: code === "CHECKED",
|
|
3439
3528
|
code,
|
|
3440
3529
|
entries,
|
|
@@ -3444,7 +3533,7 @@ function compileBatch(profiles, output) {
|
|
|
3444
3533
|
if (!entries.length || entries.length > 16 || entries.some(([id]) => !/^[a-z0-9][a-z0-9-]*$/.test(id))) return result("INVALID_PROFILE_FILENAMES");
|
|
3445
3534
|
compiled.push(...entries.map(([, profile]) => compileProfile(profile)));
|
|
3446
3535
|
const invalid = compiled.find((profile) => !profile.ok);
|
|
3447
|
-
if (invalid) return result(invalid.engine === "invalid" ? invalid.code : "COMPILATION_FAILED");
|
|
3536
|
+
if (invalid) return result(invalid.engine === "invalid" ? invalid.code : "COMPILATION_FAILED", invalid.engine === "invalid" ? invalid.paths : void 0);
|
|
3448
3537
|
if (output !== void 0) {
|
|
3449
3538
|
outputDirectoryChecked = true;
|
|
3450
3539
|
if (compiled.some((profile) => profile.engine === "sing-box" && profile.compilation.plans.some((plan) => plan.program.endpoints?.some((endpoint) => pathsOverlap(output, endpoint.stateDirectory))))) return result("ENDPOINT_STATE_OVERLAP");
|
|
@@ -3477,6 +3566,7 @@ function checkBuild(input) {
|
|
|
3477
3566
|
ok: profile.ok,
|
|
3478
3567
|
...profile.engine === "invalid" ? {
|
|
3479
3568
|
code: profile.code,
|
|
3569
|
+
...profile.paths ? { paths: profile.paths } : {},
|
|
3480
3570
|
diagnostics: []
|
|
3481
3571
|
} : { diagnostics: profile.compilation.diagnostics }
|
|
3482
3572
|
}))
|
|
@@ -3488,7 +3578,8 @@ async function publish(profiles, output, readSecret) {
|
|
|
3488
3578
|
if (!checked.ok) return {
|
|
3489
3579
|
published: false,
|
|
3490
3580
|
exitCode: 1,
|
|
3491
|
-
code: checked.code
|
|
3581
|
+
code: checked.code,
|
|
3582
|
+
...checked.paths ? { paths: checked.paths } : {}
|
|
3492
3583
|
};
|
|
3493
3584
|
const { entries, compiled } = checked;
|
|
3494
3585
|
const read = secretReader(readSecret);
|
|
@@ -3516,7 +3607,8 @@ async function publish(profiles, output, readSecret) {
|
|
|
3516
3607
|
return {
|
|
3517
3608
|
published: false,
|
|
3518
3609
|
exitCode: 1,
|
|
3519
|
-
code: error instanceof RenderError ? error.code : "BUILD_FAILED"
|
|
3610
|
+
code: error instanceof RenderError ? error.code : "BUILD_FAILED",
|
|
3611
|
+
...secretFailure(error)
|
|
3520
3612
|
};
|
|
3521
3613
|
}
|
|
3522
3614
|
}
|
|
@@ -3605,4 +3697,4 @@ async function runBuild(input, output, options = {}) {
|
|
|
3605
3697
|
};
|
|
3606
3698
|
}
|
|
3607
3699
|
//#endregion
|
|
3608
|
-
export {
|
|
3700
|
+
export { inspectDefinition as $, 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, exactDefinition 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, definitionDiagnostic as Z, rule as _, render as a, sequence as b, direct as c, match as d, outbound as et, mihomo as f, route as g, reject as h, buildToDirectory as i, secretReader as j, renderSurgeProfile as k, dnsRule as l, proxy as m, defineBuild as n, block as o, policy as p, ProfileDefinitionError as q, runBuild as r, defineConfig as s, checkBuild as t, group as u, ruleSet as v, surge$1 as w, singbox$1 as x, secret as y, surgeProxy as z };
|
package/package.json
CHANGED