@vmosedge/proxy-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VMOS Edge
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # VMOS Edge Proxy SDK
2
+
3
+ 一个用于管理和运行代理服务的 Node.js SDK。支持多协议解析和链式代理请求。
4
+
5
+ ## 特性
6
+
7
+ - **多协议支持**: 自动解析 VLESS, VMESS, SS, SSR, Trojan, TUIC, Hysteria, Hysteria2, Wireguard, HTTP, SOCKS5 等多种代理 URI。
8
+ - **内置二进制**: 自动识别并运行对应平台的二进制文件(支持 Windows, macOS, Linux)。
9
+ - **链式代理**: 支持将多个代理节点串联成代理链。
10
+ - **一键请求**: 提供简便的 API 直接通过代理发起 HTTP/HTTPS 请求。
11
+ - **状态透明**: 所有异步方法均返回统一的响应格式,明确暴露成功或失败状态。
12
+ - **生命周期管理**: 自动管理工作目录、配置文件并在进程退出时自动清理。
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install @vmosedge/proxy-sdk
18
+ ```
19
+
20
+ ## 快速开始
21
+
22
+ ### 发起代理请求
23
+
24
+ 可以直接使用代理 URI 发起请求,SDK 会自动启动代理服务并在请求完成后关闭。
25
+
26
+ ```typescript
27
+ import { VMOSEdgeProxy } from '@vmosedge/proxy-sdk';
28
+
29
+ const proxy = new VMOSEdgeProxy();
30
+
31
+ async function run() {
32
+ const vlessNode = 'vless://...';
33
+ const vmessNode = 'vmess://...';
34
+
35
+ // 链式代理示例 (节点1 -> 节点2)
36
+ const res = await proxy.request(
37
+ [vlessNode, vmessNode],
38
+ { url: 'https://api.ipify.org?format=json' },
39
+ { 'mixed-port': 10086 }
40
+ );
41
+
42
+ if (res.success) {
43
+ console.log('Your IP Info:', res.data);
44
+ } else {
45
+ console.error('Request failed:', res.error);
46
+ }
47
+ }
48
+
49
+ run();
50
+ ```
51
+
52
+ ### 手动管理代理服务
53
+
54
+ 如果需要持久运行代理服务或手动控制开关。
55
+
56
+ ```typescript
57
+ import { VMOSEdgeProxy } from '@vmosedge/proxy-sdk';
58
+
59
+ const proxy = new VMOSEdgeProxy();
60
+
61
+ async function startProxy() {
62
+ const res = await proxy.start({
63
+ "mixed-port": 10809,
64
+ "proxies": []
65
+ });
66
+
67
+ if (res.success) {
68
+ console.log('代理服务已启动,监听端口 10809');
69
+ } else {
70
+ console.error('启动失败:', res.error);
71
+ }
72
+ }
73
+
74
+ // 停止服务
75
+ // proxy.stop();
76
+ ```
77
+
78
+ ## API
79
+
80
+ ### `new VMOSEdgeProxy(config?: ProxyConfig)`
81
+ 初始化 SDK。
82
+ - `config.timeout`: 默认启动超时时间(毫秒)。
83
+ - `config.logLevel`: 日志级别 (`debug`, `info`, `warn`, `error`, `none`)。
84
+
85
+ ### `async start(config?: any, timeout?: number): Promise<ProxyResponse>`
86
+ 启动代理服务。
87
+ - `config`: 配置文件对象。
88
+ - `timeout`: 启动超时时间(毫秒)。
89
+
90
+ ### `async reload(config?: any): Promise<ProxyResponse>`
91
+ 重新加载配置而不停止进程。
92
+
93
+ ### `async request(proxies: (string|any)[], req: AxiosRequestConfig, config?: any): Promise<ProxyResponse>`
94
+ 通过代理链发起单次请求。
95
+ - `proxies`: 代理 URI 或配置对象数组。
96
+ - `req`: Axios 请求配置。
97
+ - `config`: 额外的全局配置。
98
+
99
+ ### `stop(): ProxyResponse`
100
+ 停止代理服务。
101
+
102
+ ## 响应格式
103
+
104
+ 所有异步方法返回 `ProxyResponse` 对象:
105
+ ```typescript
106
+ interface ProxyResponse<T = any> {
107
+ success: boolean;
108
+ data?: T;
109
+ error?: string;
110
+ }
111
+ ```
112
+
113
+ ## 许可证
114
+
115
+ MIT
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,27 @@
1
+ {
2
+ "mixed-port": 7891,
3
+ "allow-lan": false,
4
+ "mode": "rule",
5
+ "log-level": "info",
6
+ "unified-delay": true,
7
+ "tcp-concurrent": true,
8
+ "dns": {
9
+ "enable": true,
10
+ "ipv6": false,
11
+ "proxy-server-nameserver": [
12
+ "223.5.5.5",
13
+ "8.8.8.8",
14
+ "https://dns.alidns.com/dns-query",
15
+ "https://dns.google/dns-query"
16
+ ],
17
+ "nameserver": [
18
+ "223.5.5.5",
19
+ "8.8.8.8",
20
+ "https://dns.alidns.com/dns-query",
21
+ "https://dns.google/dns-query"
22
+ ]
23
+ },
24
+ "proxies": [],
25
+ "proxy-groups": [],
26
+ "rules": []
27
+ }
@@ -0,0 +1,60 @@
1
+ import { ProxyResponse, ProxyConfig } from "./types";
2
+ export * from "./types";
3
+ export * from "./uri-parser/types";
4
+ export { default as parseUri } from "./uri-parser";
5
+ export declare class VMOSEdgeProxy {
6
+ private process;
7
+ private binPath;
8
+ private workingDir;
9
+ private logLevel;
10
+ private isStopped;
11
+ private logsDir;
12
+ private logRetentionMs;
13
+ private sessionId;
14
+ private sessionLogStream;
15
+ private stdoutLogStream;
16
+ private stderrLogStream;
17
+ private instanceId;
18
+ private startCount;
19
+ private exitHandler;
20
+ private sigintHandler;
21
+ private sigtermHandler;
22
+ private uncaughtHandler;
23
+ private rejectionHandler;
24
+ constructor(config?: ProxyConfig);
25
+ /** 初始化日志系统 */
26
+ private initLogging;
27
+ /** 确保日志流可用(多次 start 时重新打开) */
28
+ private ensureLogStreams;
29
+ /** 清理过期的日志会话目录 */
30
+ private cleanupExpiredLogs;
31
+ /** 关闭所有日志流 */
32
+ private closeLogStreams;
33
+ /** 写入会话日志文件 */
34
+ private writeLog;
35
+ /** 记录内存快照到日志 */
36
+ private logMemorySnapshot;
37
+ /**
38
+ * 移除全局事件监听器
39
+ */
40
+ private removeEventListeners;
41
+ private log;
42
+ /** 将启动配置保存到日志目录 */
43
+ private saveConfigSnapshot;
44
+ start(config?: any, timeout?: number): Promise<ProxyResponse>;
45
+ private startInternal;
46
+ /** 检查 mihomo 启动输出中的关键字 */
47
+ private checkStartupOutput;
48
+ reload(config?: any): Promise<ProxyResponse>;
49
+ /**
50
+ * One-shot request: starts proxy, makes request, then stops proxy
51
+ * If multiple proxies are provided, they will be chained using dialer-proxy
52
+ */
53
+ request(proxies: (any | string)[], req: {
54
+ url: string;
55
+ timeout?: number;
56
+ }, config?: any): Promise<ProxyResponse>;
57
+ /** 仅终止子进程,不做完整 stop(给 start 内部复用) */
58
+ private killProcess;
59
+ stop(): ProxyResponse;
60
+ }