sing-box-kit 0.1.1 → 0.1.3

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/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isIP } from "node:net";
2
2
  import Ajv2020 from "ajv/dist/2020.js";
3
+ import { createPrivateKey, createPublicKey } from "node:crypto";
3
4
  // schema/sing-box.json
4
5
  var sing_box_default = {
5
6
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -8769,26 +8770,23 @@ function checkSchema(validate, value, path) {
8769
8770
  function validateConfig(value) {
8770
8771
  return checkSchema(validateOfficial, value, "");
8771
8772
  }
8772
- const definitions = sing_box_default.$defs;
8773
+ const definitions$1 = sing_box_default.$defs;
8774
+ const rootProperties = sing_box_default.properties;
8773
8775
  function definition(name) {
8774
- return definitions[name] ?? fail(name, "unknown schema definition");
8776
+ return definitions$1[name] ?? fail(name, "unknown schema definition");
8775
8777
  }
8776
- function variant(name, type) {
8777
- const schema = definition(name);
8778
- return (schema.oneOf ?? schema.anyOf)?.find((option) => option.properties?.type?.const === type || option.properties?.type?.enum?.includes(type)) ?? fail(name, "unknown schema variant");
8778
+ function definitionName(schema) {
8779
+ return schema.$ref?.slice(8);
8780
+ }
8781
+ function schemaBranches(schema) {
8782
+ const name = definitionName(schema);
8783
+ if (name) return schemaBranches(definition(name));
8784
+ return (schema.oneOf ?? schema.anyOf)?.flatMap(schemaBranches) ?? [schema];
8779
8785
  }
8780
8786
  function compileSchema(schema) {
8781
8787
  const rewriteReferences = (key, value) => key === "$ref" && typeof value === "string" && value.startsWith("#/") ? sing_box_default.$id + value : value;
8782
8788
  return ajv.compile(JSON.parse(JSON.stringify(schema, rewriteReferences)));
8783
8789
  }
8784
- function objectValidator(properties, required = []) {
8785
- return compileSchema({
8786
- type: "object",
8787
- properties,
8788
- required,
8789
- additionalProperties: false
8790
- });
8791
- }
8792
8790
  function pickSchema(properties, keys) {
8793
8791
  return Object.fromEntries(keys.map((key) => [key, properties[key] ?? fail(key, "field missing from official schema")]));
8794
8792
  }
@@ -8866,14 +8864,7 @@ const tlsProfileValidators = {
8866
8864
  handshake: {
8867
8865
  type: "object",
8868
8866
  additionalProperties: false,
8869
- properties: pickSchema(definition("InboundRealityHandshakeOptions").properties, [
8870
- "server",
8871
- "server_port",
8872
- "connect_timeout",
8873
- "detour",
8874
- "domain_resolver",
8875
- "netns"
8876
- ]),
8867
+ properties: definition("InboundRealityHandshakeOptions").properties,
8877
8868
  required: ["server", "server_port"]
8878
8869
  }
8879
8870
  },
@@ -8925,7 +8916,317 @@ const tlsProfileValidators = {
8925
8916
  })
8926
8917
  }
8927
8918
  };
8919
+ // src/input-schema.ts
8920
+ const targetSchema = {
8921
+ inbounds: "Inbound",
8922
+ outbounds: "Outbound",
8923
+ endpoints: "Endpoint",
8924
+ services: "Service",
8925
+ http_clients: "HTTPClient",
8926
+ "dns.servers": "DNSServer",
8927
+ "route.rule_set": "RuleSet",
8928
+ certificate_providers: "CertificateProvider",
8929
+ network_namespaces: "NetworkNamespace"
8930
+ };
8931
+ const tagReferences = {
8932
+ inbound: {
8933
+ role: "inbound",
8934
+ type: "InboundRef"
8935
+ },
8936
+ listen_detour: {
8937
+ role: "listen-detour",
8938
+ type: "ListenDetour"
8939
+ },
8940
+ outbound: {
8941
+ role: "egress",
8942
+ type: "Egress"
8943
+ },
8944
+ dial_detour: {
8945
+ role: "dial-detour",
8946
+ type: "Egress"
8947
+ },
8948
+ network_namespace: {
8949
+ role: "netns",
8950
+ type: "Namespace",
8951
+ allowString: true
8952
+ },
8953
+ dns_server: {
8954
+ role: "dns-server",
8955
+ type: "DnsServer"
8956
+ },
8957
+ rule_set: {
8958
+ role: "rule-set",
8959
+ type: "RuleSetRef"
8960
+ },
8961
+ certificate_provider: {
8962
+ role: "certificate-provider",
8963
+ type: "CertificateProvider"
8964
+ },
8965
+ http_client: {
8966
+ role: "http-client",
8967
+ type: "HttpClientValue"
8968
+ },
8969
+ tagged_http_client: {
8970
+ role: "http-client",
8971
+ type: "TaggedHttpClient"
8972
+ },
8973
+ tailscale_endpoint: {
8974
+ role: "tailscale-endpoint",
8975
+ type: "TailscaleEndpoint"
8976
+ },
8977
+ openconnect_endpoint: {
8978
+ role: "openconnect-endpoint",
8979
+ type: "OpenConnectEndpoint"
8980
+ },
8981
+ openvpn_client_endpoint: {
8982
+ role: "openvpn-client-endpoint",
8983
+ type: "OpenVpnClientEndpoint"
8984
+ },
8985
+ resolved_service: {
8986
+ role: "resolved-service",
8987
+ type: "ResolvedService"
8988
+ },
8989
+ ssm: {
8990
+ role: "ssm",
8991
+ type: "SsmInbound"
8992
+ },
8993
+ preferred_routes: {
8994
+ role: "preferred-routes",
8995
+ type: "PreferredRoutes"
8996
+ },
8997
+ preferred_domain: {
8998
+ role: "preferred-domain",
8999
+ type: "PreferredDomain"
9000
+ }
9001
+ };
9002
+ function tagReference(name) {
9003
+ if (!Object.hasOwn(tagReferences, name)) fail(name, "unknown tag reference");
9004
+ return tagReferences[name];
9005
+ }
9006
+ function tagged(schema, reference) {
9007
+ return {
9008
+ ...schema,
9009
+ "x-tag-reference": reference
9010
+ };
9011
+ }
9012
+ function inputProperty(key, schema) {
9013
+ if (key !== "detour") return schema;
9014
+ const reference = schema["x-tag-reference"];
9015
+ if (reference === "outbound") return tagged(schema, "dial_detour");
9016
+ if (reference === "inbound") return tagged(schema, "listen_detour");
9017
+ return schema;
9018
+ }
9019
+ function oneOrManyReference(schema, reference) {
9020
+ return {
9021
+ ...schema,
9022
+ anyOf: schema.anyOf.map((option) => option.items ? {
9023
+ ...option,
9024
+ items: tagged(option.items, reference)
9025
+ } : tagged(option, reference))
9026
+ };
9027
+ }
9028
+ function projectObject(properties, required = []) {
9029
+ return {
9030
+ type: "object",
9031
+ properties,
9032
+ required,
9033
+ additionalProperties: false
9034
+ };
9035
+ }
9036
+ function supplementFactory(target, kind, properties) {
9037
+ if (target === "dns.servers" && properties.endpoint) {
9038
+ const references = {
9039
+ tailscale: "tailscale_endpoint",
9040
+ openconnect: "openconnect_endpoint",
9041
+ openvpn: "openvpn_client_endpoint"
9042
+ };
9043
+ if (Object.hasOwn(references, kind)) properties.endpoint = tagged(properties.endpoint, references[kind]);
9044
+ }
9045
+ if (target === "dns.servers" && kind === "resolved") properties.service = tagged(properties.service, "resolved_service");
9046
+ if (target === "certificate_providers" && kind === "tailscale") properties.endpoint = tagged(properties.endpoint, "tailscale_endpoint");
9047
+ if (target === "services" && kind === "derp") properties.verify_client_endpoint = oneOrManyReference(properties.verify_client_endpoint, "tailscale_endpoint");
9048
+ if (target === "services" && kind === "ssm-api") properties.servers = {
9049
+ ...properties.servers,
9050
+ additionalProperties: tagged({ type: "string" }, "ssm")
9051
+ };
9052
+ }
9053
+ const definitions = /* @__PURE__ */ new Map();
9054
+ function inputDefinition(name) {
9055
+ const cached = definitions.get(name);
9056
+ if (cached) return cached;
9057
+ let schema = definition(name);
9058
+ if (name === "RouteOptions") schema = {
9059
+ ...schema,
9060
+ properties: {
9061
+ ...schema.properties,
9062
+ default_http_client: tagged(schema.properties.default_http_client, "tagged_http_client")
9063
+ }
9064
+ };
9065
+ if (name === "CertificateProviderReference") {
9066
+ const [tag, inline] = schema.anyOf;
9067
+ schema = {
9068
+ ...schema,
9069
+ anyOf: [tag, {
9070
+ ...inline,
9071
+ oneOf: inline.oneOf.map((branch) => {
9072
+ if (branch.properties?.type?.const !== "tailscale") return branch;
9073
+ const properties = { ...branch.properties };
9074
+ supplementFactory("certificate_providers", "tailscale", properties);
9075
+ return {
9076
+ ...branch,
9077
+ properties
9078
+ };
9079
+ })
9080
+ }]
9081
+ };
9082
+ }
9083
+ definitions.set(name, schema);
9084
+ return schema;
9085
+ }
9086
+ const rootSettings = Object.fromEntries(Object.entries(rootProperties).filter(([key]) => !Object.hasOwn(targetSchema, key) && key !== "route" && key !== "dns"));
9087
+ const sectionSettings = {
9088
+ route: projectObject(Object.fromEntries(Object.entries(inputDefinition("RouteOptions").properties).filter(([key]) => key !== "rules" && key !== "rule_set"))),
9089
+ dns: projectObject(Object.fromEntries(Object.entries(definition("DNS").properties).filter(([key]) => key !== "rules" && key !== "servers")))
9090
+ };
9091
+ const dialKeys = new Set(Object.keys(definition("DialerOptions").properties));
9092
+ const listenKeys = /* @__PURE__ */ new Set([
9093
+ "listen",
9094
+ "listen_port",
9095
+ "udp_timeout",
9096
+ "domain_resolver",
9097
+ "bind_interface",
9098
+ "routing_mark",
9099
+ "reuse_addr",
9100
+ "netns",
9101
+ "disable_tcp_keep_alive",
9102
+ "tcp_keep_alive",
9103
+ "tcp_keep_alive_interval",
9104
+ "tcp_fast_open",
9105
+ "tcp_multi_path",
9106
+ "udp_fragment",
9107
+ "detour"
9108
+ ]);
9109
+ const requiredOptions = {
9110
+ inbounds: {
9111
+ shadowsocks: ["method"],
9112
+ vless: ["users"]
9113
+ },
9114
+ outbounds: {
9115
+ vless: [
9116
+ "server",
9117
+ "server_port",
9118
+ "uuid"
9119
+ ],
9120
+ selector: ["outbounds"],
9121
+ urltest: ["outbounds"]
9122
+ },
9123
+ endpoints: { wireguard: ["address", "private_key"] },
9124
+ services: { "ssm-api": ["servers"] },
9125
+ "dns.servers": {
9126
+ tcp: ["server"],
9127
+ udp: ["server"],
9128
+ tls: ["server"],
9129
+ https: ["server"],
9130
+ tailscale: ["endpoint"],
9131
+ openconnect: ["endpoint"],
9132
+ openvpn: ["endpoint"],
9133
+ resolved: ["service"]
9134
+ },
9135
+ "route.rule_set": {
9136
+ inline: ["rules"],
9137
+ local: ["path"],
9138
+ remote: ["url"]
9139
+ },
9140
+ certificate_providers: { tailscale: ["endpoint"] },
9141
+ network_namespaces: { default: ["path"] }
9142
+ };
9143
+ function factoryCatalog(target) {
9144
+ const kinds = /* @__PURE__ */ new Map();
9145
+ for (const schema of schemaBranches(definition(targetSchema[target]))) {
9146
+ const type = schema.properties?.type;
9147
+ const kind = type?.const ?? type?.enum?.[0] ?? "http-client";
9148
+ if (typeof kind !== "string") fail(target, "expected a resource kind in the schema");
9149
+ const properties = Object.fromEntries(Object.entries(schema.properties ?? {}).map(([key, value]) => [key, inputProperty(key, value)]));
9150
+ supplementFactory(target, kind, properties);
9151
+ const listens = properties.listen !== void 0 || target === "inbounds" && kind === "tun";
9152
+ const options = {};
9153
+ const listen = {};
9154
+ const dial = {};
9155
+ for (const [key, value] of Object.entries(properties)) {
9156
+ if (key === "type" || key === "tls") continue;
9157
+ if (listens && listenKeys.has(key)) {
9158
+ if (key === "listen") continue;
9159
+ listen[key === "listen_port" ? "port" : key] = value;
9160
+ } else if (!listens && dialKeys.has(key)) {
9161
+ if (key === "detour" && target === "outbounds" && kind === "direct") continue;
9162
+ dial[key] = value;
9163
+ } else options[key] = value;
9164
+ }
9165
+ const required = [...schema.required ?? [], ...requiredOptions[target]?.[kind] ?? []];
9166
+ if (target !== "services" && target !== "http_clients") required.push("tag");
9167
+ const branch = {
9168
+ output: {
9169
+ ...schema,
9170
+ properties
9171
+ },
9172
+ options: projectObject(options, [...new Set(required)].filter((key) => Object.hasOwn(options, key))),
9173
+ listen: listens ? projectObject(listen) : void 0,
9174
+ dial: Object.keys(dial).length ? projectObject(dial) : void 0,
9175
+ tls: properties.tls
9176
+ };
9177
+ const entries = kinds.get(kind) ?? [];
9178
+ entries.push(branch);
9179
+ kinds.set(kind, entries);
9180
+ }
9181
+ return kinds;
9182
+ }
9183
+ function factoryName(kind) {
9184
+ return kind.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
9185
+ }
9186
+ function schemaShape(schema) {
9187
+ const name = definitionName(schema);
9188
+ return name ? inputDefinition(name) : schema;
9189
+ }
9190
+ const ruleMatchSchema = {
9191
+ route: matchSchema("NestedRule", "preferred_routes"),
9192
+ dns: matchSchema("NestedDNSRule", "preferred_domain")
9193
+ };
9194
+ function matchSchema(name, preferred) {
9195
+ const { type: _type, ...properties } = definition(name).oneOf[0].properties;
9196
+ properties.preferred_by = oneOrManyReference(properties.preferred_by, preferred);
9197
+ return projectObject(properties);
9198
+ }
9199
+ function ruleActionSchemas(scope) {
9200
+ const actions = schemaBranches(definition(scope === "route" ? "RuleAction" : "DNSRuleAction"));
9201
+ return new Map(actions.map((branch) => {
9202
+ const properties = { ...branch.properties };
9203
+ const action = properties.action.const;
9204
+ const required = /* @__PURE__ */ new Set(["action", ...branch.required ?? []]);
9205
+ if (action === "route" && scope === "route") required.add("outbound");
9206
+ if (scope === "dns" && (action === "route" || action === "evaluate")) required.add("server");
9207
+ if (action === "reject" && scope === "dns") properties.method = {
9208
+ type: "string",
9209
+ enum: ["default", "drop"]
9210
+ };
9211
+ return [action, projectObject(properties, [...required])];
9212
+ }));
9213
+ }
8928
9214
  // src/resource.ts
9215
+ const preferredRouteEndpoints = [
9216
+ "tailscale",
9217
+ "wireguard",
9218
+ "openconnect",
9219
+ "openvpn-client"
9220
+ ];
9221
+ const preferredDnsKinds = [
9222
+ "hosts",
9223
+ "local",
9224
+ "mdns",
9225
+ "tailscale",
9226
+ "openconnect",
9227
+ "openvpn",
9228
+ "resolved"
9229
+ ];
8929
9230
  const resources = /* @__PURE__ */ new WeakMap();
8930
9231
  const identities = /* @__PURE__ */ new WeakSet();
8931
9232
  /** Internal constructor. Factory methods supply immutable data. */
@@ -8958,7 +9259,7 @@ function copy(value, path, immutable, ancestors) {
8958
9259
  if (value === null || typeof value !== "object") return value;
8959
9260
  if (identities.has(value)) {
8960
9261
  if (immutable) return value;
8961
- fail(path, "unexpected Kit value in JSON fields");
9262
+ fail(path, "unexpected SBKit value in JSON fields");
8962
9263
  }
8963
9264
  if (ancestors.has(value)) fail(path, "cyclic configuration object");
8964
9265
  ancestors.add(value);
@@ -8972,82 +9273,106 @@ function snapshot(value, path) {
8972
9273
  function copyJson(value, path) {
8973
9274
  return copy(value, path, false, /* @__PURE__ */ new Set());
8974
9275
  }
8975
- const ref = (role) => (value, path, resolve) => resolve(value, role, path);
8976
- const arrayOrOne = (expand) => (value, path, resolve) => Array.isArray(value) ? Array.from(value, (item, index) => expand(item, `${path}[${index}]`, resolve)) : expand(value, path, resolve);
8977
- function expandFields(fields, expansions, path, resolve) {
8978
- return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== void 0).map(([key, value]) => {
8979
- const fieldPath = keyPath(path, key);
8980
- const expand = Object.hasOwn(expansions, key) ? expansions[key] : void 0;
8981
- return [key, expand ? expand(value, fieldPath, resolve) : copyJson(value, fieldPath)];
8982
- }));
8983
- }
8984
9276
  // src/settings.ts
8985
9277
  const previewReference = (value, role, path) => {
8986
9278
  if (!resourceData(value)) fail(path, `expected a typed ${role} reference`);
8987
9279
  return "reference";
8988
9280
  };
8989
- const expandResolver = (value, path, resolve) => {
8990
- if (resourceData(value) || typeof value !== "object" || value === null) return resolve(value, "dns-server", path);
8991
- const options = record(value, path);
8992
- if (options.server === void 0) fail(`${path}.server`, "required field");
8993
- return expandFields(options, { server: ref("dns-server") }, path, resolve);
8994
- };
8995
- const expandNamespace = (value, path, resolve) => typeof value === "string" ? value : resolve(value, "netns", path);
8996
- const listenReferences = {
8997
- netns: expandNamespace,
8998
- detour: ref("listen-detour")
8999
- };
9000
- const dialReferences = {
9001
- netns: expandNamespace,
9002
- detour: ref("dial-detour"),
9003
- domain_resolver: expandResolver
9004
- };
9005
9281
  function checkDial(fields, path) {
9006
9282
  const timeout = durationNanoseconds(fields.connect_timeout, `${path}.connect_timeout`);
9007
9283
  if (fields.detour === void 0) return;
9008
9284
  if (timeout !== 0) fail(`${path}.connect_timeout`, "non-zero timeout with detour");
9009
9285
  if (fields.netns !== void 0 && fields.netns !== "") fail(`${path}.netns`, "namespace with detour");
9010
9286
  }
9011
- const commonDialKeys = [
9012
- "connect_timeout",
9013
- "domain_resolver",
9014
- "netns"
9287
+ const discriminators = [
9288
+ "type",
9289
+ "version",
9290
+ "provider"
9015
9291
  ];
9016
- function dialFields(input, path, detour) {
9017
- const fields = fieldsFrom(input, path, detour ? [...commonDialKeys, "detour"] : commonDialKeys);
9018
- checkDial(fields, path);
9019
- return fields;
9292
+ function matchesDiscriminators(schema, fields) {
9293
+ return discriminators.every((key) => {
9294
+ const property = schema.properties?.[key];
9295
+ if (property?.const === void 0 && !property?.enum) return true;
9296
+ const value = fields[key];
9297
+ if (value === void 0) return !schema.required?.includes(key);
9298
+ return property.const === value || property.enum?.includes(value) === true;
9299
+ });
9020
9300
  }
9021
- function listenFields(address, input, path, detour) {
9022
- const { port, ...options } = fieldsFrom(input, path, detour ? [
9023
- "port",
9024
- "netns",
9025
- "detour"
9026
- ] : ["port", "netns"], ["port"]);
9027
- if (typeof address !== "string") fail(`${path}.listen`, "expected a string");
9028
- return {
9029
- listen: address,
9030
- listen_port: port,
9031
- ...options
9032
- };
9301
+ function matchesShape(input, value) {
9302
+ const schema = schemaShape(input);
9303
+ const alternatives = schema.oneOf ?? schema.anyOf;
9304
+ if (alternatives) return alternatives.some((option) => matchesShape(option, value));
9305
+ if (schema.const !== void 0) return value === schema.const;
9306
+ if (schema.enum) return schema.enum.includes(value);
9307
+ if (resourceData(value)) return schema["x-tag-reference"] !== void 0;
9308
+ if (schema.type === "array") return Array.isArray(value);
9309
+ if (schema.type === "object") return value !== null && typeof value === "object" && !Array.isArray(value) && matchesDiscriminators(schema, value);
9310
+ if (schema.type === "integer") return typeof value === "number";
9311
+ return schema.type === void 0 || typeof value === schema.type;
9312
+ }
9313
+ /** Expand annotated tags anywhere in a schema-shaped input. Ajv checks the resulting JSON. */
9314
+ function expandInput(input, value, path, resolve) {
9315
+ if (definitionName(input) === "HTTPClientReference") {
9316
+ const client = resourceData(value);
9317
+ if (client?.target === "http_clients" && client.fields.tag === void 0) return expandInput(definition("HTTPClient"), client.fields, path, resolve);
9318
+ }
9319
+ const schema = schemaShape(input);
9320
+ const annotation = schema["x-tag-reference"];
9321
+ if (annotation !== void 0) {
9322
+ const reference = tagReference(annotation);
9323
+ if ("allowString" in reference && typeof value === "string") return value;
9324
+ return resolve(value, reference.role, path);
9325
+ }
9326
+ const alternatives = schema.oneOf ?? schema.anyOf;
9327
+ if (alternatives) {
9328
+ const option = alternatives.find((branch) => matchesShape(branch, value));
9329
+ return option ? expandInput(option, value, path, resolve) : copyJson(value, path);
9330
+ }
9331
+ if (schema.items && Array.isArray(value)) {
9332
+ const items = schema.items;
9333
+ return Array.from(value, (item, index) => expandInput(items, item, `${path}[${index}]`, resolve));
9334
+ }
9335
+ if (schema.type === "object" && value !== null && typeof value === "object" && !Array.isArray(value)) {
9336
+ const fields = record(value, path);
9337
+ const detour = schema.properties?.detour?.["x-tag-reference"];
9338
+ if (detour === "dial_detour" || detour === "outbound") checkDial(fields, path);
9339
+ const additional = typeof schema.additionalProperties === "object" ? schema.additionalProperties : {};
9340
+ return Object.fromEntries(Object.entries(fields).filter(([, item]) => item !== void 0).map(([key, item]) => {
9341
+ return [key, expandInput(inputProperty(key, schema.properties && Object.hasOwn(schema.properties, key) ? schema.properties[key] : additional), item, keyPath(path, key), resolve)];
9342
+ }));
9343
+ }
9344
+ return copyJson(value, path);
9345
+ }
9346
+ function listenFields(address, input, path, schema) {
9347
+ const { port, ...options } = fieldsFrom(input, path, Object.keys(schema.properties));
9348
+ if (address !== void 0) {
9349
+ if (!Object.hasOwn(schema.properties, "port")) fail(`${path}.listen`, "unexpected field");
9350
+ if (typeof address !== "string") fail(`${path}.listen`, "expected a string");
9351
+ options.listen = address;
9352
+ }
9353
+ if (port !== void 0) options.listen_port = port;
9354
+ return options;
9033
9355
  }
9034
- const expandReality = (value, path, resolve) => expandFields(record(value, path), { handshake: (handshake, path, resolve) => expandFields(record(handshake, path), dialReferences, path, resolve) }, path, resolve);
9035
- const expandTls = (value, path, resolve) => expandFields(record(value, path), {
9036
- certificate_provider: ref("certificate-provider"),
9037
- reality: expandReality
9038
- }, path, resolve);
9039
- function tlsFields(input, path, mode) {
9356
+ function checkTlsAlpn(kind, options, path) {
9357
+ if (kind === "naive" && options.alpn !== void 0) fail(`${path}.alpn`, "ALPN cannot be configured for Naive");
9358
+ }
9359
+ function tlsFields(input, path, schema, mode, kind) {
9040
9360
  const profile = record(input, path);
9361
+ checkTlsAlpn(kind, profile, path);
9362
+ const enabled = Object.hasOwn(schemaShape(schema).properties ?? {}, "enabled");
9363
+ if (!Object.hasOwn(profile, "side")) return { tls: enabled && profile.enabled === void 0 ? {
9364
+ ...profile,
9365
+ enabled: true
9366
+ } : profile };
9367
+ if (!mode) fail(`${path}.side`, "unsupported TLS profile");
9041
9368
  const server = mode === "server" || mode === "server-reality";
9042
9369
  const isReality = profile.reality !== void 0;
9043
9370
  if (isReality && !mode.endsWith("-reality")) fail(`${path}.reality`, "unsupported TLS profile");
9044
- checkSchema(server ? isReality ? tlsProfileValidators.server.reality : profile.certificate_provider === void 0 ? tlsProfileValidators.server.files : tlsProfileValidators.server.provider : isReality ? tlsProfileValidators.client.reality : tlsProfileValidators.client.regular, expandTls(profile, path, previewReference), path);
9371
+ checkSchema(server ? isReality ? tlsProfileValidators.server.reality : profile.certificate_provider === void 0 ? tlsProfileValidators.server.files : tlsProfileValidators.server.provider : isReality ? tlsProfileValidators.client.reality : tlsProfileValidators.client.regular, expandInput(schema, profile, path, previewReference), path);
9045
9372
  const { side: _side, ...fields } = profile;
9046
9373
  if (isReality) {
9047
- const reality = record(profile.reality, `${path}.reality`);
9048
- if (server) checkDial(record(reality.handshake, `${path}.reality.handshake`), `${path}.reality.handshake`);
9049
9374
  fields.reality = {
9050
- ...reality,
9375
+ ...record(profile.reality, `${path}.reality`),
9051
9376
  enabled: true
9052
9377
  };
9053
9378
  if (!server) fields.utls = { enabled: true };
@@ -9057,40 +9382,22 @@ function tlsFields(input, path, mode) {
9057
9382
  enabled: true
9058
9383
  } };
9059
9384
  }
9060
- const httpClientObject = compileSchema(definition("HTTPClientReference").anyOf[1]);
9061
- const expandHttpClient = (value, path, resolve) => {
9062
- const data = resourceData(value);
9063
- if (data) {
9064
- if (data.target === "http_clients" && data.fields.tag === void 0) return expandFields(data.fields, data.references ?? {}, path, resolve);
9065
- return resolve(value, "http-client", path);
9066
- }
9067
- const fields = record(value, path);
9068
- if (Object.hasOwn(fields, "tag")) fail(`${path}.tag`, "unexpected field");
9069
- checkDial(fields, path);
9070
- const output = expandFields(fields, dialReferences, path, resolve);
9071
- return checkSchema(httpClientObject, output, path);
9072
- };
9073
- const expandDashboard = (value, path, resolve) => typeof value === "string" || typeof value === "boolean" ? value : expandFields(record(value, path), { http_client: expandHttpClient }, path, resolve);
9074
- const expandSsmServers = (value, path, resolve) => {
9075
- const servers = Object.entries(record(value, path));
9385
+ function checkSsmServers(value, path) {
9386
+ const servers = Object.keys(record(value, path));
9076
9387
  if (servers.length === 0) fail(path, "expected at least one SSM server");
9077
- return Object.fromEntries(servers.map(([pattern, inbound]) => {
9078
- const fieldPath = `${path}[${JSON.stringify(pattern)}]`;
9079
- if (!pattern.startsWith("/")) fail(fieldPath, "expected a route pattern starting with /");
9080
- return [pattern, resolve(inbound, "ssm", fieldPath)];
9081
- }));
9082
- };
9388
+ for (const pattern of servers) if (!pattern.startsWith("/")) fail(`${path}[${JSON.stringify(pattern)}]`, "expected a route pattern starting with /");
9389
+ }
9390
+ const directDialProperties = definition("DialerOptions").properties;
9083
9391
  function isEmptyDirect(fields) {
9084
- return durationNanoseconds(fields.connect_timeout, "connect_timeout") === 0 && (fields.netns === void 0 || fields.netns === "") && fields.domain_resolver === void 0;
9392
+ return Object.entries(fields).every(([key, value]) => {
9393
+ if (value === void 0 || !Object.hasOwn(directDialProperties, key)) return true;
9394
+ if (definitionName(directDialProperties[key]) === "Duration") return durationNanoseconds(value, key) === 0;
9395
+ if (key === "udp_fragment") return false;
9396
+ if (key === "routing_mark") return Number(value) === 0;
9397
+ return value === "" || value === 0 || value === false;
9398
+ });
9085
9399
  }
9086
9400
  // src/rules.ts
9087
- const commonMatches = [
9088
- "domain",
9089
- "domain_suffix",
9090
- "port",
9091
- "auth_user"
9092
- ];
9093
- const routeMatches = ["client"];
9094
9401
  const responseMatches = [
9095
9402
  "response_rcode",
9096
9403
  "response_answer",
@@ -9100,16 +9407,6 @@ const responseMatches = [
9100
9407
  "ip_is_private",
9101
9408
  "ip_accept_any"
9102
9409
  ];
9103
- const dnsMatches = [
9104
- "query_type",
9105
- "match_response",
9106
- ...responseMatches
9107
- ];
9108
- const referenceMatches = [
9109
- "inbound",
9110
- "rule_set",
9111
- "preferred_by"
9112
- ];
9113
9410
  const conditions = /* @__PURE__ */ new WeakMap();
9114
9411
  const allScopes = ["route", "dns"];
9115
9412
  function conditionData(value, path) {
@@ -9140,51 +9437,23 @@ function makeCondition(data) {
9140
9437
  conditions.set(value, data);
9141
9438
  return value;
9142
9439
  }
9143
- const scopeMatches = {
9144
- route: routeMatches,
9145
- dns: dnsMatches
9146
- };
9147
- const allMatches = [
9148
- ...commonMatches,
9149
- ...referenceMatches,
9150
- ...routeMatches,
9151
- ...dnsMatches
9152
- ];
9440
+ const routeKeys$1 = new Set(Object.keys(ruleMatchSchema.route.properties));
9441
+ const dnsKeys$1 = new Set(Object.keys(ruleMatchSchema.dns.properties));
9442
+ const allMatches = [.../* @__PURE__ */ new Set([...routeKeys$1, ...dnsKeys$1])];
9153
9443
  const leafValidators = {
9154
- route: objectValidator(pickSchema(definition("NestedRule").oneOf[0].properties, [
9155
- ...commonMatches,
9156
- ...referenceMatches,
9157
- ...routeMatches
9158
- ])),
9159
- dns: objectValidator(pickSchema(definition("NestedDNSRule").oneOf[0].properties, [
9160
- ...commonMatches,
9161
- ...referenceMatches,
9162
- ...dnsMatches
9163
- ]))
9164
- };
9165
- const leafReferences = {
9166
- route: {
9167
- inbound: arrayOrOne(ref("inbound")),
9168
- rule_set: arrayOrOne(ref("rule-set")),
9169
- preferred_by: arrayOrOne(ref("preferred-routes"))
9170
- },
9171
- dns: {
9172
- inbound: arrayOrOne(ref("inbound")),
9173
- rule_set: arrayOrOne(ref("rule-set")),
9174
- preferred_by: arrayOrOne(ref("preferred-domain"))
9175
- }
9444
+ route: compileSchema(ruleMatchSchema.route),
9445
+ dns: compileSchema(ruleMatchSchema.dns)
9176
9446
  };
9177
9447
  function active(value) {
9178
9448
  return value !== void 0 && value !== false && (!Array.isArray(value) || value.length !== 0);
9179
9449
  }
9180
- function checkLeaf(fields, path) {
9450
+ function checkLeaf(fields, path, scope) {
9181
9451
  if (fields.match_response === "") fail(`${path}.match_response`, "empty response tag");
9182
- if (responseMatches.some((key) => active(fields[key])) && !active(fields.match_response)) fail(`${path}.match_response`, "response fields require active response matching");
9183
- if (!Object.values(fields).some(active)) fail(path, "condition has no active fields");
9452
+ if (scope === "dns" && responseMatches.some((key) => active(fields[key])) && !active(fields.match_response)) fail(`${path}.match_response`, "response fields require active response matching");
9453
+ if (!Object.entries(fields).some(([key, value]) => key !== "invert" && active(value))) fail(path, "condition has no active fields");
9184
9454
  }
9185
9455
  function match(input) {
9186
9456
  const fields = fieldsFrom(input, "match", allMatches);
9187
- checkLeaf(fields, "match");
9188
9457
  const preferred = Array.isArray(fields.preferred_by) ? fields.preferred_by : [fields.preferred_by];
9189
9458
  const hasDnsTransport = preferred.some((value) => resourceData(value)?.target === "dns.servers");
9190
9459
  const hasOtherResource = preferred.some((value) => {
@@ -9192,11 +9461,17 @@ function match(input) {
9192
9461
  return data && data.target !== "dns.servers";
9193
9462
  });
9194
9463
  if (hasDnsTransport && hasOtherResource) fail("match.preferred_by", "mixed route and DNS targets");
9195
- const scopes = allScopes.filter((scope) => {
9196
- return !scopeMatches[scope === "route" ? "dns" : "route"].some((key) => fields[key] !== void 0) && !(scope === "route" ? hasDnsTransport : hasOtherResource);
9197
- });
9464
+ const keys = Object.keys(fields);
9465
+ const dnsOnly = hasDnsTransport || keys.some((key) => !routeKeys$1.has(key));
9466
+ const icmp = fields.network === "icmp" || Array.isArray(fields.network) && fields.network.includes("icmp");
9467
+ const addressMatch = fields.ip_cidr !== void 0 || fields.ip_is_private === true;
9468
+ const routeOnly = hasOtherResource || icmp || keys.some((key) => !dnsKeys$1.has(key)) || addressMatch && !dnsOnly;
9469
+ const scopes = allScopes.filter((scope) => scope === "route" ? !dnsOnly : !routeOnly);
9198
9470
  if (!scopes.length) fail("match", "fields have no common scope");
9199
- for (const scope of scopes) checkSchema(leafValidators[scope], expandFields(fields, leafReferences[scope], "match", previewReference), "match");
9471
+ for (const scope of scopes) {
9472
+ checkLeaf(fields, "match", scope);
9473
+ checkSchema(leafValidators[scope], expandInput(ruleMatchSchema[scope], fields, "match", previewReference), "match");
9474
+ }
9200
9475
  return makeCondition({
9201
9476
  scopes,
9202
9477
  invert: false,
@@ -9204,98 +9479,47 @@ function match(input) {
9204
9479
  });
9205
9480
  }
9206
9481
  const Rule = Object.freeze({ match });
9207
- function actionVariant(scope, action, keys, required = []) {
9208
- const raw = definition(scope === "route" ? "RuleAction" : "DNSRuleAction").oneOf.find((item) => item.properties?.action?.const === action).properties;
9209
- const properties = pickSchema(raw, ["action", ...keys]);
9210
- if (action === "reject") properties.method = {
9211
- type: "string",
9212
- enum: ["default", "drop"]
9213
- };
9214
- return {
9215
- keys: ["action", ...keys],
9216
- required: ["action", ...required],
9217
- validate: objectValidator(properties, ["action", ...required])
9218
- };
9482
+ function actionsFor(scope) {
9483
+ return new Map(Array.from(ruleActionSchemas(scope), ([action, schema]) => [action, {
9484
+ schema,
9485
+ validate: compileSchema(schema)
9486
+ }]));
9219
9487
  }
9220
- const sharedDnsOptions = [
9221
- "timeout",
9222
- "disable_cache",
9223
- "disable_optimistic_cache",
9224
- "rewrite_ttl",
9225
- "client_subnet",
9226
- "remove_client_subnet"
9227
- ];
9228
9488
  const actions = {
9229
- route: {
9230
- route: actionVariant("route", "route", ["outbound"], ["outbound"]),
9231
- bypass: actionVariant("route", "bypass", ["outbound"]),
9232
- reject: actionVariant("route", "reject", ["method", "no_drop"]),
9233
- "hijack-dns": actionVariant("route", "hijack-dns", [])
9234
- },
9235
- dns: {
9236
- route: actionVariant("dns", "route", [
9237
- "server",
9238
- "speculative",
9239
- "race",
9240
- ...sharedDnsOptions
9241
- ], ["server"]),
9242
- evaluate: actionVariant("dns", "evaluate", [
9243
- "server",
9244
- "tag",
9245
- "speculative",
9246
- ...sharedDnsOptions
9247
- ], ["server"]),
9248
- respond: actionVariant("dns", "respond", ["race"]),
9249
- "route-options": actionVariant("dns", "route-options", sharedDnsOptions),
9250
- reject: actionVariant("dns", "reject", [
9251
- "method",
9252
- "no_drop",
9253
- "race"
9254
- ]),
9255
- predefined: actionVariant("dns", "predefined", [
9256
- "rcode",
9257
- "answer",
9258
- "ns",
9259
- "extra",
9260
- "race"
9261
- ])
9262
- }
9489
+ route: actionsFor("route"),
9490
+ dns: actionsFor("dns")
9263
9491
  };
9264
9492
  function validSubnet(input) {
9265
9493
  const [address = "", prefix, ...extra] = input.split("/");
9266
9494
  const version = isIP(address);
9267
9495
  return version !== 0 && !address.includes("%") && extra.length === 0 && (prefix === void 0 || /^\d+$/.test(prefix) && Number(prefix) <= (version === 4 ? 32 : 128));
9268
9496
  }
9269
- function checkAction(fields, path) {
9497
+ function checkAction(fields, path, scope) {
9270
9498
  if (fields.method === "drop" && fields.no_drop === true) fail(`${path}.no_drop`, "no_drop with drop");
9271
9499
  if (fields.client_subnet !== void 0) {
9272
9500
  if (fields.remove_client_subnet === true) fail(`${path}.client_subnet`, "client_subnet with remove_client_subnet");
9273
9501
  if (!validSubnet(fields.client_subnet)) fail(`${path}.client_subnet`, "invalid subnet");
9274
9502
  }
9275
- if (fields.action === "route-options" && fields.rewrite_ttl === void 0 && fields.client_subnet === void 0 && fields.disable_cache !== true && fields.disable_optimistic_cache !== true && fields.remove_client_subnet !== true && durationNanoseconds(fields.timeout, `${path}.timeout`) <= 0) fail(path, "route-options requires an effective DNS option");
9503
+ if (scope === "dns" && fields.action === "route-options" && fields.rewrite_ttl === void 0 && fields.client_subnet === void 0 && fields.disable_cache !== true && fields.disable_optimistic_cache !== true && fields.remove_client_subnet !== true && durationNanoseconds(fields.timeout, `${path}.timeout`) <= 0) fail(path, "route-options requires an effective DNS option");
9276
9504
  if (fields.race === true && fields.speculative === true) fail(`${path}.race`, "race with speculative");
9277
9505
  }
9278
- const actionReferences = {
9279
- route: { outbound: ref("egress") },
9280
- dns: { server: ref("dns-server") }
9281
- };
9282
9506
  const rules = /* @__PURE__ */ new WeakMap();
9283
9507
  function makeRule(scope, condition, actionInput) {
9284
9508
  const path = `${scope}.rule`;
9285
- const variants = actions[scope];
9286
9509
  const name = record(actionInput, path).action;
9287
- if (typeof name !== "string" || !Object.hasOwn(variants, name)) fail(`${path}.action`, "unsupported action");
9288
- const variant = variants[name];
9289
- const action = fieldsFrom(actionInput, path, variant.keys, variant.required);
9290
- checkSchema(variant.validate, expandFields(action, actionReferences[scope], path, previewReference), path);
9291
- checkAction(action, path);
9510
+ const variant = typeof name === "string" ? actions[scope].get(name) : void 0;
9511
+ if (!variant) fail(`${path}.action`, "unsupported action");
9512
+ const action = fieldsFrom(actionInput, path, Object.keys(variant.schema.properties), variant.schema.required);
9513
+ checkSchema(variant.validate, expandInput(variant.schema, action, path, previewReference), path);
9514
+ checkAction(action, path, scope);
9292
9515
  if (condition !== void 0 && !conditionData(condition, path).scopes.includes(scope)) fail(path, "condition is incompatible with rule scope");
9293
9516
  if (action.race === true && !hasResponseCondition(condition)) fail(`${path}.race`, "race requires active response matching");
9294
9517
  const value = preserveIdentity({});
9295
9518
  rules.set(value, {
9296
9519
  scope,
9297
9520
  condition,
9298
- action: snapshot(action, path)
9521
+ action: snapshot(action, path),
9522
+ schema: variant.schema
9299
9523
  });
9300
9524
  return value;
9301
9525
  }
@@ -9315,11 +9539,10 @@ function expandCondition(value, scope, path, resolve) {
9315
9539
  const { node, invert } = conditionData(value, path);
9316
9540
  const inversion = invert ? { invert: true } : {};
9317
9541
  if ("fields" in node) {
9318
- checkLeaf(node.fields, path);
9319
- return {
9320
- ...expandFields(node.fields, leafReferences[scope], path, resolve),
9321
- ...inversion
9322
- };
9542
+ checkLeaf(node.fields, path, scope);
9543
+ const fields = expandInput(ruleMatchSchema[scope], node.fields, path, resolve);
9544
+ if (invert) fields.invert = node.fields.invert !== true;
9545
+ return fields;
9323
9546
  }
9324
9547
  if (!node.rules.length) fail(`${path}.rules`, "empty logical group");
9325
9548
  return {
@@ -9338,7 +9561,7 @@ function expandRule(value, scope, path, resolve) {
9338
9561
  }
9339
9562
  return {
9340
9563
  ...data.condition ? expandCondition(data.condition, scope, path, resolve) : {},
9341
- ...expandFields(data.action, actionReferences[scope], path, resolve)
9564
+ ...expandInput(data.schema, data.action, path, resolve)
9342
9565
  };
9343
9566
  }
9344
9567
  function checkDnsRules(rules, path) {
@@ -9381,14 +9604,12 @@ const topLevelLists = [
9381
9604
  const routeKeys = [
9382
9605
  "rules",
9383
9606
  "rule_set",
9384
- "final",
9385
- "default_domain_resolver",
9386
- "default_http_client"
9607
+ ...Object.keys(sectionSettings.route.properties)
9387
9608
  ];
9388
9609
  const dnsKeys = [
9389
9610
  "rules",
9390
9611
  "servers",
9391
- "final"
9612
+ ...Object.keys(sectionSettings.dns.properties)
9392
9613
  ];
9393
9614
  function array(value, path) {
9394
9615
  if (!Array.isArray(value)) fail(path, "expected an array");
@@ -9419,8 +9640,7 @@ function checkCycles(resources) {
9419
9640
  */
9420
9641
  function compile(input) {
9421
9642
  const fields = fieldsFrom(input, "config", [
9422
- "log",
9423
- "experimental",
9643
+ ...Object.keys(rootSettings),
9424
9644
  ...topLevelLists,
9425
9645
  "route",
9426
9646
  "dns"
@@ -9508,59 +9728,85 @@ function compile(input) {
9508
9728
  const { data, path } = entry;
9509
9729
  const { server, detour, domain_resolver } = data.fields;
9510
9730
  if (data.remoteDns && typeof server === "string" && !isIP(server) && detour === void 0 && domain_resolver === void 0) fail(`${path}.domain_resolver`, "hostname requires a per-server resolver or detour");
9511
- return expandFields(data.fields, data.references ?? {}, path, resolveFrom(entry));
9731
+ return (data.expand ?? copyJson)(data.fields, path, resolveFrom(entry));
9512
9732
  });
9513
9733
  }
9514
9734
  const resolve = resolveFrom();
9515
9735
  const output = {};
9516
- for (const key of ["log", "experimental"]) if (fields[key] !== void 0) output[key] = copyJson(fields[key], key);
9736
+ for (const [key, schema] of Object.entries(rootSettings)) if (fields[key] !== void 0) output[key] = expandInput(schema, fields[key], key, resolve);
9517
9737
  for (const target of topLevelLists) {
9518
9738
  const values = emitList(target);
9519
9739
  if (values !== void 0) output[target] = values;
9520
9740
  }
9521
- if (route) output.route = expandFields(route, {
9522
- rule_set: () => emitList("route.rule_set"),
9523
- final: ref("egress"),
9524
- default_domain_resolver: expandResolver,
9525
- default_http_client: ref("http-client"),
9526
- rules: (values, path) => array(values, path).map((value, index) => expandRule(value, "route", `${path}[${index}]`, resolve))
9527
- }, "route", resolve);
9528
- if (dns) output.dns = expandFields(dns, {
9529
- servers: () => emitList("dns.servers"),
9530
- final: ref("dns-server"),
9531
- rules: (values, path) => {
9532
- const rules = array(values, path).map((value, index) => expandRule(value, "dns", `${path}[${index}]`, resolve));
9533
- checkDnsRules(rules, path);
9534
- return rules;
9741
+ if (route) {
9742
+ const { rules, rule_set, ...settings } = route;
9743
+ const result = expandInput(sectionSettings.route, settings, "route", resolve);
9744
+ if (rule_set !== void 0) result.rule_set = emitList("route.rule_set");
9745
+ if (rules !== void 0) result.rules = array(rules, "route.rules").map((value, index) => expandRule(value, "route", `route.rules[${index}]`, resolve));
9746
+ output.route = result;
9747
+ }
9748
+ if (dns) {
9749
+ const { rules, servers, ...settings } = dns;
9750
+ const result = expandInput(sectionSettings.dns, settings, "dns", resolve);
9751
+ if (servers !== void 0) result.servers = emitList("dns.servers");
9752
+ if (rules !== void 0) {
9753
+ const compiled = array(rules, "dns.rules").map((value, index) => expandRule(value, "dns", `dns.rules[${index}]`, resolve));
9754
+ checkDnsRules(compiled, "dns.rules");
9755
+ result.rules = compiled;
9535
9756
  }
9536
- }, "dns", resolve);
9757
+ output.dns = result;
9758
+ }
9537
9759
  checkCycles(registrations.values());
9538
9760
  return validateConfig(output);
9539
9761
  }
9540
9762
  // src/user.ts
9541
- const users = /* @__PURE__ */ new WeakSet();
9763
+ const passwordFields = ["password"];
9764
+ const credentialFields = {
9765
+ anytls: passwordFields,
9766
+ http: passwordFields,
9767
+ hysteria: ["auth", "auth_str"],
9768
+ hysteria2: passwordFields,
9769
+ mixed: passwordFields,
9770
+ naive: passwordFields,
9771
+ shadowsocks: passwordFields,
9772
+ shadowtls: passwordFields,
9773
+ snell: ["userkey"],
9774
+ socks: passwordFields,
9775
+ trojan: passwordFields,
9776
+ tuic: ["password", "uuid"],
9777
+ vless: ["uuid", "flow"],
9778
+ vmess: ["uuid", "alter_id"]
9779
+ };
9780
+ const users = /* @__PURE__ */ new WeakMap();
9542
9781
  function user(input) {
9543
- const { name } = fieldsFrom(input, "user", ["name"], ["name"]);
9782
+ const { name, credentials } = fieldsFrom(input, "user", ["name", "credentials"], ["name"]);
9544
9783
  if (typeof name !== "string") fail("user.name", "expected a string");
9784
+ const entries = fieldsFrom(credentials === void 0 ? {} : credentials, "user.credentials", Object.keys(credentialFields));
9785
+ for (const key of Object.keys(credentialFields)) {
9786
+ if (!Object.hasOwn(entries, key)) continue;
9787
+ const path = `user.credentials.${key}`;
9788
+ const allowed = credentialFields[key];
9789
+ const required = key === "hysteria" ? [] : allowed.filter((field) => field !== "flow" && field !== "alter_id");
9790
+ const entry = fieldsFrom(entries[key], path, allowed, required);
9791
+ if (key === "hysteria" && Object.keys(entry).length !== 1) fail(path, "expected either auth or auth_str");
9792
+ for (const [field, value] of Object.entries(entry)) if (field === "alter_id") {
9793
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) fail(`${path}.${field}`, "expected a non-negative integer");
9794
+ } else if (field === "auth" && Array.isArray(value)) {
9795
+ if (Array.from(value).some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255)) fail(`${path}.${field}`, "expected an array of bytes");
9796
+ } else if (typeof value !== "string") fail(`${path}.${field}`, "expected a string");
9797
+ entries[key] = entry;
9798
+ }
9545
9799
  const value = preserveIdentity({ name });
9546
- users.add(value);
9800
+ users.set(value, snapshot(entries, "user.credentials"));
9547
9801
  return value;
9548
9802
  }
9549
9803
  function isUser(value) {
9550
9804
  return value !== null && typeof value === "object" && users.has(value);
9551
9805
  }
9806
+ function requireUserCredentials(value, kind, path) {
9807
+ return users.get(value)?.[kind] ?? fail(path, `missing ${kind} credentials`);
9808
+ }
9552
9809
  // src/factories.ts
9553
- const targetSchema = {
9554
- inbounds: "Inbound",
9555
- outbounds: "Outbound",
9556
- endpoints: "Endpoint",
9557
- services: "Service",
9558
- http_clients: "HTTPClient",
9559
- "dns.servers": "DNSServer",
9560
- "route.rule_set": "RuleSet",
9561
- certificate_providers: "CertificateProvider",
9562
- network_namespaces: "NetworkNamespace"
9563
- };
9564
9810
  const targetRoles = {
9565
9811
  inbounds: ["inbound", "listen-detour"],
9566
9812
  outbounds: ["egress"],
@@ -9572,45 +9818,72 @@ const targetRoles = {
9572
9818
  certificate_providers: ["certificate-provider"],
9573
9819
  network_namespaces: ["netns"]
9574
9820
  };
9575
- const settingsGroups = [
9576
- "listen",
9577
- "dial",
9578
- "tls"
9579
- ];
9580
- const validators = /* @__PURE__ */ new WeakMap();
9581
- function validateFactoryOutput(def, fields, path) {
9582
- let validate = validators.get(def);
9583
- if (!validate) {
9584
- const name = targetSchema[def.target];
9585
- validate = compileSchema(def.target === "http_clients" ? definition(name) : variant(name, def.kind));
9586
- validators.set(def, validate);
9587
- }
9588
- checkSchema(validate, fields, path);
9589
- }
9590
- function prepareUsers(fields, auth, path) {
9821
+ const endpointRoles = {
9822
+ tailscale: "tailscale-endpoint",
9823
+ openconnect: "openconnect-endpoint",
9824
+ "openvpn-client": "openvpn-client-endpoint"
9825
+ };
9826
+ const namedAuth = {
9827
+ name: "name",
9828
+ allowRaw: true
9829
+ };
9830
+ const usernameAuth = {
9831
+ name: "username",
9832
+ allowRaw: true
9833
+ };
9834
+ const authOptions = {
9835
+ anytls: namedAuth,
9836
+ http: usernameAuth,
9837
+ hysteria: namedAuth,
9838
+ hysteria2: namedAuth,
9839
+ mixed: usernameAuth,
9840
+ naive: usernameAuth,
9841
+ shadowsocks: namedAuth,
9842
+ shadowtls: namedAuth,
9843
+ snell: namedAuth,
9844
+ socks: {
9845
+ name: "username",
9846
+ allowRaw: false
9847
+ },
9848
+ trojan: namedAuth,
9849
+ tuic: namedAuth,
9850
+ vless: {
9851
+ name: "name",
9852
+ allowRaw: false
9853
+ },
9854
+ vmess: namedAuth
9855
+ };
9856
+ function prepareUsers(fields, kind, path) {
9591
9857
  if (fields.users === void 0) return [];
9592
9858
  const users = fields.users;
9593
9859
  if (!Array.isArray(users)) fail(`${path}.users`, "expected an array");
9860
+ const auth = authOptions[kind];
9594
9861
  const members = [];
9595
9862
  fields.users = Array.from(users, (value, index) => {
9596
9863
  const entryPath = `${path}.users[${index}]`;
9597
- const entry = record(value, entryPath);
9598
- if (!Object.hasOwn(entry, "user") && auth.allowRaw) {
9599
- const raw = fieldsFrom(entry, entryPath, [auth.name, ...auth.credentials]);
9600
- members.push({ name: raw[auth.name] });
9601
- return raw;
9864
+ if (isUser(value)) {
9865
+ members.push({
9866
+ user: value,
9867
+ name: value.name
9868
+ });
9869
+ if (kind === "vmess") {
9870
+ const { alter_id, ...credentials } = requireUserCredentials(value, kind, entryPath);
9871
+ return {
9872
+ name: value.name,
9873
+ ...credentials,
9874
+ alterId: alter_id
9875
+ };
9876
+ }
9877
+ return {
9878
+ [auth.name]: value.name,
9879
+ ...requireUserCredentials(value, kind, entryPath)
9880
+ };
9602
9881
  }
9603
- if (Object.hasOwn(entry, auth.name)) fail(keyPath(entryPath, auth.name), "explicit name with User");
9604
- const { user, ...credentials } = fieldsFrom(entry, entryPath, ["user", ...auth.credentials], ["user", ...auth.required]);
9605
- if (!isUser(user)) fail(`${entryPath}.user`, "expected a User");
9606
- members.push({
9607
- user,
9608
- name: user.name
9609
- });
9610
- return {
9611
- [auth.name]: user.name,
9612
- ...credentials
9613
- };
9882
+ if (!auth.allowRaw) fail(entryPath, "expected a User from user()");
9883
+ const raw = record(value, entryPath);
9884
+ if (Object.hasOwn(raw, "user")) fail(`${entryPath}.user`, "pass the User directly and configure credentials in user()");
9885
+ members.push({ name: raw[auth.name] });
9886
+ return raw;
9614
9887
  });
9615
9888
  return members;
9616
9889
  }
@@ -9627,192 +9900,6 @@ function validateTag(tag, path) {
9627
9900
  });
9628
9901
  } else if (typeof tag !== "string" || tag === "") fail(path, "expected a non-empty tag");
9629
9902
  }
9630
- function build(def, input) {
9631
- const path = `${def.target}.${def.kind}`;
9632
- const options = fieldsFrom(input, path, [...def.required, ...def.optional ?? []], def.required);
9633
- validateTag(options.tag, `${path}.tag`);
9634
- const members = def.auth ? prepareUsers(options, def.auth, path) : [];
9635
- const extraRoles = def.prepare?.(options, path) ?? [];
9636
- const roles = Object.freeze([
9637
- ...targetRoles[def.target],
9638
- ...def.roles ?? [],
9639
- ...extraRoles
9640
- ]);
9641
- const base = snapshot(def.target === "http_clients" ? options : {
9642
- type: def.kind,
9643
- ...options
9644
- }, path);
9645
- const references = Object.freeze({
9646
- ...def.references,
9647
- ...def.listen ? listenReferences : {},
9648
- ...def.dial ? dialReferences : {},
9649
- ...def.tls ? { tls: expandTls } : {}
9650
- });
9651
- function create(groups) {
9652
- const fields = { ...base };
9653
- for (const group of settingsGroups) for (const [key, value] of Object.entries(groups[group] ?? {})) {
9654
- if (Object.hasOwn(fields, key)) fail(keyPath(path, key), "conflicting output field");
9655
- fields[key] = value;
9656
- }
9657
- validateFactoryOutput(def, expandFields(fields, references, path, previewReference), path);
9658
- const apply = (group, getFields) => {
9659
- if (groups[group]) fail(keyPath(path, group), "settings group already applied");
9660
- return create({
9661
- ...groups,
9662
- [group]: snapshot(getFields(), path)
9663
- });
9664
- };
9665
- const methods = {};
9666
- if (def.listen) methods.listen = (address, input) => apply("listen", () => listenFields(address, input, path, def.listen === "forwarding"));
9667
- if (def.dial) methods.dial = (input) => apply("dial", () => {
9668
- const dial = dialFields(input, path, def.dial === "detour");
9669
- def.checkDial?.(fields, dial, path);
9670
- return dial;
9671
- });
9672
- const tlsMode = def.tls;
9673
- if (tlsMode) methods.tls = (input) => apply("tls", () => tlsFields(input, `${path}.tls`, tlsMode));
9674
- if (def.auth) methods.authUser = (user) => {
9675
- const matching = members.filter((entry) => entry.user === user);
9676
- if (!isUser(user) || matching.length !== 1 || !user.name || members.filter((entry) => entry.name === user.name).length !== 1) fail(`${path}.authUser`, "expected one User entry with a unique non-empty name");
9677
- return Rule.match({
9678
- inbound: resource,
9679
- auth_user: user.name
9680
- });
9681
- };
9682
- const resource = createResource(Object.freeze({
9683
- target: def.target,
9684
- kind: def.kind,
9685
- fields: Object.freeze(fields),
9686
- references,
9687
- roles,
9688
- remoteDns: def.remoteDns,
9689
- startupDetour: def.startupDetour
9690
- }), methods);
9691
- return resource;
9692
- }
9693
- return create({});
9694
- }
9695
- function factory(def) {
9696
- return (options) => build(def, options);
9697
- }
9698
- const passwordAuth = {
9699
- name: "username",
9700
- credentials: ["password"],
9701
- required: ["password"]
9702
- };
9703
- const mixed = {
9704
- target: "inbounds",
9705
- kind: "mixed",
9706
- required: ["tag"],
9707
- optional: ["users", "set_system_proxy"],
9708
- listen: "forwarding",
9709
- tls: "server",
9710
- auth: {
9711
- ...passwordAuth,
9712
- allowRaw: true
9713
- }
9714
- };
9715
- const socks = {
9716
- target: "inbounds",
9717
- kind: "socks",
9718
- required: ["tag"],
9719
- optional: ["users"],
9720
- listen: "forwarding",
9721
- auth: passwordAuth
9722
- };
9723
- const inboundVless = {
9724
- target: "inbounds",
9725
- kind: "vless",
9726
- required: ["tag", "users"],
9727
- listen: "forwarding",
9728
- tls: "server-reality",
9729
- auth: {
9730
- name: "name",
9731
- credentials: ["uuid", "flow"],
9732
- required: ["uuid"]
9733
- }
9734
- };
9735
- const shadowsocks = {
9736
- target: "inbounds",
9737
- kind: "shadowsocks",
9738
- required: ["tag", "method"],
9739
- optional: [
9740
- "network",
9741
- "password",
9742
- "users",
9743
- "managed"
9744
- ],
9745
- listen: "forwarding",
9746
- auth: {
9747
- ...passwordAuth,
9748
- name: "name",
9749
- allowRaw: true
9750
- },
9751
- prepare(fields, path) {
9752
- const hasUsers = Array.isArray(fields.users) && fields.users.length > 0;
9753
- if (hasUsers && fields.managed === true) fail(`${path}.users`, "managed mode cannot have static users");
9754
- if (hasUsers || fields.managed === true) {
9755
- if (fields.method === "none") fail(`${path}.method`, "method none is unavailable in multi-user modes");
9756
- return ["ssm"];
9757
- }
9758
- }
9759
- };
9760
- function makeShadowsocks(options) {
9761
- return build(shadowsocks, options);
9762
- }
9763
- const inbound = Object.freeze({
9764
- mixed: (options) => build(mixed, options),
9765
- socks: (options) => build(socks, options),
9766
- vless: (options) => build(inboundVless, options),
9767
- shadowsocks: makeShadowsocks
9768
- });
9769
- const api = {
9770
- target: "services",
9771
- kind: "api",
9772
- required: [],
9773
- optional: [
9774
- "tag",
9775
- "secret",
9776
- "dashboard",
9777
- "access_control_allow_origin",
9778
- "access_control_allow_private_network"
9779
- ],
9780
- listen: "listener",
9781
- tls: "server",
9782
- references: { dashboard: expandDashboard }
9783
- };
9784
- const ssmApi = {
9785
- target: "services",
9786
- kind: "ssm-api",
9787
- required: ["servers"],
9788
- optional: ["tag", "cache_path"],
9789
- listen: "listener",
9790
- tls: "server",
9791
- references: { servers: expandSsmServers }
9792
- };
9793
- const service = Object.freeze({
9794
- /**
9795
- * sing-box defaults to loopback (127.0.0.1). An omitted or empty secret allows
9796
- * unauthenticated connections. Omitting server TLS uses plaintext TCP.
9797
- */
9798
- api: (options = {}) => build(api, options),
9799
- ssmApi: (options) => build(ssmApi, options)
9800
- });
9801
- const http = {
9802
- target: "http_clients",
9803
- kind: "http-client",
9804
- required: [],
9805
- optional: [
9806
- "version",
9807
- "headers",
9808
- "tag"
9809
- ],
9810
- dial: "detour",
9811
- tls: "client"
9812
- };
9813
- function httpClient(options = {}) {
9814
- return build(http, options);
9815
- }
9816
9903
  function checkGroup(fields, path) {
9817
9904
  const candidates = fields.outbounds;
9818
9905
  if (!Array.isArray(candidates) || candidates.length === 0) fail(`${path}.outbounds`, "expected at least one candidate");
@@ -9827,153 +9914,6 @@ function checkGroup(fields, path) {
9827
9914
  });
9828
9915
  if (fields.default !== void 0 && !candidates.includes(fields.default)) fail(`${path}.default`, "default must be a candidate");
9829
9916
  }
9830
- const selector = {
9831
- target: "outbounds",
9832
- kind: "selector",
9833
- required: ["tag", "outbounds"],
9834
- optional: ["default", "interrupt_exist_connections"],
9835
- prepare: checkGroup,
9836
- references: {
9837
- outbounds: arrayOrOne(ref("egress")),
9838
- default: ref("egress")
9839
- }
9840
- };
9841
- const urltest = {
9842
- target: "outbounds",
9843
- kind: "urltest",
9844
- required: ["tag", "outbounds"],
9845
- optional: [
9846
- "url",
9847
- "interval",
9848
- "tolerance",
9849
- "idle_timeout",
9850
- "interrupt_exist_connections"
9851
- ],
9852
- prepare: checkGroup,
9853
- references: { outbounds: arrayOrOne(ref("egress")) }
9854
- };
9855
- const outbound = Object.freeze({
9856
- direct: factory({
9857
- target: "outbounds",
9858
- kind: "direct",
9859
- required: ["tag"],
9860
- dial: "direct"
9861
- }),
9862
- vless: factory({
9863
- target: "outbounds",
9864
- kind: "vless",
9865
- required: [
9866
- "tag",
9867
- "server",
9868
- "server_port",
9869
- "uuid"
9870
- ],
9871
- optional: ["flow"],
9872
- dial: "detour",
9873
- tls: "client-reality",
9874
- startupDetour: true
9875
- }),
9876
- selector: (options) => build(selector, options),
9877
- urltest: (options) => build(urltest, options)
9878
- });
9879
- const endpoint = Object.freeze({
9880
- tailscale: factory({
9881
- target: "endpoints",
9882
- kind: "tailscale",
9883
- required: ["tag"],
9884
- optional: [
9885
- "state_directory",
9886
- "auth_key",
9887
- "hostname",
9888
- "accept_routes",
9889
- "exit_node",
9890
- "listen_port"
9891
- ],
9892
- dial: "detour",
9893
- roles: ["preferred-routes", "tailscale-endpoint"]
9894
- }),
9895
- wireguard: factory({
9896
- target: "endpoints",
9897
- kind: "wireguard",
9898
- required: [
9899
- "tag",
9900
- "address",
9901
- "private_key"
9902
- ],
9903
- optional: [
9904
- "peers",
9905
- "listen_port",
9906
- "system"
9907
- ],
9908
- dial: "detour",
9909
- startupDetour: true,
9910
- roles: ["preferred-routes"],
9911
- checkDial(fields, dial, path) {
9912
- if (dial.detour !== void 0 && fields.listen_port !== void 0 && fields.listen_port !== 0) fail(`${path}.listen_port`, "non-zero WireGuard listen port with detour");
9913
- }
9914
- })
9915
- });
9916
- const remoteDns = {
9917
- target: "dns.servers",
9918
- required: ["tag", "server"],
9919
- optional: ["server_port"],
9920
- dial: "detour",
9921
- remoteDns: true
9922
- };
9923
- const tailscaleDns = {
9924
- target: "dns.servers",
9925
- kind: "tailscale",
9926
- required: ["tag", "endpoint"],
9927
- optional: ["accept_default_resolvers", "accept_search_domain"],
9928
- roles: ["preferred-domain"],
9929
- references: { endpoint: ref("tailscale-endpoint") }
9930
- };
9931
- const dnsServer = Object.freeze({
9932
- tcp: factory({
9933
- ...remoteDns,
9934
- kind: "tcp"
9935
- }),
9936
- udp: factory({
9937
- ...remoteDns,
9938
- kind: "udp"
9939
- }),
9940
- tls: factory({
9941
- ...remoteDns,
9942
- kind: "tls",
9943
- tls: "client"
9944
- }),
9945
- https: factory({
9946
- ...remoteDns,
9947
- kind: "https",
9948
- tls: "client",
9949
- optional: [
9950
- "server_port",
9951
- "path",
9952
- "headers"
9953
- ]
9954
- }),
9955
- tailscale: (options) => build(tailscaleDns, options)
9956
- });
9957
- const tailscaleProvider = {
9958
- target: "certificate_providers",
9959
- kind: "tailscale",
9960
- required: ["tag", "endpoint"],
9961
- references: { endpoint: ref("tailscale-endpoint") }
9962
- };
9963
- const certificateProvider = Object.freeze({ tailscale: (options) => build(tailscaleProvider, options) });
9964
- const networkNamespace = Object.freeze({
9965
- default: factory({
9966
- target: "network_namespaces",
9967
- kind: "default",
9968
- required: ["tag", "path"]
9969
- }),
9970
- unshare: factory({
9971
- target: "network_namespaces",
9972
- kind: "unshare",
9973
- required: ["tag"],
9974
- optional: ["pid_file"]
9975
- })
9976
- });
9977
9917
  function ruleSetFormat(fields, path, location) {
9978
9918
  const input = fields[location];
9979
9919
  if (typeof input !== "string") fail(keyPath(path, location), "expected a string");
@@ -9990,47 +9930,618 @@ function ruleSetFormat(fields, path, location) {
9990
9930
  else if (extension?.endsWith(".srs")) fields.format = "binary";
9991
9931
  else fail(`${path}.format`, "cannot infer rule-set format");
9992
9932
  }
9993
- const inlineRuleSet = {
9994
- target: "route.rule_set",
9995
- kind: "inline",
9996
- required: ["tag", "rules"],
9997
- prepare(fields, path) {
9998
- if (!Array.isArray(fields.rules) || !fields.rules.length) fail(`${path}.rules`, "expected at least one rule");
9933
+ const settingsGroups = [
9934
+ "listen",
9935
+ "dial",
9936
+ "tls"
9937
+ ];
9938
+ function prepareOptions(target, kind, options, path, roles) {
9939
+ if (target === "inbounds" && kind === "shadowsocks") {
9940
+ const hasUsers = Array.isArray(options.users) && options.users.length > 0;
9941
+ if (hasUsers && options.managed === true) fail(`${path}.users`, "managed mode cannot have static users");
9942
+ if (hasUsers || options.managed === true) {
9943
+ if (options.method === "none") fail(`${path}.method`, "method none is unavailable in multi-user modes");
9944
+ roles.push("ssm");
9945
+ }
9946
+ }
9947
+ if (target === "outbounds" && (kind === "selector" || kind === "urltest")) checkGroup(options, path);
9948
+ if (target === "services" && kind === "ssm-api") checkSsmServers(options.servers, `${path}.servers`);
9949
+ if (target === "route.rule_set") {
9950
+ if (kind === "inline") {
9951
+ if (typeof options.tag !== "string") fail(`${path}.tag`, "expected a single tag");
9952
+ if (!Array.isArray(options.rules) || !options.rules.length) fail(`${path}.rules`, "expected at least one rule");
9953
+ } else ruleSetFormat(options, path, kind === "local" ? "path" : "url");
9954
+ }
9955
+ }
9956
+ function getRoles(target, kind) {
9957
+ const roles = [...targetRoles[target]];
9958
+ if (target === "endpoints") {
9959
+ if (Object.hasOwn(endpointRoles, kind)) roles.push(endpointRoles[kind]);
9960
+ if (preferredRouteEndpoints.some((preferred) => preferred === kind)) roles.push("preferred-routes");
9999
9961
  }
9962
+ if (target === "outbounds" && kind === "bridge") roles.push("preferred-routes");
9963
+ if (target === "dns.servers" && preferredDnsKinds.some((preferred) => preferred === kind)) roles.push("preferred-domain");
9964
+ if (target === "services" && kind === "resolved") roles.push("resolved-service");
9965
+ return roles;
9966
+ }
9967
+ function makeFactory(target, kind, branches) {
9968
+ const path = `${target}.${kind}`;
9969
+ const validators = /* @__PURE__ */ new Map();
9970
+ const auth = target === "inbounds" && Object.hasOwn(authOptions, kind) ? kind : void 0;
9971
+ return (input = {}) => {
9972
+ const raw = record(input, path);
9973
+ const branch = branches.length === 1 ? branches[0] : branches.find((item) => matchesDiscriminators(item.options, raw));
9974
+ if (!branch) {
9975
+ const discriminator = branches[0]?.options.properties?.version ? "version" : "provider";
9976
+ fail(keyPath(path, discriminator), "invalid or missing branch discriminator");
9977
+ }
9978
+ const options = fieldsFrom(raw, path, Object.keys(branch.options.properties), branch.options.required);
9979
+ validateTag(options.tag, `${path}.tag`);
9980
+ const users = auth ? prepareUsers(options, auth, path) : [];
9981
+ const members = kind === "shadowtls" && options.version !== 3 ? [] : users;
9982
+ const roles = getRoles(target, kind);
9983
+ prepareOptions(target, kind, options, path, roles);
9984
+ const base = snapshot(target === "http_clients" ? options : {
9985
+ type: kind,
9986
+ ...options
9987
+ }, path);
9988
+ const expand = (value, path, resolve) => expandInput(branch.output, value, path, resolve);
9989
+ const validate = validators.get(branch) ?? compileSchema(branch.output);
9990
+ validators.set(branch, validate);
9991
+ const { listen, dial, tls } = branch;
9992
+ function create(groups) {
9993
+ const fields = { ...base };
9994
+ for (const group of settingsGroups) for (const [key, value] of Object.entries(groups[group] ?? {})) {
9995
+ if (Object.hasOwn(fields, key)) fail(keyPath(path, key), "conflicting output field");
9996
+ fields[key] = value;
9997
+ }
9998
+ checkSchema(validate, expand(fields, path, previewReference), path);
9999
+ const apply = (group, getFields) => {
10000
+ if (groups[group]) fail(keyPath(path, group), "settings group already applied");
10001
+ return create({
10002
+ ...groups,
10003
+ [group]: snapshot(getFields(), path)
10004
+ });
10005
+ };
10006
+ const methods = {};
10007
+ if (listen) methods.listen = (address, input = {}) => apply("listen", () => address !== null && typeof address === "object" ? listenFields(void 0, address, path, listen) : listenFields(address, input, path, listen));
10008
+ if (dial) methods.dial = (input) => apply("dial", () => {
10009
+ const settings = fieldsFrom(input, path, Object.keys(dial.properties));
10010
+ if (kind === "wireguard" && settings.detour !== void 0 && fields.listen_port !== void 0 && fields.listen_port !== 0) fail(`${path}.listen_port`, "non-zero WireGuard listen port with detour");
10011
+ return settings;
10012
+ });
10013
+ if (tls) {
10014
+ const name = definitionName(tls);
10015
+ let mode;
10016
+ if (name === "InboundTLSOptions") mode = kind === "vless" ? "server-reality" : "server";
10017
+ if (name === "OutboundTLSOptions") mode = kind === "vless" ? "client-reality" : "client";
10018
+ methods.tls = (input) => apply("tls", () => tlsFields(input, `${path}.tls`, tls, mode, kind));
10019
+ }
10020
+ if (auth) methods.authUser = (user) => {
10021
+ if (!isUser(user) || members.filter((entry) => entry.user === user).length !== 1 || !user.name || members.filter((entry) => entry.name === user.name).length !== 1) fail(`${path}.authUser`, "expected one User entry with a unique non-empty name");
10022
+ return Rule.match({
10023
+ inbound: resource,
10024
+ auth_user: user.name
10025
+ });
10026
+ };
10027
+ const resource = createResource(Object.freeze({
10028
+ target,
10029
+ kind,
10030
+ fields: Object.freeze(fields),
10031
+ expand,
10032
+ roles: Object.freeze(roles),
10033
+ remoteDns: target === "dns.servers" && Object.hasOwn(base, "server"),
10034
+ startupDetour: target === "outbounds" && kind === "vless" || target === "endpoints" && kind === "wireguard"
10035
+ }), methods);
10036
+ return resource;
10037
+ }
10038
+ return create({});
10039
+ };
10040
+ }
10041
+ function factoriesFor(target) {
10042
+ return Object.fromEntries(Array.from(factoryCatalog(target), ([kind, branches]) => [factoryName(kind), makeFactory(target, kind, branches)]));
10043
+ }
10044
+ const inbound = Object.freeze(factoriesFor("inbounds"));
10045
+ const outbound = Object.freeze(factoriesFor("outbounds"));
10046
+ const endpoint = Object.freeze(factoriesFor("endpoints"));
10047
+ const service = Object.freeze(factoriesFor("services"));
10048
+ const dnsServer = Object.freeze(factoriesFor("dns.servers"));
10049
+ const certificateProvider = Object.freeze(factoriesFor("certificate_providers"));
10050
+ const networkNamespace = Object.freeze(factoriesFor("network_namespaces"));
10051
+ const httpClient = factoriesFor("http_clients").httpClient;
10052
+ const ruleSet = Object.freeze(factoriesFor("route.rule_set"));
10053
+ // src/proxy-profile.ts
10054
+ const sharedOption = {
10055
+ hysteria: "obfs",
10056
+ hysteria2: "obfs",
10057
+ shadowsocks: "method"
10058
+ };
10059
+ const ownedServer = [
10060
+ "tag",
10061
+ "users",
10062
+ "password",
10063
+ "version",
10064
+ "transport",
10065
+ "managed",
10066
+ "destinations",
10067
+ "psk",
10068
+ "mode",
10069
+ "obfs_mode",
10070
+ "realm",
10071
+ "handshake"
10072
+ ];
10073
+ const ownedClient = [
10074
+ "tag",
10075
+ "server",
10076
+ "server_port",
10077
+ "server_ports",
10078
+ "username",
10079
+ "password",
10080
+ "uuid",
10081
+ "flow",
10082
+ "alter_id",
10083
+ "auth",
10084
+ "auth_str",
10085
+ "userkey",
10086
+ "psk",
10087
+ "version",
10088
+ "transport",
10089
+ "mode",
10090
+ "obfs_mode",
10091
+ "realm"
10092
+ ];
10093
+ const transportFields = {
10094
+ tcp: [],
10095
+ quic: [],
10096
+ http: [
10097
+ "host",
10098
+ "path",
10099
+ "method"
10100
+ ],
10101
+ ws: [
10102
+ "path",
10103
+ "max_early_data",
10104
+ "early_data_header_name"
10105
+ ],
10106
+ grpc: ["service_name"],
10107
+ httpupgrade: ["host", "path"]
10000
10108
  };
10001
- const localRuleSet = {
10002
- target: "route.rule_set",
10003
- kind: "local",
10004
- required: ["tag", "path"],
10005
- optional: ["format"],
10006
- prepare: (fields, path) => ruleSetFormat(fields, path, "path")
10109
+ const localTransportFields = {
10110
+ tcp: [],
10111
+ quic: [],
10112
+ http: [
10113
+ "headers",
10114
+ "idle_timeout",
10115
+ "ping_timeout"
10116
+ ],
10117
+ ws: ["headers"],
10118
+ grpc: ["idle_timeout", "ping_timeout"],
10119
+ httpupgrade: ["headers"]
10007
10120
  };
10008
- const remoteRuleSet = {
10009
- target: "route.rule_set",
10010
- kind: "remote",
10011
- required: ["tag", "url"],
10012
- optional: [
10013
- "format",
10014
- "initial_path",
10015
- "update_interval",
10016
- "http_client"
10121
+ const grpcClientFields = ["permit_without_stream"];
10122
+ const tlsRequired = /* @__PURE__ */ new Set([
10123
+ "anytls",
10124
+ "hysteria",
10125
+ "hysteria2",
10126
+ "naive",
10127
+ "tuic"
10128
+ ]);
10129
+ const versioned = [
10130
+ "socks",
10131
+ "shadowtls",
10132
+ "snell"
10133
+ ];
10134
+ const transportProtocols = [
10135
+ "vmess",
10136
+ "vless",
10137
+ "trojan"
10138
+ ];
10139
+ const namedClients = [
10140
+ "socks",
10141
+ "http",
10142
+ "naive"
10143
+ ];
10144
+ const optionalUsers = [
10145
+ "http",
10146
+ "socks",
10147
+ "snell",
10148
+ "shadowsocks",
10149
+ "shadowtls"
10150
+ ];
10151
+ const specialFields = {
10152
+ hysteria2: ["realm"],
10153
+ shadowsocks: [
10154
+ "password",
10155
+ "serverKey",
10156
+ "managed"
10157
+ ],
10158
+ shadowtls: [
10159
+ "password",
10160
+ "serverName",
10161
+ "handshake"
10017
10162
  ],
10018
- references: { http_client: expandHttpClient },
10019
- prepare: (fields, path) => ruleSetFormat(fields, path, "url")
10163
+ snell: [
10164
+ "psk",
10165
+ "obfs_mode",
10166
+ "mode"
10167
+ ]
10020
10168
  };
10021
- function requireSingleTag(fields, path) {
10022
- if (typeof fields.tag !== "string") fail(`${path}.tag`, "expected a single tag");
10169
+ function native(factory, options) {
10170
+ return factory(options);
10023
10171
  }
10024
- const ruleSet = Object.freeze({
10025
- inline(options) {
10026
- requireSingleTag(record(options, "ruleSet.inline"), "ruleSet.inline");
10027
- return build(inlineRuleSet, options);
10028
- },
10029
- local(options) {
10030
- return build(localRuleSet, options);
10031
- },
10032
- remote(options) {
10033
- return build(remoteRuleSet, options);
10172
+ function connection(value, path) {
10173
+ const { host, port } = fieldsFrom(value, path, ["host", "port"], ["host", "port"]);
10174
+ if (typeof host !== "string" || host === "") fail(`${path}.host`, "expected a host");
10175
+ if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535) fail(`${path}.port`, "expected a port from 1 to 65535");
10176
+ return {
10177
+ server: host,
10178
+ server_port: port
10179
+ };
10180
+ }
10181
+ function profileConnection(kind, value, path) {
10182
+ if (kind !== "hysteria" && kind !== "hysteria2") return connection(value, path);
10183
+ const fields = record(value, path);
10184
+ if (!Object.hasOwn(fields, "ports")) return connection(fields, path);
10185
+ const { host, ports } = fieldsFrom(fields, path, ["host", "ports"], ["host", "ports"]);
10186
+ return {
10187
+ server: requiredString(host, `${path}.host`),
10188
+ server_ports: ports
10189
+ };
10190
+ }
10191
+ function usersFor(input, path) {
10192
+ if (!Array.isArray(input) || input.length === 0) fail(path, "expected a non-empty array of Users");
10193
+ const names = /* @__PURE__ */ new Set();
10194
+ return Array.from(input, (value, index) => {
10195
+ const entry = `${path}[${index}]`;
10196
+ if (!isUser(value) || !value.name) fail(entry, "expected a User with a non-empty name");
10197
+ if (names.has(value.name)) fail(entry, "duplicate user name");
10198
+ names.add(value.name);
10199
+ return value;
10200
+ });
10201
+ }
10202
+ function realityKeys(input, path) {
10203
+ const keys = fieldsFrom(input, path, ["privateKey", "publicKey"], ["privateKey", "publicKey"]);
10204
+ const { privateKey, publicKey } = keys;
10205
+ for (const [key, value] of Object.entries(keys)) if (typeof value !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(value) || Buffer.from(value, "base64url").toString("base64url") !== value) fail(`${path}.${key}`, "expected an unpadded 32-byte Base64url key");
10206
+ const der = Buffer.concat([Buffer.from("302e020100300506032b656e04220420", "hex"), Buffer.from(privateKey, "base64url")]);
10207
+ if (createPublicKey(createPrivateKey({
10208
+ key: der,
10209
+ format: "der",
10210
+ type: "pkcs8"
10211
+ })).export({ format: "jwk" }).x !== publicKey) fail(`${path}.publicKey`, "does not match private key");
10212
+ return keys;
10213
+ }
10214
+ function tlsFor(kind, input, needsTls, path) {
10215
+ const { mode } = record(input ?? { mode: "none" }, path);
10216
+ if (mode === "tls") {
10217
+ if (kind === "shadowsocks" || kind === "snell" || kind === "socks" || kind === "shadowtls") fail(path, "TLS is unavailable for this profile");
10218
+ const fields = fieldsFrom(input, path, [
10219
+ "mode",
10220
+ "serverName",
10221
+ "alpn"
10222
+ ]);
10223
+ checkTlsAlpn(kind, fields, path);
10224
+ if (fields.serverName !== void 0 && (typeof fields.serverName !== "string" || !fields.serverName)) fail(`${path}.serverName`, "expected a server name");
10225
+ return {
10226
+ mode,
10227
+ fields
10228
+ };
10229
+ }
10230
+ if (needsTls) fail(path, "requires regular TLS");
10231
+ if (mode === "none") {
10232
+ if (input !== void 0) fieldsFrom(input, path, ["mode"]);
10233
+ return { mode };
10034
10234
  }
10235
+ if (mode !== "reality" || kind !== "vless") fail(`${path}.mode`, "unsupported TLS mode");
10236
+ const fields = fieldsFrom(input, path, [
10237
+ "mode",
10238
+ "serverName",
10239
+ "handshake",
10240
+ "keyPair",
10241
+ "shortId",
10242
+ "shortIds"
10243
+ ], [
10244
+ "serverName",
10245
+ "handshake",
10246
+ "keyPair"
10247
+ ]);
10248
+ if (typeof fields.serverName !== "string" || !fields.serverName) fail(`${path}.serverName`, "expected a server name");
10249
+ if (fields.shortId === void 0 === (fields.shortIds === void 0)) fail(path, "specify either shortId or shortIds");
10250
+ const ids = fields.shortIds ?? [fields.shortId];
10251
+ if (!Array.isArray(ids) || !ids.length || Array.from(ids).some((id) => typeof id !== "string" || !/^(?:[\da-f]{2}){0,8}$/i.test(id)) || new Set(ids.map((id) => id.toLowerCase())).size !== ids.length) fail(`${path}.shortIds`, "expected unique hexadecimal short IDs");
10252
+ const { host, port, ...dial } = record(fields.handshake, `${path}.handshake`);
10253
+ if (Object.hasOwn(dial, "server") || Object.hasOwn(dial, "server_port")) fail(`${path}.handshake`, "use host and port for the handshake address");
10254
+ return {
10255
+ mode,
10256
+ serverName: fields.serverName,
10257
+ keys: realityKeys(fields.keyPair, `${path}.keyPair`),
10258
+ ids,
10259
+ handshake: {
10260
+ ...dial,
10261
+ ...connection({
10262
+ host,
10263
+ port
10264
+ }, `${path}.handshake`)
10265
+ }
10266
+ };
10267
+ }
10268
+ function checkedOptions(value, owned, path) {
10269
+ const fields = record(value ?? {}, path);
10270
+ for (const key of Object.keys(fields)) if (owned.includes(key)) fail(keyPath(path, key), "field is controlled by the profile");
10271
+ return fields;
10272
+ }
10273
+ function protocolOptions(kind, config, hasUsers, sharedKey, path) {
10274
+ const serverFields = {};
10275
+ const clientFields = {};
10276
+ if (sharedKey && config[sharedKey] !== void 0) {
10277
+ serverFields[sharedKey] = config[sharedKey];
10278
+ clientFields[sharedKey] = config[sharedKey];
10279
+ }
10280
+ switch (kind) {
10281
+ case "socks": {
10282
+ const version = config.version ?? "5";
10283
+ if (version !== "4" && version !== "4a" && version !== "5") fail(`${path}.version`, "unsupported SOCKS version");
10284
+ clientFields.version = version;
10285
+ break;
10286
+ }
10287
+ case "snell": {
10288
+ const version = config.version ?? 6;
10289
+ if (version !== 5 && version !== 6) fail(`${path}.version`, "unsupported Snell version");
10290
+ const forbidden = version === 5 ? "mode" : "obfs_mode";
10291
+ if (config[forbidden] !== void 0) fail(`${path}.${forbidden}`, "unavailable for this Snell version");
10292
+ serverFields.version = version;
10293
+ clientFields.version = version === 5 ? 4 : 6;
10294
+ const flag = version === 5 ? "obfs_mode" : "mode";
10295
+ if (config[flag] !== void 0) serverFields[flag] = clientFields[flag] = config[flag];
10296
+ serverFields.psk = clientFields.psk = requiredString(config.psk, `${path}.psk`);
10297
+ break;
10298
+ }
10299
+ case "shadowtls": {
10300
+ const version = config.version ?? 3;
10301
+ if (version !== 1 && version !== 2 && version !== 3) fail(`${path}.version`, "unsupported ShadowTLS version");
10302
+ if (version === 3 ? !hasUsers : hasUsers) fail(`${path}.users`, "users are required for ShadowTLS v3 and unavailable in other versions");
10303
+ if (version === 2) serverFields.password = clientFields.password = requiredString(config.password, `${path}.password`);
10304
+ else if (config.password !== void 0) fail(`${path}.password`, "shared password is available only in ShadowTLS v2");
10305
+ const handshake = record(config.handshake, `${path}.handshake`);
10306
+ connection({
10307
+ host: handshake.server,
10308
+ port: handshake.server_port
10309
+ }, `${path}.handshake`);
10310
+ serverFields.handshake = handshake;
10311
+ requiredString(config.serverName, `${path}.serverName`);
10312
+ serverFields.version = clientFields.version = version;
10313
+ break;
10314
+ }
10315
+ case "shadowsocks": {
10316
+ if (config.managed !== void 0 && typeof config.managed !== "boolean") fail(`${path}.managed`, "expected a boolean");
10317
+ if (config.managed && hasUsers) fail(`${path}.users`, "managed Shadowsocks uses SSM accounts");
10318
+ const method = requiredString(config.method, `${path}.method`);
10319
+ if (config.managed || hasUsers) {
10320
+ if (method === "none" || method === "2022-blake3-chacha20-poly1305") fail(`${path}.method`, "unavailable with multiple Shadowsocks users");
10321
+ if (config.password !== void 0) fail(`${path}.password`, "use User credentials for multiple users");
10322
+ if (method.startsWith("2022-")) serverFields.password = requiredString(config.serverKey, `${path}.serverKey`);
10323
+ else if (config.serverKey !== void 0) fail(`${path}.serverKey`, "requires a Shadowsocks 2022 AES method");
10324
+ if (config.managed) serverFields.managed = true;
10325
+ } else {
10326
+ if (config.serverKey !== void 0) fail(`${path}.serverKey`, "requires multiple users");
10327
+ if (method !== "none") serverFields.password = clientFields.password = requiredString(config.password, `${path}.password`);
10328
+ else if (config.password !== void 0) fail(`${path}.password`, "unavailable with method none");
10329
+ }
10330
+ break;
10331
+ }
10332
+ }
10333
+ return {
10334
+ serverFields,
10335
+ clientFields
10336
+ };
10337
+ }
10338
+ function makeProfile(kind, input) {
10339
+ const path = `proxyProfile.${kind}`;
10340
+ const sharedKey = Object.hasOwn(sharedOption, kind) ? sharedOption[kind] : void 0;
10341
+ const config = snapshot(fieldsFrom(input, path, [
10342
+ "connect",
10343
+ "users",
10344
+ ...kind === "shadowtls" || kind === "shadowsocks" || kind === "snell" || kind === "socks" ? [] : ["tls"],
10345
+ ...transportProtocols.includes(kind) ? ["transport"] : [],
10346
+ ...versioned.includes(kind) ? ["version"] : [],
10347
+ ...sharedKey ? [sharedKey] : [],
10348
+ ...specialFields[kind] ?? []
10349
+ ]), path);
10350
+ const realm = config.realm === void 0 ? void 0 : fieldsFrom(config.realm, `${path}.realm`, [
10351
+ "server_url",
10352
+ "realm_id",
10353
+ "stun_servers",
10354
+ "token"
10355
+ ], [
10356
+ "server_url",
10357
+ "realm_id",
10358
+ "stun_servers"
10359
+ ]);
10360
+ if (realm && config.connect !== void 0) fail(`${path}.connect`, "conflicts with Realm");
10361
+ const connect = realm ? {} : profileConnection(kind, config.connect, `${path}.connect`);
10362
+ const users = config.users === void 0 ? [] : usersFor(config.users, `${path}.users`);
10363
+ if (!optionalUsers.includes(kind) && !users.length) fail(`${path}.users`, "expected at least one User");
10364
+ let transport = {};
10365
+ let transportType = "tcp";
10366
+ if (config.transport !== void 0) {
10367
+ const { type } = record(config.transport, `${path}.transport`);
10368
+ if (typeof type !== "string" || !Object.hasOwn(transportFields, type)) fail(`${path}.transport.type`, "unsupported transport");
10369
+ transportType = type;
10370
+ transport = fieldsFrom(config.transport, `${path}.transport`, ["type", ...transportFields[transportType]]);
10371
+ }
10372
+ const tls = tlsFor(kind, config.tls, tlsRequired.has(kind) || transportType === "quic", `${path}.tls`);
10373
+ if (realm && (tls.mode !== "tls" || !tls.fields.serverName)) fail(`${path}.tls.serverName`, "required for Realm connections");
10374
+ const { serverFields, clientFields } = protocolOptions(kind, config, users.length > 0, sharedKey, path);
10375
+ function credentials(user, location) {
10376
+ if (kind === "socks" && clientFields.version !== "5") {
10377
+ if (requireUserCredentials(user, "socks", location).password !== "") fail(location, "SOCKS4 and SOCKS4a use username-only authentication");
10378
+ return {};
10379
+ }
10380
+ return { ...requireUserCredentials(user, kind, location) };
10381
+ }
10382
+ users.forEach((user, index) => credentials(user, `${path}.users[${index}]`));
10383
+ if (users.length) serverFields.users = users;
10384
+ function sideOptions(input, client) {
10385
+ const location = `${path}.${client ? "client" : "server"}`;
10386
+ const local = fieldsFrom(input, location, [
10387
+ "tag",
10388
+ "options",
10389
+ "tls",
10390
+ "transport",
10391
+ "realm",
10392
+ ...client ? ["dial", "shortId"] : ["listen"]
10393
+ ], ["tag"]);
10394
+ const extra = checkedOptions(local.options, [...client ? ownedClient : ownedServer, ...sharedKey ? [sharedKey] : []], `${location}.options`);
10395
+ let transportOptions = {};
10396
+ if (local.transport !== void 0) {
10397
+ if (transportType === "tcp" || transportType === "quic") fail(`${location}.transport`, "this transport has no side-specific fields");
10398
+ transportOptions = fieldsFrom(local.transport, `${location}.transport`, [...localTransportFields[transportType], ...client && transportType === "grpc" ? grpcClientFields : []]);
10399
+ }
10400
+ let realmOptions = {};
10401
+ if (local.realm !== void 0) {
10402
+ if (!realm) fail(`${location}.realm`, "requires a Realm profile");
10403
+ realmOptions = fieldsFrom(local.realm, `${location}.realm`, [
10404
+ "token",
10405
+ "ip_version",
10406
+ "port_mapping",
10407
+ "http_client",
10408
+ ...client ? [] : ["stun_domain_resolver"]
10409
+ ]);
10410
+ }
10411
+ return {
10412
+ location,
10413
+ local,
10414
+ fields: {
10415
+ ...extra,
10416
+ tag: local.tag,
10417
+ ...transportType === "tcp" ? {} : { transport: {
10418
+ ...transport,
10419
+ ...transportOptions
10420
+ } },
10421
+ ...realm ? { realm: {
10422
+ ...realm,
10423
+ ...realmOptions
10424
+ } } : {}
10425
+ }
10426
+ };
10427
+ }
10428
+ function applyTls(builder, local, location, client) {
10429
+ if (local.shortId !== void 0 && tls.mode !== "reality") fail(`${location}.shortId`, "requires REALITY");
10430
+ if (tls.mode === "reality") {
10431
+ if (local.tls !== void 0) fail(`${location}.tls`, "REALITY settings belong to the profile");
10432
+ if (!client) return builder.tls({
10433
+ side: "server",
10434
+ server_name: tls.serverName,
10435
+ reality: {
10436
+ private_key: tls.keys.privateKey,
10437
+ short_id: tls.ids,
10438
+ handshake: tls.handshake
10439
+ }
10440
+ });
10441
+ const selected = local.shortId ?? (tls.ids.length === 1 ? tls.ids[0] : void 0);
10442
+ if (typeof selected !== "string" || !tls.ids.includes(selected)) fail(`${location}.shortId`, "select a short ID from the profile");
10443
+ return builder.tls({
10444
+ side: "client",
10445
+ server_name: tls.serverName,
10446
+ reality: {
10447
+ public_key: tls.keys.publicKey,
10448
+ short_id: selected
10449
+ }
10450
+ });
10451
+ }
10452
+ if (tls.mode === "tls" || kind === "shadowtls" && client) {
10453
+ const settings = checkedOptions(local.tls, [
10454
+ "enabled",
10455
+ "reality",
10456
+ "side",
10457
+ ...client ? ["server_name"] : [],
10458
+ ...tls.mode === "tls" && tls.fields.alpn !== void 0 ? ["alpn"] : []
10459
+ ], `${location}.tls`);
10460
+ checkTlsAlpn(kind, settings, `${location}.tls`);
10461
+ if (!client && !settings.certificate_provider && (!(settings.certificate || settings.certificate_path) || !(settings.key || settings.key_path))) fail(`${location}.tls`, "expected a certificate and key or certificate provider");
10462
+ return builder.tls({
10463
+ ...settings,
10464
+ enabled: true,
10465
+ ...tls.mode === "tls" && tls.fields.alpn !== void 0 ? { alpn: tls.fields.alpn } : {},
10466
+ ...client ? { server_name: tls.mode === "tls" ? tls.fields.serverName ?? connect.server : config.serverName } : {}
10467
+ });
10468
+ }
10469
+ if (local.tls !== void 0) fail(`${location}.tls`, "TLS must be enabled in the profile");
10470
+ return builder;
10471
+ }
10472
+ return Object.freeze({
10473
+ server(input) {
10474
+ const { local, fields, location } = sideOptions(input, false);
10475
+ let builder = native(inbound[kind], {
10476
+ ...fields,
10477
+ ...serverFields
10478
+ });
10479
+ if (local.listen !== void 0) {
10480
+ const { address, ...listen } = record(local.listen, `${location}.listen`);
10481
+ builder = builder.listen(address, listen);
10482
+ }
10483
+ return applyTls(builder, local, location, false);
10484
+ },
10485
+ client(userOrOptions, options) {
10486
+ const authenticated = users.length > 0 || config.managed === true;
10487
+ if (authenticated && (!isUser(userOrOptions) || !userOrOptions.name || config.managed !== true && !users.includes(userOrOptions))) fail(`${path}.client.user`, "expected a User for this profile");
10488
+ if (!authenticated && options !== void 0) fail(`${path}.client.user`, "profile has no user selection");
10489
+ const { local, fields, location } = sideOptions(authenticated ? options : userOrOptions, true);
10490
+ const selected = isUser(userOrOptions) ? userOrOptions : void 0;
10491
+ const auth = selected ? {
10492
+ ...credentials(selected, `${location}.user`),
10493
+ ...namedClients.includes(kind) ? { username: selected.name } : {}
10494
+ } : {};
10495
+ if (kind === "shadowsocks" && typeof auth.password === "string" && typeof serverFields.password === "string") auth.password = `${serverFields.password}:${auth.password}`;
10496
+ let builder = native(outbound[kind], {
10497
+ ...fields,
10498
+ ...clientFields,
10499
+ ...connect,
10500
+ ...auth
10501
+ });
10502
+ if (local.dial !== void 0) builder = builder.dial(local.dial);
10503
+ return applyTls(builder, local, location, true);
10504
+ }
10505
+ });
10506
+ }
10507
+ function requiredString(input, path) {
10508
+ if (typeof input !== "string" || !input) fail(path, "expected a non-empty string");
10509
+ return input;
10510
+ }
10511
+ function http(input) {
10512
+ return makeProfile("http", input);
10513
+ }
10514
+ function socks(input) {
10515
+ return makeProfile("socks", input);
10516
+ }
10517
+ function snell(input) {
10518
+ return makeProfile("snell", input);
10519
+ }
10520
+ function shadowtls(input) {
10521
+ return makeProfile("shadowtls", input);
10522
+ }
10523
+ function shadowsocks(input) {
10524
+ return makeProfile("shadowsocks", input);
10525
+ }
10526
+ function transportProfile(kind) {
10527
+ function create(input) {
10528
+ return makeProfile(kind, input);
10529
+ }
10530
+ return create;
10531
+ }
10532
+ const proxyProfile = Object.freeze({
10533
+ anytls: (input) => makeProfile("anytls", input),
10534
+ http,
10535
+ hysteria: (input) => makeProfile("hysteria", input),
10536
+ hysteria2: (input) => makeProfile("hysteria2", input),
10537
+ naive: (input) => makeProfile("naive", input),
10538
+ shadowsocks,
10539
+ shadowtls,
10540
+ snell,
10541
+ socks,
10542
+ trojan: transportProfile("trojan"),
10543
+ tuic: (input) => makeProfile("tuic", input),
10544
+ vless: transportProfile("vless"),
10545
+ vmess: transportProfile("vmess")
10035
10546
  });
10036
- export { Rule, certificateProvider, compile, dns, dnsServer, endpoint, httpClient, inbound, networkNamespace, outbound, route, ruleSet, service, user, validateConfig };
10547
+ export { Rule, certificateProvider, compile, dns, dnsServer, endpoint, httpClient, inbound, networkNamespace, outbound, proxyProfile, route, ruleSet, service, user, validateConfig };