dsh-provider-proxy 0.5.0 → 0.5.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 +23 -10
- package/lib/client.js +189 -71
- package/lib/client.js.map +2 -2
- package/lib/index.js +42 -24
- package/lib/index.js.map +3 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -134,6 +134,42 @@ import { ProxyAgent, Socks5ProxyAgent } from "undici";
|
|
|
134
134
|
// src/config.ts
|
|
135
135
|
import { createRequire } from "node:module";
|
|
136
136
|
|
|
137
|
+
// src/proxy-address.ts
|
|
138
|
+
var PROXY_HOST_INVALID = "\u4EE3\u7406\u5730\u5740\u53EA\u80FD\u586B IPv4\u3001IPv6 \u6216\u57DF\u540D";
|
|
139
|
+
var IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
|
|
140
|
+
var DOMAIN = /^(?=.*[a-z])(?=.{1,253}$)(?!.*\.\d+$)[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?)*$/i;
|
|
141
|
+
var IPV6_CHARS = /^[0-9a-f:.]+$/i;
|
|
142
|
+
function proxyHostProblem(rawHost) {
|
|
143
|
+
const host = (rawHost ?? "").trim().replace(/\.$/, "");
|
|
144
|
+
if (host.length === 0) return "\u672A\u586B\u5199\u4EE3\u7406\u5730\u5740";
|
|
145
|
+
if (IPV4.test(host)) return void 0;
|
|
146
|
+
if (host.includes(":") || host.startsWith("[")) {
|
|
147
|
+
const literal = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
148
|
+
if (!IPV6_CHARS.test(literal)) return PROXY_HOST_INVALID;
|
|
149
|
+
try {
|
|
150
|
+
new URL(`http://[${literal}]:1`);
|
|
151
|
+
return void 0;
|
|
152
|
+
} catch {
|
|
153
|
+
return PROXY_HOST_INVALID;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return DOMAIN.test(host) ? void 0 : PROXY_HOST_INVALID;
|
|
157
|
+
}
|
|
158
|
+
function defaultProxyProblem(endpoint) {
|
|
159
|
+
const hostProblem = proxyHostProblem(endpoint.host);
|
|
160
|
+
if (hostProblem !== void 0) return hostProblem;
|
|
161
|
+
const port = endpoint.port ?? 0;
|
|
162
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
163
|
+
return "\u4EE3\u7406\u7AEF\u53E3\u65E0\u6548\uFF08\u9700\u4E3A 1-65535 \u7684\u6574\u6570\uFF09";
|
|
164
|
+
}
|
|
165
|
+
const hasUser = (endpoint.username ?? "").trim().length > 0;
|
|
166
|
+
const hasPassword = (endpoint.password ?? "").length > 0;
|
|
167
|
+
if (hasUser !== hasPassword) {
|
|
168
|
+
return hasUser ? "\u914D\u7F6E\u4E86\u4EE3\u7406\u7528\u6237\u540D\u4F46\u6CA1\u6709\u5BC6\u7801\uFF1B\u8BF7\u8865\u5168\u5BC6\u7801\u6216\u6E05\u7A7A\u7528\u6237\u540D" : "\u914D\u7F6E\u4E86\u4EE3\u7406\u5BC6\u7801\u4F46\u6CA1\u6709\u7528\u6237\u540D\uFF1B\u8BF7\u8865\u5168\u7528\u6237\u540D\u6216\u6E05\u7A7A\u5BC6\u7801";
|
|
169
|
+
}
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
137
173
|
// node_modules/@deepseek-ai/schemastery/lib/index.mjs
|
|
138
174
|
var lib_exports = {};
|
|
139
175
|
__export(lib_exports, {
|
|
@@ -1117,11 +1153,11 @@ function normalizeRoute(provider, raw, options) {
|
|
|
1117
1153
|
return { ...value, port: value.port || 0, onlyHosts, bypassHosts, testTarget };
|
|
1118
1154
|
}
|
|
1119
1155
|
const host = value.host.trim();
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1156
|
+
const hostProblem = proxyHostProblem(host);
|
|
1157
|
+
if (hostProblem !== void 0) {
|
|
1158
|
+
throw new TypeError(
|
|
1159
|
+
hostProblem === "\u672A\u586B\u5199\u4EE3\u7406\u5730\u5740" ? `dsh-provider-proxy: provider "${provider}" \u542F\u7528\u4E86\u4EE3\u7406\uFF0C\u4F46\u672A\u586B\u5199\u4EE3\u7406\u5730\u5740` : `dsh-provider-proxy: provider "${provider}" \u7684${hostProblem}`
|
|
1160
|
+
);
|
|
1125
1161
|
}
|
|
1126
1162
|
if (!Number.isInteger(value.port) || value.port < 1 || value.port > 65535) {
|
|
1127
1163
|
throw new TypeError(
|
|
@@ -1131,25 +1167,6 @@ function normalizeRoute(provider, raw, options) {
|
|
|
1131
1167
|
return { ...value, host, username: value.username.trim(), onlyHosts, bypassHosts, testTarget };
|
|
1132
1168
|
}
|
|
1133
1169
|
|
|
1134
|
-
// src/proxy-address.ts
|
|
1135
|
-
function defaultProxyProblem(endpoint) {
|
|
1136
|
-
const host = (endpoint.host ?? "").trim();
|
|
1137
|
-
if (host.length === 0) return "\u672A\u586B\u5199\u4EE3\u7406\u5730\u5740";
|
|
1138
|
-
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(host) || host.includes("/")) {
|
|
1139
|
-
return "\u4EE3\u7406\u5730\u5740\u53EA\u586B\u4E3B\u673A\u540D\u6216 IP\uFF0C\u4E0D\u8981\u5E26\u534F\u8BAE\u524D\u7F00\u6216\u8DEF\u5F84";
|
|
1140
|
-
}
|
|
1141
|
-
const port = endpoint.port ?? 0;
|
|
1142
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
1143
|
-
return "\u4EE3\u7406\u7AEF\u53E3\u65E0\u6548\uFF08\u9700\u4E3A 1-65535 \u7684\u6574\u6570\uFF09";
|
|
1144
|
-
}
|
|
1145
|
-
const hasUser = (endpoint.username ?? "").length > 0;
|
|
1146
|
-
const hasPassword = (endpoint.password ?? "").length > 0;
|
|
1147
|
-
if (hasUser !== hasPassword) {
|
|
1148
|
-
return hasUser ? "\u914D\u7F6E\u4E86\u4EE3\u7406\u7528\u6237\u540D\u4F46\u6CA1\u6709\u5BC6\u7801\uFF1B\u8BF7\u8865\u5168\u5BC6\u7801\u6216\u6E05\u7A7A\u7528\u6237\u540D" : "\u914D\u7F6E\u4E86\u4EE3\u7406\u5BC6\u7801\u4F46\u6CA1\u6709\u7528\u6237\u540D\uFF1B\u8BF7\u8865\u5168\u7528\u6237\u540D\u6216\u6E05\u7A7A\u5BC6\u7801";
|
|
1149
|
-
}
|
|
1150
|
-
return void 0;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
1170
|
// src/proxy-table.ts
|
|
1154
1171
|
function proxyUrl(route) {
|
|
1155
1172
|
const credentials = route.username.length === 0 ? "" : route.password.length > 0 && route.protocol !== "socks5" ? `${encodeURIComponent(route.username)}:${encodeURIComponent(route.password)}@` : `${encodeURIComponent(route.username)}@`;
|
|
@@ -1797,6 +1814,7 @@ export {
|
|
|
1797
1814
|
name,
|
|
1798
1815
|
normalizeDefaultProxy,
|
|
1799
1816
|
normalizeRoute,
|
|
1817
|
+
proxyHostProblem,
|
|
1800
1818
|
proxyUrl
|
|
1801
1819
|
};
|
|
1802
1820
|
//# sourceMappingURL=index.js.map
|