proxylang 0.12.0 → 0.13.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 +116 -374
- package/dist/build-B_eJXR4E.js +3619 -0
- package/dist/cli.js +216 -175
- package/dist/index.d.ts +829 -819
- package/dist/index.js +347 -178
- package/package.json +7 -5
- package/dist/profile-build-Cfs0OIt3.js +0 -4008
package/dist/index.js
CHANGED
|
@@ -1,194 +1,363 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "zod";
|
|
1
|
+
import { S as ProfileDefinitionError, T as inspectDefinition, _ as endpointSchema, a as defineBuild, b as nativeRuleSetSchema, c as dnsRulesSchema, d as tunnelSchema, f as created, g as requireKind, h as parsed, l as conditionSchema, m as inspectRecord, n as runBuild, o as secretSources, p as flatten, r as explainProfile, s as defineProfile, t as checkBuild, u as groupTestSchema, v as idSchema, w as exactDefinition, x as nodeSchema, y as matchSchema } from "./build-B_eJXR4E.js";
|
|
3
2
|
import { createHash } from "node:crypto";
|
|
4
|
-
//#region src/
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (new Set(symbols.map((s) => s.nativeName)).size !== symbols.length) error("DUPLICATE_NATIVE_NAME", "names", "节点和外部符号的原生名必须唯一");
|
|
59
|
-
const allIds = new Set(ids);
|
|
60
|
-
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
61
|
-
for (const node of nodes) if (node.via && !allIds.has(node.via)) error("MISSING_REFERENCE", `nodes.${node.id}.via`, "拨号依赖未声明");
|
|
62
|
-
const states = /* @__PURE__ */ new Map();
|
|
63
|
-
const visit = (id) => {
|
|
64
|
-
if (states.get(id) === 1) {
|
|
65
|
-
error("RESOURCE_CYCLE", `nodes.${id}.via`, "内部拨号依赖形成循环");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (states.get(id) === 2) return;
|
|
69
|
-
states.set(id, 1);
|
|
70
|
-
const via = byId.get(id)?.via;
|
|
71
|
-
if (via && byId.has(via)) visit(via);
|
|
72
|
-
states.set(id, 2);
|
|
73
|
-
};
|
|
74
|
-
if (ids.length <= 1e3) for (const id of byId.keys()) visit(id);
|
|
75
|
-
if (diagnostics.length) return failure();
|
|
76
|
-
if (target.engine !== "surge" || target.platform !== "macos" || target.version !== "6.10.0") {
|
|
77
|
-
error("UNKNOWN_TARGET", "target", "节点片段仅支持 Surge macOS 6.10.0");
|
|
78
|
-
return failure();
|
|
79
|
-
}
|
|
80
|
-
const descriptor = targetCatalog.find((t) => t.engine === "surge" && t.version === target.version);
|
|
81
|
-
for (const node of nodes) {
|
|
82
|
-
if (!descriptor.protocols.includes(node.type)) error("PROTOCOL_UNSUPPORTED", `nodes.${node.id}`, "精确目标不支持该节点协议");
|
|
83
|
-
validateProxyOptions(node, {
|
|
84
|
-
id: "nodes",
|
|
85
|
-
program: "nodes",
|
|
86
|
-
engine: "surge",
|
|
87
|
-
platform: "macos",
|
|
88
|
-
version: target.version
|
|
89
|
-
}, diagnostics);
|
|
90
|
-
}
|
|
91
|
-
if (diagnostics.some((d) => d.severity === "error")) return failure();
|
|
92
|
-
const requirements = externals.flatMap((external) => {
|
|
93
|
-
const usedBy = nodes.filter((node) => node.via === external.id).map((node) => node.id);
|
|
94
|
-
return usedBy.length ? [{
|
|
95
|
-
...external,
|
|
96
|
-
usedBy
|
|
97
|
-
}] : [];
|
|
98
|
-
});
|
|
99
|
-
if (requirements.length) diagnostics.push({
|
|
100
|
-
severity: "warning",
|
|
101
|
-
code: "EXTERNAL_REFERENCE_UNVERIFIED",
|
|
102
|
-
path: "externals",
|
|
103
|
-
message: "必须逐设备验证原生符号、include 闭包及完整依赖图;未知动态组须拒绝"
|
|
104
|
-
});
|
|
105
|
-
const compilation = deepFreeze({
|
|
106
|
-
ok: true,
|
|
107
|
-
artifactKind: "proxy-nodes",
|
|
108
|
-
diagnostics,
|
|
109
|
-
bindings,
|
|
110
|
-
requirements
|
|
3
|
+
//#region src/authoring/resources.ts
|
|
4
|
+
const builtin = (builtin) => created({ builtin }, "builtin");
|
|
5
|
+
const outbound = {
|
|
6
|
+
direct: builtin("DIRECT"),
|
|
7
|
+
reject: builtin("REJECT"),
|
|
8
|
+
rejectDrop: builtin("REJECT-DROP"),
|
|
9
|
+
rejectNoDrop: builtin("REJECT-NO-DROP"),
|
|
10
|
+
rejectTinyGif: builtin("REJECT-TINYGIF")
|
|
11
|
+
};
|
|
12
|
+
function defineProxyGroup(input) {
|
|
13
|
+
inspectDefinition(input);
|
|
14
|
+
exactDefinition(input, [
|
|
15
|
+
"id",
|
|
16
|
+
"name",
|
|
17
|
+
"algorithm",
|
|
18
|
+
"members",
|
|
19
|
+
"surge"
|
|
20
|
+
]);
|
|
21
|
+
parsed(idSchema, input.id);
|
|
22
|
+
if (input.surge !== void 0) parsed(groupTestSchema, input.surge);
|
|
23
|
+
if (input.name !== void 0 && typeof input.name !== "string") throw new ProfileDefinitionError("INVALID_FIELD", ["name"]);
|
|
24
|
+
requireKind(input.algorithm, ["algorithm"]);
|
|
25
|
+
const members = flatten(input.members);
|
|
26
|
+
if (!members.length) throw new ProfileDefinitionError("EMPTY_FRAGMENT", ["members"]);
|
|
27
|
+
for (const member of members) requireKind(member, [
|
|
28
|
+
"node",
|
|
29
|
+
"group",
|
|
30
|
+
"tunnel",
|
|
31
|
+
"endpoint",
|
|
32
|
+
"builtin"
|
|
33
|
+
]);
|
|
34
|
+
return created({
|
|
35
|
+
...input,
|
|
36
|
+
type: "proxy-group",
|
|
37
|
+
members
|
|
38
|
+
}, "group");
|
|
39
|
+
}
|
|
40
|
+
function defineRoutes(input) {
|
|
41
|
+
inspectDefinition(input);
|
|
42
|
+
exactDefinition(input, ["when", "to"]);
|
|
43
|
+
requireKind(input.to, [
|
|
44
|
+
"node",
|
|
45
|
+
"group",
|
|
46
|
+
"tunnel",
|
|
47
|
+
"endpoint",
|
|
48
|
+
"builtin"
|
|
49
|
+
]);
|
|
50
|
+
return flatten(input.when).map((when) => {
|
|
51
|
+
requireKind(when, ["condition", "ruleSet"]);
|
|
52
|
+
return created({
|
|
53
|
+
type: "route",
|
|
54
|
+
when,
|
|
55
|
+
to: input.to
|
|
56
|
+
}, "route");
|
|
111
57
|
});
|
|
112
|
-
plans.set(compilation, deepFreeze({
|
|
113
|
-
nodes,
|
|
114
|
-
names: Object.fromEntries(symbols.map((s) => [s.id, s.nativeName]))
|
|
115
|
-
}));
|
|
116
|
-
return compilation;
|
|
117
58
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}));
|
|
126
|
-
return
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/authoring/proxy-builder.ts
|
|
61
|
+
function proxyBuilder(node) {
|
|
62
|
+
requireKind(node, ["node"]);
|
|
63
|
+
const fork = (patch) => proxyBuilder(created({
|
|
64
|
+
...node,
|
|
65
|
+
...patch
|
|
66
|
+
}, "node"));
|
|
67
|
+
return Object.freeze({
|
|
68
|
+
via: (value) => {
|
|
69
|
+
requireKind(value, ["node", "group"]);
|
|
70
|
+
return fork({ via: value });
|
|
71
|
+
},
|
|
72
|
+
name: (text) => {
|
|
73
|
+
if (typeof text !== "string") throw new ProfileDefinitionError("INVALID_FIELD");
|
|
74
|
+
return fork({ name: text });
|
|
75
|
+
},
|
|
76
|
+
tcpFastOpen: (enabled) => {
|
|
77
|
+
if (typeof enabled !== "boolean") throw new ProfileDefinitionError("INVALID_FIELD");
|
|
78
|
+
if (node.type === "hysteria2") throw new ProfileDefinitionError("INVALID_FIELD");
|
|
79
|
+
return fork({ tcpFastOpen: enabled });
|
|
80
|
+
},
|
|
81
|
+
build: () => created({ ...node }, "node")
|
|
130
82
|
});
|
|
131
83
|
}
|
|
132
84
|
//#endregion
|
|
133
|
-
//#region src/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
85
|
+
//#region src/authoring/surge-match.ts
|
|
86
|
+
function condition(value) {
|
|
87
|
+
inspectDefinition(value);
|
|
88
|
+
const fields = value.type === "ruleSet" ? [
|
|
89
|
+
"format",
|
|
90
|
+
"url",
|
|
91
|
+
"builtin",
|
|
92
|
+
"intervalSeconds"
|
|
93
|
+
] : value.type === "all" || value.type === "any" ? ["conditions"] : value.type === "not" ? ["condition"] : value.type === "port" || value.type === "sourcePort" ? ["from", "to"] : ["value"];
|
|
94
|
+
exactDefinition(value, [
|
|
95
|
+
"type",
|
|
96
|
+
"noResolve",
|
|
97
|
+
...fields,
|
|
98
|
+
...[
|
|
99
|
+
"domain",
|
|
100
|
+
"domainSuffix",
|
|
101
|
+
"ruleSet"
|
|
102
|
+
].includes(value.type) ? ["includeSniffed"] : []
|
|
103
|
+
]);
|
|
104
|
+
if (value.includeSniffed !== void 0 && typeof value.includeSniffed !== "boolean") throw new ProfileDefinitionError("INVALID_MATCH_OPTIONS");
|
|
105
|
+
return created(parsed(conditionSchema, value), "condition");
|
|
106
|
+
}
|
|
107
|
+
function atom$1(type) {
|
|
108
|
+
return (value, options) => {
|
|
109
|
+
inspectDefinition(options ?? {});
|
|
110
|
+
exactDefinition(options ?? {}, ["noResolve", ...["domain", "domainSuffix"].includes(type) ? ["includeSniffed"] : []]);
|
|
111
|
+
return condition({
|
|
112
|
+
...options,
|
|
113
|
+
type,
|
|
114
|
+
value
|
|
115
|
+
});
|
|
116
|
+
};
|
|
138
117
|
}
|
|
118
|
+
const surgeMatch = {
|
|
119
|
+
ipAsn: (value, options = {}) => condition({
|
|
120
|
+
type: "ipAsn",
|
|
121
|
+
value,
|
|
122
|
+
...options
|
|
123
|
+
}),
|
|
124
|
+
ipCidr6: (value, options = {}) => atom$1("ipCidr6")(value, options),
|
|
125
|
+
macAddress: (value) => atom$1("macAddress")(value)
|
|
126
|
+
};
|
|
139
127
|
//#endregion
|
|
140
|
-
//#region src/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
128
|
+
//#region src/authoring/constructors.ts
|
|
129
|
+
function dnsRule(pattern, server) {
|
|
130
|
+
const batch = Array.isArray(pattern);
|
|
131
|
+
const result = parsed(dnsRulesSchema, (batch ? pattern : [pattern]).map((p) => ({
|
|
132
|
+
pattern: p,
|
|
133
|
+
server
|
|
134
|
+
}))).map((item) => created(item, "dns"));
|
|
135
|
+
return batch ? Object.freeze(result) : result[0];
|
|
136
|
+
}
|
|
137
|
+
function atom(type, keys) {
|
|
138
|
+
function construct(value, options = {}) {
|
|
139
|
+
inspectDefinition({
|
|
140
|
+
value,
|
|
141
|
+
options
|
|
142
|
+
});
|
|
143
|
+
exactDefinition(options, keys);
|
|
144
|
+
const one = (v) => created(parsed(matchSchema, {
|
|
145
|
+
type,
|
|
146
|
+
value: v,
|
|
147
|
+
...options
|
|
148
|
+
}), "condition");
|
|
149
|
+
return Array.isArray(value) ? Object.freeze(value.map(one)) : one(value);
|
|
150
|
+
}
|
|
151
|
+
return construct;
|
|
152
|
+
}
|
|
153
|
+
function logical(type, fragments) {
|
|
154
|
+
const conditions = flatten(fragments);
|
|
155
|
+
for (const c of conditions) requireKind(c, ["condition", "ruleSet"]);
|
|
156
|
+
if (!conditions.length) throw new ProfileDefinitionError("EMPTY_FRAGMENT");
|
|
157
|
+
return created({
|
|
158
|
+
type,
|
|
159
|
+
conditions
|
|
160
|
+
}, "condition");
|
|
161
|
+
}
|
|
162
|
+
const match = {
|
|
163
|
+
domain: atom("domain", ["includeSniffed"]),
|
|
164
|
+
domainSuffix: atom("domainSuffix", ["includeSniffed"]),
|
|
165
|
+
ipCidr: atom("ipCidr", ["noResolve"]),
|
|
166
|
+
sourceIp: atom("sourceIp", []),
|
|
167
|
+
processName: atom("processName", []),
|
|
168
|
+
port: (from, to = from) => created(parsed(matchSchema, {
|
|
169
|
+
type: "port",
|
|
170
|
+
from,
|
|
171
|
+
to
|
|
172
|
+
}), "condition"),
|
|
173
|
+
sourcePort: (from, to = from) => created(parsed(matchSchema, {
|
|
174
|
+
type: "sourcePort",
|
|
175
|
+
from,
|
|
176
|
+
to
|
|
177
|
+
}), "condition"),
|
|
178
|
+
network: (value) => created(parsed(matchSchema, {
|
|
179
|
+
type: "network",
|
|
180
|
+
value
|
|
181
|
+
}), "condition"),
|
|
182
|
+
all: (...conditions) => logical("all", conditions),
|
|
183
|
+
any: (...conditions) => logical("any", conditions),
|
|
184
|
+
not: (condition) => {
|
|
185
|
+
requireKind(condition, ["condition", "ruleSet"]);
|
|
186
|
+
return created({
|
|
187
|
+
type: "not",
|
|
188
|
+
condition
|
|
189
|
+
}, "condition");
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
function ruleSet(input) {
|
|
193
|
+
inspectRecord(input);
|
|
194
|
+
exactDefinition(input, [
|
|
195
|
+
"id",
|
|
196
|
+
"surge",
|
|
197
|
+
"singBox",
|
|
198
|
+
"mihomo"
|
|
199
|
+
]);
|
|
200
|
+
parsed(idSchema, input.id);
|
|
201
|
+
let count = 0;
|
|
202
|
+
for (const branch of [
|
|
203
|
+
"surge",
|
|
204
|
+
"singBox",
|
|
205
|
+
"mihomo"
|
|
206
|
+
]) {
|
|
207
|
+
if (input[branch] === void 0) continue;
|
|
208
|
+
count++;
|
|
209
|
+
parsed(nativeRuleSetSchema, {
|
|
210
|
+
type: "nativeRuleSet",
|
|
211
|
+
id: input.id,
|
|
212
|
+
engine: branch === "singBox" ? "sing-box" : branch,
|
|
213
|
+
...branch === "surge" ? { format: "rule-set" } : {},
|
|
214
|
+
...input[branch]
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (!count) throw new ProfileDefinitionError("INVALID_FIELD");
|
|
218
|
+
return created({
|
|
219
|
+
...input,
|
|
220
|
+
type: "ruleSetSource"
|
|
221
|
+
}, "ruleSet");
|
|
222
|
+
}
|
|
223
|
+
const group = {
|
|
224
|
+
auto: () => created({ type: "auto" }, "algorithm"),
|
|
225
|
+
select: () => created({ type: "select" }, "algorithm"),
|
|
226
|
+
urltest: (input) => {
|
|
227
|
+
inspectRecord(input);
|
|
148
228
|
exactDefinition(input, [
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
229
|
+
"url",
|
|
230
|
+
"intervalSeconds",
|
|
231
|
+
"toleranceMs"
|
|
152
232
|
]);
|
|
153
|
-
|
|
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;
|
|
233
|
+
let url;
|
|
183
234
|
try {
|
|
184
|
-
|
|
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;
|
|
235
|
+
url = new URL(input.url);
|
|
188
236
|
} catch {
|
|
189
|
-
throw new
|
|
237
|
+
throw new ProfileDefinitionError("INVALID_FIELD");
|
|
190
238
|
}
|
|
239
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.hash || !Number.isInteger(input.intervalSeconds ?? 180) || (input.intervalSeconds ?? 180) < 1 || (input.intervalSeconds ?? 180) > 86400 || !Number.isInteger(input.toleranceMs ?? 50) || (input.toleranceMs ?? 50) < 0 || (input.toleranceMs ?? 50) > 6e4) throw new ProfileDefinitionError("INVALID_FIELD");
|
|
240
|
+
return created({
|
|
241
|
+
...input,
|
|
242
|
+
type: "urltest"
|
|
243
|
+
}, "algorithm");
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
function nodeConstructor(type) {
|
|
247
|
+
return (input) => {
|
|
248
|
+
inspectRecord(input);
|
|
249
|
+
for (const key of [
|
|
250
|
+
"password",
|
|
251
|
+
"username",
|
|
252
|
+
"uuid"
|
|
253
|
+
]) if (key in input) requireKind(input[key], ["secret"]);
|
|
254
|
+
const { name, via, ...rest } = input;
|
|
255
|
+
if (name !== void 0 && typeof name !== "string") throw new ProfileDefinitionError("INVALID_FIELD", ["name"]);
|
|
256
|
+
if (via !== void 0) requireKind(via, ["node", "group"]);
|
|
257
|
+
parsed(nodeSchema, {
|
|
258
|
+
...rest,
|
|
259
|
+
type,
|
|
260
|
+
...via ? { via: via.id } : {}
|
|
261
|
+
});
|
|
262
|
+
return created({
|
|
263
|
+
...input,
|
|
264
|
+
type
|
|
265
|
+
}, "node");
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const proxy = {
|
|
269
|
+
builder: proxyBuilder,
|
|
270
|
+
http: nodeConstructor("http"),
|
|
271
|
+
trojan: nodeConstructor("trojan"),
|
|
272
|
+
anytls: nodeConstructor("anytls"),
|
|
273
|
+
hysteria2: nodeConstructor("hysteria2"),
|
|
274
|
+
shadowsocks: nodeConstructor("shadowsocks"),
|
|
275
|
+
vmess: nodeConstructor("vmess"),
|
|
276
|
+
vless: nodeConstructor("vless")
|
|
277
|
+
};
|
|
278
|
+
function tunnel(type) {
|
|
279
|
+
return (input) => {
|
|
280
|
+
inspectRecord(input);
|
|
281
|
+
const { name, ...rest } = input;
|
|
282
|
+
if (name !== void 0 && typeof name !== "string") throw new ProfileDefinitionError("INVALID_FIELD", ["name"]);
|
|
283
|
+
parsed(tunnelSchema, {
|
|
284
|
+
...rest,
|
|
285
|
+
type
|
|
286
|
+
});
|
|
287
|
+
return created({
|
|
288
|
+
...input,
|
|
289
|
+
type
|
|
290
|
+
}, "tunnel");
|
|
191
291
|
};
|
|
192
292
|
}
|
|
293
|
+
const surge = {
|
|
294
|
+
match: surgeMatch,
|
|
295
|
+
ruleSets: {
|
|
296
|
+
lan: created({
|
|
297
|
+
type: "ruleSet",
|
|
298
|
+
id: "surge:lan",
|
|
299
|
+
format: "rule-set",
|
|
300
|
+
builtin: "LAN"
|
|
301
|
+
}, "ruleSet"),
|
|
302
|
+
system: created({
|
|
303
|
+
type: "ruleSet",
|
|
304
|
+
id: "surge:system",
|
|
305
|
+
format: "rule-set",
|
|
306
|
+
builtin: "SYSTEM"
|
|
307
|
+
}, "ruleSet")
|
|
308
|
+
},
|
|
309
|
+
smart: () => created({ type: "surge-smart" }, "algorithm"),
|
|
310
|
+
tailscale: tunnel("tailscale"),
|
|
311
|
+
wireguard: tunnel("wireguard")
|
|
312
|
+
};
|
|
313
|
+
const singbox = { tailscale: (input) => {
|
|
314
|
+
inspectRecord(input);
|
|
315
|
+
const { name, ...rest } = input;
|
|
316
|
+
if (name !== void 0 && typeof name !== "string") throw new ProfileDefinitionError("INVALID_FIELD", ["name"]);
|
|
317
|
+
parsed(endpointSchema, {
|
|
318
|
+
...rest,
|
|
319
|
+
type: "sing-box-tailscale"
|
|
320
|
+
});
|
|
321
|
+
return created({
|
|
322
|
+
...input,
|
|
323
|
+
type: "sing-box-tailscale"
|
|
324
|
+
}, "endpoint");
|
|
325
|
+
} };
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/authoring/secret-inputs.ts
|
|
328
|
+
function defineSecrets(input) {
|
|
329
|
+
inspectRecord(input);
|
|
330
|
+
exactDefinition(input, Object.keys(input));
|
|
331
|
+
const refs = {};
|
|
332
|
+
const sources = /* @__PURE__ */ new Map();
|
|
333
|
+
for (const [name, source] of Object.entries(input)) {
|
|
334
|
+
if (!/^[A-Z][A-Z0-9_]*$/.test(name)) throw new ProfileDefinitionError("INVALID_FIELD");
|
|
335
|
+
exactDefinition(source, [
|
|
336
|
+
"env",
|
|
337
|
+
"value",
|
|
338
|
+
"validation"
|
|
339
|
+
]);
|
|
340
|
+
if (source.env === void 0 === (source.value === void 0) || source.env !== void 0 && (typeof source.env !== "string" || !source.env) || source.value !== void 0 && typeof source.value !== "string" || source.validation !== void 0 && typeof source.validation !== "string") throw new ProfileDefinitionError("INVALID_FIELD", [name]);
|
|
341
|
+
const ref = created({
|
|
342
|
+
type: "env",
|
|
343
|
+
name
|
|
344
|
+
}, "secret");
|
|
345
|
+
Object.defineProperty(refs, name, {
|
|
346
|
+
value: ref,
|
|
347
|
+
enumerable: true
|
|
348
|
+
});
|
|
349
|
+
sources.set(ref, Object.freeze({ ...source }));
|
|
350
|
+
}
|
|
351
|
+
const collection = created(refs, "secrets");
|
|
352
|
+
secretSources.set(collection, sources);
|
|
353
|
+
return collection;
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region src/authoring/proxy-id.ts
|
|
357
|
+
/** Stable identity independent of engine and mutable metadata. */
|
|
358
|
+
function proxyId(namespace, name) {
|
|
359
|
+
if (typeof namespace !== "string" || !namespace.length || typeof name !== "string" || !name.length) throw new ProfileDefinitionError("INVALID_FIELD");
|
|
360
|
+
return `node-${createHash("sha256").update(JSON.stringify([namespace, name])).digest("hex").slice(0, 16)}`;
|
|
361
|
+
}
|
|
193
362
|
//#endregion
|
|
194
|
-
export { ProfileDefinitionError,
|
|
363
|
+
export { ProfileDefinitionError, checkBuild, defineBuild, defineProfile, defineProxyGroup, defineRoutes, defineSecrets, dnsRule, explainProfile, group, match, outbound, proxy, proxyId, ruleSet, runBuild, singbox, surge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proxylang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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": {
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
|
-
"import": "./dist/index.js"
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.js"
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
"publishConfig": {
|
|
@@ -32,13 +33,14 @@
|
|
|
32
33
|
"build": "vp pack",
|
|
33
34
|
"typecheck": "vp exec tsc --noEmit -p tsconfig.check.json",
|
|
34
35
|
"test": "vp test run",
|
|
35
|
-
"test:native": "PROXYLANG_NATIVE_CHECK=1 vp test run test/native
|
|
36
|
+
"test:native": "PROXYLANG_NATIVE_CHECK=1 vp test run test/native/",
|
|
36
37
|
"check": "vp pack && vp check && vp run typecheck && vp test run",
|
|
37
38
|
"docs:check": "concord check --fresh",
|
|
38
39
|
"docs:gaps": "concord trace gaps --fresh",
|
|
39
40
|
"example:check": "cd examples/home && vp exec node ../../dist/cli.js check",
|
|
40
41
|
"example:build": "cd examples/home && vp exec node ../../dist/cli.js build",
|
|
41
|
-
"test:package": "vp pack && vp exec node scripts/verify-package.mjs"
|
|
42
|
+
"test:package": "vp pack && vp exec node scripts/verify-package.mjs",
|
|
43
|
+
"test:golden:update": "vp pack && vp exec tsx scripts/update-golden.mts"
|
|
42
44
|
},
|
|
43
45
|
"dependencies": {
|
|
44
46
|
"ipaddr.js": "2.5.0",
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.3.0"
|
|
56
58
|
},
|
|
57
59
|
"engines": {
|
|
58
|
-
"node": ">=24.11.0 <25"
|
|
60
|
+
"node": ">=24.11.0 <25 || >=26.0.0 <27"
|
|
59
61
|
},
|
|
60
62
|
"packageManager": "npm@11.12.1"
|
|
61
63
|
}
|