@frp-bridge/core 0.0.2 → 0.0.4

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.d.ts CHANGED
@@ -1,177 +1,719 @@
1
- import { NodeRegisterPayload, NodeHeartbeatPayload, NodeInfo as NodeInfo$1, NodeListQuery, NodeListResponse, NodeStatistics, TunnelSyncPayload, ProxyConfig, ClientConfig, ServerConfig, RpcRequest } from '@frp-bridge/types';
2
- import { EventEmitter } from 'node:events';
1
+ import { EventEmitter } from "node:events";
3
2
 
3
+ //#region src/runtime/contracts.d.ts
4
4
  type Awaitable<T> = T | Promise<T>;
5
5
  type RuntimeMode = 'client' | 'server';
6
6
  type RuntimeStatus = 'idle' | 'starting' | 'running' | 'stopping' | 'error';
7
7
  interface RuntimeContext {
8
- id: string;
9
- mode: RuntimeMode;
10
- workDir: string;
11
- platform: string;
12
- clock?: () => number;
13
- logger?: RuntimeLogger;
8
+ id: string;
9
+ mode: RuntimeMode;
10
+ workDir: string;
11
+ platform: string;
12
+ clock?: () => number;
14
13
  }
15
14
  interface RuntimeLogger {
16
- debug: (message: string, context?: Record<string, unknown>) => void;
17
- info: (message: string, context?: Record<string, unknown>) => void;
18
- warn: (message: string, context?: Record<string, unknown>) => void;
19
- error: (message: string, context?: Record<string, unknown>) => void;
15
+ debug: (message: string, context?: Record<string, unknown>) => void;
16
+ info: (message: string, context?: Record<string, unknown>) => void;
17
+ warn: (message: string, context?: Record<string, unknown>) => void;
18
+ error: (message: string, context?: Record<string, unknown>) => void;
20
19
  }
21
20
  interface RuntimeState {
22
- status: RuntimeStatus;
23
- version: number;
24
- lastAppliedAt?: number;
25
- lastError?: RuntimeError;
21
+ status: RuntimeStatus;
22
+ version: number;
23
+ lastAppliedAt?: number;
24
+ lastError?: RuntimeError;
26
25
  }
27
26
  interface CommandMetadata {
28
- requestId?: string;
29
- correlationId?: string;
30
- author?: string;
31
- issuedAt?: number;
27
+ requestId?: string;
28
+ correlationId?: string;
29
+ author?: string;
30
+ issuedAt?: number;
32
31
  }
33
32
  interface RuntimeCommand<TPayload = unknown> {
34
- name: string;
35
- payload: TPayload;
36
- metadata?: CommandMetadata;
33
+ name: string;
34
+ payload: TPayload;
35
+ metadata?: CommandMetadata;
37
36
  }
38
37
  interface CommandResult<TResult = unknown> {
39
- status: CommandStatus;
40
- version?: number;
41
- events?: RuntimeEvent[];
42
- result?: TResult;
43
- error?: RuntimeError;
44
- snapshot?: ConfigSnapshot;
38
+ status: CommandStatus;
39
+ version?: number;
40
+ events?: RuntimeEvent[];
41
+ result?: TResult;
42
+ error?: RuntimeError;
43
+ snapshot?: ConfigSnapshot;
45
44
  }
46
45
  type CommandStatus = 'success' | 'failed' | 'pending';
47
46
  interface RuntimeQuery<TPayload = unknown> {
48
- name: string;
49
- payload?: TPayload;
47
+ name: string;
48
+ payload?: TPayload;
50
49
  }
51
50
  interface QueryResult<TResult = unknown> {
52
- result: TResult;
53
- version: number;
51
+ result: TResult;
52
+ version: number;
54
53
  }
55
54
  interface RuntimeEvent<TPayload = unknown> {
56
- type: string;
57
- timestamp: number;
58
- version?: number;
59
- payload?: TPayload;
55
+ type: string;
56
+ timestamp: number;
57
+ version?: number;
58
+ payload?: TPayload;
60
59
  }
61
60
  interface RuntimeError {
62
- code: RuntimeErrorCode;
63
- message: string;
64
- details?: Record<string, unknown>;
61
+ code: RuntimeErrorCode;
62
+ message: string;
63
+ details?: Record<string, unknown>;
65
64
  }
66
- type RuntimeErrorCode = 'VALIDATION_ERROR' | 'RUNTIME_ERROR' | 'SYSTEM_ERROR' | 'PORT_CONFLICT' | 'RPC_NOT_AVAILABLE' | 'RPC_ERROR';
65
+ type RuntimeErrorCode = 'VALIDATION_ERROR' | 'RUNTIME_ERROR' | 'SYSTEM_ERROR' | 'PORT_CONFLICT' | 'RPC_NOT_AVAILABLE' | 'RPC_ERROR' | 'MODE_ERROR' | 'UNKNOWN_ERROR';
67
66
  interface ConfigSnapshot {
68
- version: number;
69
- checksum: string;
70
- appliedAt: number;
71
- author?: string;
72
- summary?: string;
67
+ version: number;
68
+ checksum: string;
69
+ appliedAt: number;
70
+ author?: string;
71
+ summary?: string;
73
72
  }
74
73
  interface SnapshotStorage {
75
- save: (snapshot: ConfigSnapshot) => Awaitable<void>;
76
- load: (version: number) => Awaitable<ConfigSnapshot | undefined>;
77
- list: () => Awaitable<ConfigSnapshot[]>;
74
+ save: (snapshot: ConfigSnapshot) => Awaitable<void>;
75
+ load: (version: number) => Awaitable<ConfigSnapshot | undefined>;
76
+ list: () => Awaitable<ConfigSnapshot[]>;
78
77
  }
79
78
  interface CommandHandlerContext {
80
- context: RuntimeContext;
81
- state: RuntimeState;
82
- emit: (events: RuntimeEvent[]) => void;
83
- requestVersionBump: () => number;
79
+ context: RuntimeContext;
80
+ state: RuntimeState;
81
+ emit: (events: RuntimeEvent[]) => void;
82
+ requestVersionBump: () => number;
84
83
  }
85
84
  type CommandHandler<TPayload = unknown, TResult = unknown> = (command: RuntimeCommand<TPayload>, ctx: CommandHandlerContext) => Awaitable<CommandResult<TResult>>;
86
85
  type QueryHandler<TPayload = unknown, TResult = unknown> = (query: RuntimeQuery<TPayload>, ctx: RuntimeContext) => Awaitable<QueryResult<TResult>>;
87
86
  interface RuntimeAdapters {
88
- storage?: SnapshotStorage;
89
- commands?: Record<string, CommandHandler>;
90
- queries?: Record<string, QueryHandler>;
87
+ storage?: SnapshotStorage;
88
+ commands?: Record<string, CommandHandler>;
89
+ queries?: Record<string, QueryHandler>;
91
90
  }
92
-
91
+ //#endregion
92
+ //#region src/runtime/runtime.d.ts
93
93
  declare class FrpRuntime {
94
- private readonly context;
95
- private readonly storage?;
96
- private readonly commandHandlers;
97
- private readonly queryHandlers;
98
- private eventBuffer;
99
- private commandQueue;
100
- private state;
101
- constructor(context: RuntimeContext, adapters?: RuntimeAdapters);
102
- registerCommand(name: string, handler: CommandHandler): void;
103
- registerQuery(name: string, handler: QueryHandler): void;
104
- execute<TPayload, TResult = unknown>(command: RuntimeCommand<TPayload>): Promise<CommandResult<TResult>>;
105
- query<TPayload, TResult = unknown>(query: RuntimeQuery<TPayload>): Promise<QueryResult<TResult>>;
106
- snapshot(): RuntimeState;
107
- drainEvents(): RuntimeEvent[];
108
- private runCommand;
109
- private pushEvents;
110
- private bumpVersion;
111
- private persistSnapshot;
112
- private normalizeError;
113
- private buildError;
114
- private now;
94
+ private readonly context;
95
+ private readonly storage?;
96
+ private readonly commandHandlers;
97
+ private readonly queryHandlers;
98
+ private eventBuffer;
99
+ private commandQueue;
100
+ private state;
101
+ constructor(context: RuntimeContext, adapters?: RuntimeAdapters);
102
+ registerCommand(name: string, handler: CommandHandler): void;
103
+ registerQuery(name: string, handler: QueryHandler): void;
104
+ execute<TPayload, TResult = unknown>(command: RuntimeCommand<TPayload>): Promise<CommandResult<TResult>>;
105
+ query<TPayload, TResult = unknown>(query: RuntimeQuery<TPayload>): Promise<QueryResult<TResult>>;
106
+ snapshot(): RuntimeState;
107
+ drainEvents(): RuntimeEvent[];
108
+ private runCommand;
109
+ private pushEvents;
110
+ private bumpVersion;
111
+ private persistSnapshot;
112
+ private normalizeError;
113
+ private buildError;
114
+ private now;
115
115
  }
116
-
116
+ //#endregion
117
+ //#region ../types/src/common.d.ts
117
118
  /**
118
- * Client-side node information collector
119
- * Gathers system information and reports to server via heartbeat
119
+ * FRP 通用配置类型定义
120
+ * 基于 frp 官方文档: https://gofrp.org/zh-cn/docs/reference/common/
120
121
  */
121
-
122
- interface ClientCollectorOptions {
123
- /** Node ID (set by server after registration) */
124
- nodeId?: string;
125
- /** Heartbeat interval in milliseconds (default: 30000) */
126
- heartbeatInterval?: number;
127
- /** Logger instance */
128
- logger?: {
129
- debug?: (msg: string, data?: unknown) => void;
130
- info?: (msg: string, data?: unknown) => void;
131
- error?: (msg: string, error?: unknown) => void;
122
+ /** 日志级别类型 */
123
+ type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
124
+ /** 日志配置 */
125
+ interface LogConfig {
126
+ /** 日志输出文件路径,如果为 console,则会将日志打印在标准输出中 */
127
+ to?: string;
128
+ /** 日志级别,可选值为 trace, debug, info, warn, error,默认级别为 info */
129
+ level?: LogLevel;
130
+ /** 日志文件最多保留天数,默认为 3 */
131
+ maxDays?: number;
132
+ /** 禁用标准输出中的日志颜色 */
133
+ disablePrintColor?: boolean;
134
+ }
135
+ /** TLS 配置 */
136
+ interface TLSConfig {
137
+ /** TLS 证书文件路径 */
138
+ certFile: string;
139
+ /** TLS 密钥文件路径 */
140
+ keyFile: string;
141
+ /** CA 证书文件路径 */
142
+ trustedCaFile?: string;
143
+ /** TLS Server 名称 */
144
+ serverName?: string;
145
+ }
146
+ /** Web 服务器配置 */
147
+ interface WebServerConfig {
148
+ /** webServer 监听地址,默认为 127.0.0.1 */
149
+ addr?: string;
150
+ /** webServer 监听端口 */
151
+ port: number;
152
+ /** HTTP BasicAuth 用户名 */
153
+ user?: string;
154
+ /** HTTP BasicAuth 密码 */
155
+ password?: string;
156
+ /** 静态资源目录,Dashboard 使用的资源默认打包在二进制文件中,通过指定此参数使用自定义的静态资源 */
157
+ assetsDir?: string;
158
+ /** 启动 Go HTTP pprof,用于应用调试 */
159
+ pprofEnable?: boolean;
160
+ /** Dashboard 启用 HTTPS 的 TLS 相关配置 */
161
+ tls?: TLSConfig;
162
+ }
163
+ /** QUIC 协议选项 */
164
+ interface QUICOptions {
165
+ /** 保活周期,默认值为 10 秒 */
166
+ keepalivePeriod?: number;
167
+ /** 最大空闲超时时间,默认值为 30 秒 */
168
+ maxIdleTimeout?: number;
169
+ /** 最大传入流数量,默认值为 100000 */
170
+ maxIncomingStreams?: number;
171
+ }
172
+ /** 端口范围配置 */
173
+ interface PortsRange {
174
+ /** 起始端口 */
175
+ start?: number;
176
+ /** 终止端口 */
177
+ end?: number;
178
+ /** 单一端口 */
179
+ single?: number;
180
+ }
181
+ /** 文件数据源配置 */
182
+ interface FileSource {
183
+ /** 文件路径 */
184
+ path: string;
185
+ }
186
+ /** 数据源类型 */
187
+ type ValueSourceType = 'file';
188
+ /** 值数据源配置 */
189
+ interface ValueSource {
190
+ /** 数据源类型,目前仅支持 "file" */
191
+ type: ValueSourceType;
192
+ /** 文件数据源配置,当 type 为 "file" 时必填 */
193
+ file?: FileSource;
194
+ }
195
+ //#endregion
196
+ //#region ../types/src/server.d.ts
197
+ /** 鉴权方式类型 */
198
+ type AuthMethod = 'token' | 'oidc';
199
+ /** 鉴权信息附加范围类型 */
200
+ type AuthScope = 'HeartBeats' | 'NewWorkConns';
201
+ /** OIDC 服务端鉴权配置 */
202
+ interface AuthOIDCServerConfig {
203
+ /** OIDC 发行者 */
204
+ issuer?: string;
205
+ /** OIDC 受众 */
206
+ audience?: string;
207
+ /** 跳过过期检查 */
208
+ skipExpiryCheck?: boolean;
209
+ /** 跳过发行者检查 */
210
+ skipIssuerCheck?: boolean;
211
+ }
212
+ /** 服务端鉴权配置 */
213
+ interface AuthServerConfig {
214
+ /** 鉴权方式,可选值为 token 或 oidc,默认为 token */
215
+ method?: AuthMethod;
216
+ /** 鉴权信息附加范围,可选值为 HeartBeats 和 NewWorkConns */
217
+ additionalScopes?: AuthScope[];
218
+ /** 在 method 为 token 时生效,客户端需要设置一样的值才能鉴权通过。与 tokenSource 字段互斥 */
219
+ token?: string;
220
+ /** 从文件中加载 token 的配置。与 token 字段互斥 */
221
+ tokenSource?: ValueSource;
222
+ /** oidc 鉴权配置 */
223
+ oidc?: AuthOIDCServerConfig;
224
+ }
225
+ /** 服务端 TLS 配置 */
226
+ interface TLSServerConfig extends TLSConfig {
227
+ /** 是否只接受启用了 TLS 的客户端连接 */
228
+ force?: boolean;
229
+ }
230
+ /** 服务端传输层配置 */
231
+ interface ServerTransportConfig {
232
+ /** tcp mux 的心跳检查间隔时间,单位秒 */
233
+ tcpMuxKeepaliveInterval?: number;
234
+ /** 和客户端底层 TCP 连接的 keepalive 间隔时间,单位秒,配置为负数表示不启用 */
235
+ tcpKeepalive?: number;
236
+ /** 允许客户端设置的最大连接池大小,如果客户端配置的值大于此值,会被强制修改为最大值,默认为 5 */
237
+ maxPoolCount?: number;
238
+ /** 服务端和客户端心跳连接的超时时间,单位秒,默认为 90 秒 */
239
+ heartbeatTimeout?: number;
240
+ /** QUIC 协议配置参数 */
241
+ quic?: QUICOptions;
242
+ /** 服务端 TLS 协议配置 */
243
+ tls?: TLSServerConfig;
244
+ }
245
+ /** HTTP 插件选项 */
246
+ interface HTTPPluginOptions {
247
+ /** 插件名称 */
248
+ name: string;
249
+ /** 插件接口的地址 */
250
+ addr: string;
251
+ /** 插件接口的 Path */
252
+ path: string;
253
+ /** 插件需要生效的操作列表,具体可选值请参考服务端插件的说明文档 */
254
+ ops: string[];
255
+ /** 当插件地址为 HTTPS 协议时,是否校验插件的 TLS 证书,默认为不校验 */
256
+ tlsVerify?: boolean;
257
+ }
258
+ /** SSH 隧道网关配置 */
259
+ interface SSHTunnelGateway {
260
+ /** SSH 服务器监听端口 */
261
+ bindPort: number;
262
+ /** SSH 服务器私钥文件路径。若为空,frps将读取autoGenPrivateKeyPath路径下的私钥文件 */
263
+ privateKeyFile?: string;
264
+ /** 私钥文件自动生成路径,默认为./.autogen_ssh_key。若文件不存在或内容为空,frps将自动生成RSA私钥文件并存储到该路径 */
265
+ autoGenPrivateKeyPath?: string;
266
+ /** SSH 客户端授权密钥文件路径。若为空,则不进行SSH客户端鉴权认证。非空可实现SSH免密登录认证 */
267
+ authorizedKeysFile?: string;
268
+ }
269
+ /** 服务端配置 */
270
+ interface ServerConfig {
271
+ /** 鉴权配置 */
272
+ auth?: AuthServerConfig;
273
+ /** 服务端监听地址,用于接收 frpc 的连接,默认监听 0.0.0.0 */
274
+ bindAddr?: string;
275
+ /** 服务端监听端口,默认值为 7000 */
276
+ bindPort?: number;
277
+ /** 服务端监听 KCP 协议端口,用于接收配置了使用 KCP 协议的 frpc 连接 */
278
+ kcpBindPort?: number;
279
+ /** 服务端监听 QUIC 协议端口,用于接收配置了使用 QUIC 协议的 frpc 连接 */
280
+ quicBindPort?: number;
281
+ /** 代理监听地址,可以使代理监听在不同的网卡地址,默认情况下同 bindAddr */
282
+ proxyBindAddr?: string;
283
+ /** HTTP 类型代理监听的端口,启用后才能支持 HTTP 类型的代理 */
284
+ vhostHTTPPort?: number;
285
+ /** HTTP 类型代理在服务端的 ResponseHeader 超时时间,默认为 60s */
286
+ vhostHTTPTimeout?: number;
287
+ /** HTTPS 类型代理监听的端口,启用后才能支持 HTTPS 类型的代理 */
288
+ vhostHTTPSPort?: number;
289
+ /** tcpmux 类型且复用器为 httpconnect 的代理监听的端口 */
290
+ tcpmuxHTTPConnectPort?: number;
291
+ /** 对于 tcpmux 类型的代理是否透传 CONNECT 请求 */
292
+ tcpmuxPassthrough?: boolean;
293
+ /** 二级域名后缀 */
294
+ subDomainHost?: string;
295
+ /** 自定义 404 错误页面地址 */
296
+ custom404Page?: string;
297
+ /** ssh 隧道网关配置 */
298
+ sshTunnelGateway?: SSHTunnelGateway;
299
+ /** 服务端 Dashboard 配置 */
300
+ webServer?: WebServerConfig;
301
+ /** 是否提供 Prometheus 监控接口,需要同时启用了 webServer 后才会生效 */
302
+ enablePrometheus?: boolean;
303
+ /** 日志配置 */
304
+ log?: LogConfig;
305
+ /** 网络层配置 */
306
+ transport?: ServerTransportConfig;
307
+ /** 服务端返回详细错误信息给客户端,默认为 true */
308
+ detailedErrorsToClient?: boolean;
309
+ /** 限制单个客户端最大同时存在的代理数,默认无限制 */
310
+ maxPortsPerClient?: number;
311
+ /** 用户建立连接后等待客户端响应的超时时间,单位秒,默认为 10 秒 */
312
+ userConnTimeout?: number;
313
+ /** 代理 UDP 服务时支持的最大包长度,默认为 1500,服务端和客户端的值需要一致 */
314
+ udpPacketSize?: number;
315
+ /** 打洞策略数据的保留时间,默认为 168 小时,即 7 天 */
316
+ natholeAnalysisDataReserveHours?: number;
317
+ /** 允许代理绑定的服务端端口 */
318
+ allowPorts?: PortsRange[];
319
+ /** 服务端 HTTP 插件配置 */
320
+ httpPlugins?: HTTPPluginOptions[];
321
+ }
322
+ //#endregion
323
+ //#region ../types/src/client.d.ts
324
+ /** 客户端传输协议类型 */
325
+ type ClientTransportProtocol = 'tcp' | 'kcp' | 'quic' | 'websocket' | 'wss';
326
+ /** OIDC 客户端鉴权配置 */
327
+ interface AuthOIDCClientConfig {
328
+ /** OIDC 客户端 ID */
329
+ clientID?: string;
330
+ /** OIDC 客户端密钥 */
331
+ clientSecret?: string;
332
+ /** OIDC audience 参数 */
333
+ audience?: string;
334
+ /** OIDC scope 参数 */
335
+ scope?: string;
336
+ /** OIDC 令牌端点 URL */
337
+ tokenEndpointURL?: string;
338
+ /** 附加的端点参数 */
339
+ additionalEndpointParams?: Record<string, string>;
340
+ /** 信任的 CA 证书文件路径,用于验证 OIDC 服务器的 TLS 证书 */
341
+ trustedCaFile?: string;
342
+ /** 跳过 TLS 证书验证,不推荐在生产环境使用 */
343
+ insecureSkipVerify?: boolean;
344
+ /** 访问 OIDC 令牌端点时使用的代理服务器 URL */
345
+ proxyURL?: string;
346
+ }
347
+ /** 客户端鉴权配置 */
348
+ interface AuthClientConfig {
349
+ /** 鉴权方式,可选值为 token 或 oidc,默认为 token */
350
+ method?: AuthMethod;
351
+ /** 鉴权信息附加范围,可选值为 HeartBeats 和 NewWorkConns */
352
+ additionalScopes?: AuthScope[];
353
+ /** 在 method 为 token 时生效,客户端需要设置一样的值才能鉴权通过。与 tokenSource 字段互斥 */
354
+ token?: string;
355
+ /** 从文件中加载 token 的配置。与 token 字段互斥 */
356
+ tokenSource?: ValueSource;
357
+ /** oidc 鉴权配置 */
358
+ oidc?: AuthOIDCClientConfig;
359
+ }
360
+ /** 客户端 TLS 配置 */
361
+ interface TLSClientConfig extends TLSConfig {
362
+ /** 是否和服务端之间启用 TLS 连接,默认启用 */
363
+ enable?: boolean;
364
+ /** 启用 TLS 连接时,不发送 0x17 特殊字节。默认为 true。当配置为 true 时,无法和 vhostHTTPSPort 端口复用 */
365
+ disableCustomTLSFirstByte?: boolean;
366
+ }
367
+ /** 客户端传输层配置 */
368
+ interface ClientTransportConfig {
369
+ /** 和 frps 之间的通信协议,可选值为 tcp, kcp, quic, websocket, wss。默认为 tcp */
370
+ protocol?: ClientTransportProtocol;
371
+ /** 连接服务端的超时时间,默认为 10s */
372
+ dialServerTimeout?: number;
373
+ /** 和服务端底层 TCP 连接的 keepalive 间隔时间,单位秒 */
374
+ dialServerKeepalive?: number;
375
+ /** 连接服务端时所绑定的本地 IP */
376
+ connectServerLocalIP?: string;
377
+ /** 连接服务端使用的代理地址,格式为 {protocol}://user:passwd@192.168.1.128:8080 protocol 目前支持 http、socks5、ntlm */
378
+ proxyURL?: string;
379
+ /** 连接池大小 */
380
+ poolCount?: number;
381
+ /** TCP 多路复用,默认启用 */
382
+ tcpMux?: boolean;
383
+ /** tcp_mux 的心跳检查间隔时间 */
384
+ tcpMuxKeepaliveInterval?: number;
385
+ /** QUIC 协议配置参数 */
386
+ quic?: QUICOptions;
387
+ /** 向服务端发送心跳包的间隔时间,默认为 30s。建议启用 tcp_mux_keepalive_interval,将此值设置为 -1 */
388
+ heartbeatInterval?: number;
389
+ /** 和服务端心跳的超时时间,默认为 90s */
390
+ heartbeatTimeout?: number;
391
+ /** 客户端 TLS 协议配置 */
392
+ tls?: TLSClientConfig;
393
+ }
394
+ /** 虚拟网络配置 */
395
+ interface VirtualNetConfig {
396
+ /** 虚拟网络接口的 IP 地址和网段,格式为 CIDR (例如 "100.86.0.1/24") */
397
+ address: string;
398
+ }
399
+ /** 客户端通用配置 */
400
+ interface ClientCommonConfig {
401
+ /** 客户端鉴权配置 */
402
+ auth?: AuthClientConfig;
403
+ /** 用户名,设置此参数后,代理名称会被修改为 {user}.{proxyName},避免代理名称和其他用户冲突 */
404
+ user?: string;
405
+ /** 连接服务端的地址 */
406
+ serverAddr?: string;
407
+ /** 连接服务端的端口,默认为 7000 */
408
+ serverPort?: number;
409
+ /** xtcp 打洞所需的 stun 服务器地址,默认为 stun.easyvoip.com:3478 */
410
+ natHoleStunServer?: string;
411
+ /** 使用 DNS 服务器地址,默认使用系统配置的 DNS 服务器,指定此参数可以强制替换为自定义的 DNS 服务器地址 */
412
+ dnsServer?: string;
413
+ /** 第一次登陆失败后是否退出,默认为 true */
414
+ loginFailExit?: boolean;
415
+ /** 指定启用部分代理,当配置了较多代理,但是只希望启用其中部分时可以通过此参数指定,默认为全部启用 */
416
+ start?: string[];
417
+ /** 日志配置 */
418
+ log?: LogConfig;
419
+ /** 客户端 AdminServer 配置 */
420
+ webServer?: WebServerConfig;
421
+ /** 客户端网络层配置 */
422
+ transport?: ClientTransportConfig;
423
+ /** 虚拟网络配置,Alpha 特性 */
424
+ virtualNet?: VirtualNetConfig;
425
+ /** 特性门控,用于启用或禁用实验性功能 */
426
+ featureGates?: Record<string, boolean>;
427
+ /** 代理 UDP 服务时支持的最大包长度,默认为 1500,服务端和客户端需要保持配置一致 */
428
+ udpPacketSize?: number;
429
+ /** 附加元数据,会传递给服务端插件,提供附加能力 */
430
+ metadatas?: Record<string, string>;
431
+ /** 指定额外的配置文件目录,其中的 proxy 和 visitor 配置会被读取加载 */
432
+ includes?: string[];
433
+ }
434
+ /** 客户端配置 */
435
+ interface ClientConfig extends ClientCommonConfig {}
436
+ //#endregion
437
+ //#region ../types/src/proxy.d.ts
438
+ /**
439
+ * FRP Proxy configuration types
440
+ * Based on: https://gofrp.org/zh-cn/docs/reference/proxy-config/
441
+ */
442
+ /** Proxy type enum */
443
+ declare enum ProxyType {
444
+ /** TCP proxy */
445
+ TCP = "tcp",
446
+ /** UDP proxy */
447
+ UDP = "udp",
448
+ /** HTTP proxy */
449
+ HTTP = "http",
450
+ /** HTTPS proxy */
451
+ HTTPS = "https",
452
+ /** TCP multiplexer proxy */
453
+ TCPMUX = "tcpmux",
454
+ /** Secure TCP proxy */
455
+ STCP = "stcp",
456
+ /** XTCP (P2P) proxy */
457
+ XTCP = "xtcp",
458
+ /** Secure UDP proxy */
459
+ SUDP = "sudp"
460
+ }
461
+ /** Load balancer strategy */
462
+ type LoadBalancerStrategy = 'random' | 'round_robin';
463
+ /** Base proxy configuration */
464
+ interface BaseProxyConfig {
465
+ /** Proxy name (unique) */
466
+ name: string;
467
+ /** Proxy type */
468
+ type: ProxyType;
469
+ /** Local IP to bind */
470
+ localIP?: string;
471
+ /** Local port */
472
+ localPort?: number;
473
+ /** Additional metadata */
474
+ annotations?: Record<string, string>;
475
+ /** Custom metadata passed to server plugins */
476
+ metadatas?: Record<string, string>;
477
+ /** Load balancer settings */
478
+ loadBalancer?: {
479
+ /** Load balancing strategy */strategy?: LoadBalancerStrategy; /** Health check configuration */
480
+ healthCheck?: {
481
+ /** Health check type */type?: ProxyType.TCP | ProxyType.HTTP; /** Health check timeout (seconds) */
482
+ timeoutSeconds?: number; /** Max failed checks before marking unhealthy */
483
+ maxFailed?: number; /** Check interval (seconds) */
484
+ intervalSeconds?: number; /** HTTP health check path */
485
+ path?: string;
132
486
  };
487
+ };
488
+ /** Enable bandwidth limit */
489
+ transport?: {
490
+ /** Bandwidth limit (KB/s) */bandwidthLimit?: string; /** Bandwidth limit mode */
491
+ bandwidthLimitMode?: 'client' | 'server';
492
+ };
493
+ }
494
+ /** TCP proxy configuration */
495
+ interface TCPProxyConfig extends BaseProxyConfig {
496
+ type: ProxyType.TCP;
497
+ /** Remote port on server */
498
+ remotePort?: number;
499
+ }
500
+ /** UDP proxy configuration */
501
+ interface UDPProxyConfig extends BaseProxyConfig {
502
+ type: ProxyType.UDP;
503
+ /** Remote port on server */
504
+ remotePort?: number;
505
+ }
506
+ /** HTTP proxy configuration */
507
+ interface HTTPProxyConfig extends BaseProxyConfig {
508
+ type: ProxyType.HTTP;
509
+ /** Custom domain names */
510
+ customDomains?: string[];
511
+ /** Subdomain under server's subdomain_host */
512
+ subdomain?: string;
513
+ /** Locations to proxy */
514
+ locations?: string[];
515
+ /** Host header rewrite */
516
+ hostHeaderRewrite?: string;
517
+ /** HTTP username for basic auth */
518
+ httpUser?: string;
519
+ /** HTTP password for basic auth */
520
+ httpPassword?: string;
521
+ /** Request headers to set */
522
+ requestHeaders?: {
523
+ set?: Record<string, string>;
524
+ };
525
+ /** Response headers to set */
526
+ responseHeaders?: {
527
+ set?: Record<string, string>;
528
+ };
529
+ /** Route by HTTP user */
530
+ routeByHTTPUser?: string;
531
+ }
532
+ /** HTTPS proxy configuration */
533
+ interface HTTPSProxyConfig extends BaseProxyConfig {
534
+ type: ProxyType.HTTPS;
535
+ /** Custom domain names */
536
+ customDomains?: string[];
537
+ /** Subdomain under server's subdomain_host */
538
+ subdomain?: string;
539
+ }
540
+ /** TCPMUX proxy configuration */
541
+ interface TCPMUXProxyConfig extends BaseProxyConfig {
542
+ type: ProxyType.TCPMUX;
543
+ /** Multiplexer type */
544
+ multiplexer?: 'httpconnect';
545
+ /** Custom domain names */
546
+ customDomains?: string[];
547
+ /** Subdomain under server's subdomain_host */
548
+ subdomain?: string;
549
+ /** Route by HTTP user */
550
+ routeByHTTPUser?: string;
551
+ /** HTTP username */
552
+ httpUser?: string;
553
+ /** HTTP password */
554
+ httpPassword?: string;
555
+ }
556
+ /** STCP proxy configuration */
557
+ interface STCPProxyConfig extends BaseProxyConfig {
558
+ type: ProxyType.STCP;
559
+ /** Secret key shared with visitor */
560
+ secretKey?: string;
561
+ /** Allowed visitor users */
562
+ allowUsers?: string[];
563
+ }
564
+ /** XTCP proxy configuration */
565
+ interface XTCPProxyConfig extends BaseProxyConfig {
566
+ type: ProxyType.XTCP;
567
+ /** Secret key shared with visitor */
568
+ secretKey?: string;
569
+ /** Allowed visitor users */
570
+ allowUsers?: string[];
571
+ }
572
+ /** SUDP proxy configuration */
573
+ interface SUDPProxyConfig extends BaseProxyConfig {
574
+ type: ProxyType.SUDP;
575
+ /** Secret key shared with visitor */
576
+ secretKey?: string;
577
+ /** Allowed visitor users */
578
+ allowUsers?: string[];
579
+ }
580
+ /** Union type of all proxy configurations */
581
+ type ProxyConfig = TCPProxyConfig | UDPProxyConfig | HTTPProxyConfig | HTTPSProxyConfig | TCPMUXProxyConfig | STCPProxyConfig | XTCPProxyConfig | SUDPProxyConfig;
582
+ //#endregion
583
+ //#region ../types/src/node.d.ts
584
+ /** Node information structure */
585
+ interface NodeInfo$1 {
586
+ id: string;
587
+ ip: string;
588
+ port: number;
589
+ protocol: 'tcp' | 'udp';
590
+ serverAddr: string;
591
+ serverPort: number;
592
+ hostname?: string;
593
+ osType?: string;
594
+ osRelease?: string;
595
+ platform?: string;
596
+ cpuCores?: number;
597
+ memTotal?: number;
598
+ frpVersion?: string;
599
+ bridgeVersion?: string;
600
+ status: 'online' | 'offline' | 'connecting' | 'error';
601
+ lastHeartbeat?: number;
602
+ connectedAt?: number;
603
+ labels?: Record<string, string>;
604
+ metadata?: Record<string, unknown>;
605
+ token?: string;
606
+ tunnels?: ProxyConfig[];
607
+ createdAt: number;
608
+ updatedAt: number;
609
+ }
610
+ /** Payload for node registration (Client → Server) */
611
+ interface NodeRegisterPayload {
612
+ ip: string;
613
+ port: number;
614
+ serverAddr: string;
615
+ serverPort: number;
616
+ protocol: 'tcp' | 'udp';
617
+ hostname: string;
618
+ osType: string;
619
+ osRelease: string;
620
+ platform: string;
621
+ cpuCores: number;
622
+ memTotal: number;
623
+ frpVersion: string;
624
+ bridgeVersion: string;
625
+ token?: string;
626
+ }
627
+ /** Payload for node heartbeat (Client → Server) */
628
+ interface NodeHeartbeatPayload {
629
+ nodeId: string;
630
+ status: 'online' | 'error';
631
+ lastHeartbeat: number;
632
+ cpuCores?: number;
633
+ memTotal?: number;
634
+ }
635
+ /** Payload for tunnel synchronization (Client → Server) */
636
+ interface TunnelSyncPayload {
637
+ nodeId: string;
638
+ tunnels: ProxyConfig[];
639
+ timestamp: number;
640
+ }
641
+ /** Query parameters for listing nodes */
642
+ interface NodeListQuery {
643
+ page?: number;
644
+ pageSize?: number;
645
+ status?: NodeInfo$1['status'];
646
+ labels?: Record<string, string>;
647
+ search?: string;
648
+ }
649
+ /** Response for node list query */
650
+ interface NodeListResponse {
651
+ items: NodeInfo$1[];
652
+ total: number;
653
+ page: number;
654
+ pageSize: number;
655
+ hasMore: boolean;
656
+ }
657
+ /** Node statistics */
658
+ interface NodeStatistics {
659
+ total: number;
660
+ online: number;
661
+ offline: number;
662
+ connecting: number;
663
+ error: number;
664
+ }
665
+ //#endregion
666
+ //#region ../types/src/rpc.d.ts
667
+ interface RpcRequest$1 {
668
+ id: string;
669
+ method: string;
670
+ params: Record<string, unknown>;
671
+ timeout?: number;
672
+ }
673
+ //#endregion
674
+ //#region src/node/client-collector.d.ts
675
+ interface ClientCollectorOptions {
676
+ /** Node ID (set by server after registration) */
677
+ nodeId?: string;
678
+ /** Heartbeat interval in milliseconds (default: 30000) */
679
+ heartbeatInterval?: number;
133
680
  }
134
681
  /**
135
682
  * Collects node information on client side
136
683
  * Used in client mode to send system info and heartbeat to server
137
684
  */
138
685
  declare class ClientNodeCollector {
139
- private nodeId?;
140
- private heartbeatInterval;
141
- private logger;
142
- private heartbeatTimer?;
143
- constructor(options?: ClientCollectorOptions);
144
- /** Set node ID after server registration */
145
- setNodeId(nodeId: string): void;
146
- /** Collect current node information */
147
- collectNodeInfo(): Partial<NodeRegisterPayload>;
148
- /** Collect heartbeat payload */
149
- collectHeartbeat(): Partial<NodeHeartbeatPayload>;
150
- /**
151
- * Start periodic heartbeat collection
152
- * Callback will be called at each interval with heartbeat payload
153
- */
154
- startHeartbeat(callback: (payload: Partial<NodeHeartbeatPayload>) => void, interval?: number): void;
155
- /** Stop periodic heartbeat collection */
156
- stopHeartbeat(): void;
157
- /** Check if heartbeat is running */
158
- isHeartbeatRunning(): boolean;
686
+ private nodeId?;
687
+ private heartbeatInterval;
688
+ private readonly log;
689
+ private heartbeatTimer?;
690
+ constructor(options?: ClientCollectorOptions);
691
+ /** Set node ID after server registration */
692
+ setNodeId(nodeId: string): void;
693
+ /** Collect current node information */
694
+ collectNodeInfo(): Partial<NodeRegisterPayload>;
695
+ /** Collect heartbeat payload */
696
+ collectHeartbeat(): Partial<NodeHeartbeatPayload>;
697
+ /**
698
+ * Start periodic heartbeat collection
699
+ * Callback will be called at each interval with heartbeat payload
700
+ */
701
+ startHeartbeat(callback: (payload: Partial<NodeHeartbeatPayload>) => void, interval?: number): void;
702
+ /** Stop periodic heartbeat collection */
703
+ stopHeartbeat(): void;
704
+ /** Check if heartbeat is running */
705
+ isHeartbeatRunning(): boolean;
159
706
  }
160
-
161
- /**
162
- * Node Manager for server-side node management
163
- * Handles node registration, heartbeat, tunnel registry, and queries
164
- */
165
-
707
+ //#endregion
708
+ //#region src/node/node-manager.d.ts
166
709
  interface NodeManagerOptions {
167
- heartbeatTimeout?: number;
168
- logger?: any;
710
+ heartbeatTimeout?: number;
169
711
  }
170
712
  interface NodeStorage {
171
- save: (node: NodeInfo$1) => Promise<void> | void;
172
- delete: (id: string) => Promise<void> | void;
173
- load: (id: string) => Promise<NodeInfo$1 | undefined> | NodeInfo$1 | undefined;
174
- list: () => Promise<NodeInfo$1[]> | NodeInfo$1[];
713
+ save: (node: NodeInfo$1) => Promise<void> | void;
714
+ delete: (id: string) => Promise<void> | void;
715
+ load: (id: string) => Promise<NodeInfo$1 | undefined> | NodeInfo$1 | undefined;
716
+ list: () => Promise<NodeInfo$1[]> | NodeInfo$1[];
175
717
  }
176
718
  type NodeEvent = 'node:registered' | 'node:heartbeat' | 'node:unregistered' | 'node:statusChanged' | 'tunnel:synced';
177
719
  /**
@@ -179,64 +721,60 @@ type NodeEvent = 'node:registered' | 'node:heartbeat' | 'node:unregistered' | 'n
179
721
  * Stores node info, handles heartbeat, manages global tunnel registry, emits events
180
722
  */
181
723
  declare class NodeManager extends EventEmitter {
182
- private context;
183
- private nodes;
184
- private heartbeatTimers;
185
- private tunnelRegistry;
186
- private storage?;
187
- private heartbeatTimeout;
188
- private logger?;
189
- constructor(context: RuntimeContext, options?: NodeManagerOptions, storage?: NodeStorage);
190
- initialize(): Promise<void>;
191
- /** Register a new node (called when client connects) */
192
- registerNode(payload: NodeRegisterPayload): Promise<NodeInfo$1>;
193
- /** Update node heartbeat and status */
194
- updateHeartbeat(payload: NodeHeartbeatPayload): Promise<void>;
195
- /** Unregister a node (called when client disconnects) */
196
- unregisterNode(nodeId: string): Promise<void>;
197
- /** Get node by id */
198
- getNode(id: string): Promise<NodeInfo$1 | undefined>;
199
- /** List nodes with pagination and filtering */
200
- listNodes(query?: NodeListQuery): Promise<NodeListResponse>;
201
- /** Get node statistics */
202
- getStatistics(): Promise<NodeStatistics>;
203
- /** Check if node exists */
204
- hasNode(id: string): boolean;
205
- /** Get all online nodes */
206
- getOnlineNodes(): NodeInfo$1[];
207
- /** Get all offline nodes */
208
- getOfflineNodes(): NodeInfo$1[];
209
- /** Get nodes by status */
210
- getNodesByStatus(status: NodeInfo$1['status']): NodeInfo$1[];
211
- /** Setup heartbeat timer for a node */
212
- private setupHeartbeatTimer;
213
- /** Clear heartbeat timer for a node */
214
- private clearHeartbeatTimer;
215
- /** Handle heartbeat timeout */
216
- private handleHeartbeatTimeout;
217
- /** Sync tunnels for a node (called when node connects or updates tunnels) */
218
- syncTunnels(payload: TunnelSyncPayload): Promise<void>;
219
- /** Get tunnels for a specific node */
220
- getNodeTunnels(nodeId: string): ProxyConfig[];
221
- /** Get all tunnels across all nodes */
222
- getAllTunnels(): Map<string, ProxyConfig[]>;
223
- /** Check if a remotePort is in use across all nodes (for conflict detection) */
224
- isRemotePortInUse(remotePort: number, excludeNodeId?: string): {
225
- inUse: boolean;
226
- nodeId?: string;
227
- tunnelName?: string;
228
- };
229
- /** Clear tunnels for a node (called when node disconnects) */
230
- private clearNodeTunnels;
231
- /** Update dispose method to clear tunnels */
232
- dispose(): Promise<void>;
724
+ private context;
725
+ private nodes;
726
+ private heartbeatTimers;
727
+ private tunnelRegistry;
728
+ private storage?;
729
+ private heartbeatTimeout;
730
+ private readonly log;
731
+ constructor(context: RuntimeContext, options?: NodeManagerOptions, storage?: NodeStorage);
732
+ initialize(): Promise<void>;
733
+ /** Register a new node (called when client connects) */
734
+ registerNode(payload: NodeRegisterPayload): Promise<NodeInfo$1>;
735
+ /** Update node heartbeat and status */
736
+ updateHeartbeat(payload: NodeHeartbeatPayload): Promise<void>;
737
+ /** Unregister a node (called when client disconnects) */
738
+ unregisterNode(nodeId: string): Promise<void>;
739
+ /** Get node by id */
740
+ getNode(id: string): Promise<NodeInfo$1 | undefined>;
741
+ /** List nodes with pagination and filtering */
742
+ listNodes(query?: NodeListQuery): Promise<NodeListResponse>;
743
+ /** Get node statistics */
744
+ getStatistics(): Promise<NodeStatistics>;
745
+ /** Check if node exists */
746
+ hasNode(id: string): boolean;
747
+ /** Get all online nodes */
748
+ getOnlineNodes(): NodeInfo$1[];
749
+ /** Get all offline nodes */
750
+ getOfflineNodes(): NodeInfo$1[];
751
+ /** Get nodes by status */
752
+ getNodesByStatus(status: NodeInfo$1['status']): NodeInfo$1[];
753
+ /** Setup heartbeat timer for a node */
754
+ private setupHeartbeatTimer;
755
+ /** Clear heartbeat timer for a node */
756
+ private clearHeartbeatTimer;
757
+ /** Handle heartbeat timeout */
758
+ private handleHeartbeatTimeout;
759
+ /** Sync tunnels for a node (called when node connects or updates tunnels) */
760
+ syncTunnels(payload: TunnelSyncPayload): Promise<void>;
761
+ /** Get tunnels for a specific node */
762
+ getNodeTunnels(nodeId: string): ProxyConfig[];
763
+ /** Get all tunnels across all nodes */
764
+ getAllTunnels(): Map<string, ProxyConfig[]>;
765
+ /** Check if a remotePort is in use across all nodes (for conflict detection) */
766
+ isRemotePortInUse(remotePort: number, excludeNodeId?: string): {
767
+ inUse: boolean;
768
+ nodeId?: string;
769
+ tunnelName?: string;
770
+ };
771
+ /** Clear tunnels for a node (called when node disconnects) */
772
+ private clearNodeTunnels;
773
+ /** Update dispose method to clear tunnels */
774
+ dispose(): Promise<void>;
233
775
  }
234
-
235
- /**
236
- * File-based node storage implementation
237
- * Persists node information to disk
238
- */
239
-
776
+ //#endregion
777
+ //#region src/node/file-node-storage.d.ts
240
778
  /**
241
779
  * Stores nodes in JSON files
242
780
  * Directory structure:
@@ -245,214 +783,683 @@ declare class NodeManager extends EventEmitter {
245
783
  * └── node-{id}.json (individual node data)
246
784
  */
247
785
  declare class FileNodeStorage implements NodeStorage {
248
- private storagePath;
249
- private indexPath;
250
- private nodeDir;
251
- constructor(storagePath: string);
252
- /** Save or update a node */
253
- save(node: NodeInfo$1): Promise<void>;
254
- /** Delete a node */
255
- delete(id: string): Promise<void>;
256
- /** Load a single node */
257
- load(id: string): Promise<NodeInfo$1 | undefined>;
258
- /** Load all nodes */
259
- list(): Promise<NodeInfo$1[]>;
260
- /** Update the index of node IDs */
261
- private updateIndex;
786
+ private storagePath;
787
+ private indexPath;
788
+ private nodeDir;
789
+ constructor(storagePath: string);
790
+ /** Save or update a node */
791
+ save(node: NodeInfo$1): Promise<void>;
792
+ /** Delete a node */
793
+ delete(id: string): Promise<void>;
794
+ /** Load a single node */
795
+ load(id: string): Promise<NodeInfo$1 | undefined>;
796
+ /** Load all nodes */
797
+ list(): Promise<NodeInfo$1[]>;
798
+ /** Update the index of node IDs */
799
+ private updateIndex;
262
800
  }
263
-
801
+ //#endregion
802
+ //#region src/config-merger.d.ts
264
803
  /**
265
- * FRP process management utilities
804
+ * 预设配置接口
266
805
  */
267
-
806
+ interface PresetConfig {
807
+ frps?: FrpsPresetConfig;
808
+ frpc?: FrpcPresetConfig;
809
+ }
810
+ interface FrpsPresetConfig {
811
+ bindPort?: number;
812
+ vhostHTTPPort?: number;
813
+ vhostHTTPSPort?: number;
814
+ domain?: string;
815
+ dashboardPort?: number;
816
+ dashboardUser?: string;
817
+ dashboardPassword?: string;
818
+ authToken?: string;
819
+ subdomainHost?: string;
820
+ }
821
+ interface FrpcPresetConfig {
822
+ serverAddr?: string;
823
+ serverPort?: number;
824
+ authToken?: string;
825
+ user?: string;
826
+ heartbeatInterval?: number;
827
+ }
828
+ /**
829
+ * 默认预设配置
830
+ */
831
+ declare const DEFAULT_PRESET_CONFIG: PresetConfig;
832
+ /**
833
+ * 合并预设配置和用户配置,生成最终的 TOML 配置
834
+ */
835
+ declare function mergeConfigs(presetConfig: PresetConfig, userConfig: string, type: 'frps' | 'frpc'): string;
836
+ /**
837
+ * 从 tunnels 数组生成并保存 FRP 配置文件
838
+ */
839
+ declare function saveFrpConfigFile(configPath: string, tunnels: ProxyConfig[], presetConfig: PresetConfig, type: 'frps' | 'frpc'): Promise<void>;
840
+ /**
841
+ * 将配置对象转换为 TOML 格式
842
+ */
843
+ declare function configToToml(config: Record<string, unknown>): string;
844
+ /**
845
+ * 验证预设配置
846
+ */
847
+ declare function validatePresetConfig(config: PresetConfig, type: 'frps' | 'frpc'): {
848
+ valid: boolean;
849
+ errors: string[];
850
+ };
851
+ //#endregion
852
+ //#region src/process/controllers/process-controller.d.ts
853
+ type ProcessEventType = 'process:started' | 'process:stopped' | 'process:exited' | 'process:error' | 'status';
854
+ //#endregion
855
+ //#region src/process/index.d.ts
856
+ interface ProcessEvent {
857
+ type: ProcessEventType;
858
+ timestamp: number;
859
+ payload?: {
860
+ code?: number;
861
+ signal?: string;
862
+ error?: string;
863
+ pid?: number;
864
+ uptime?: number;
865
+ running?: boolean;
866
+ };
867
+ }
268
868
  interface FrpProcessManagerOptions {
269
- /** Working directory for FRP files */
270
- workDir?: string;
271
- /** Path to config file (overrides default) */
272
- configPath?: string;
273
- /** FRP version (defaults to latest) */
274
- version?: string;
275
- /** Mode: client or server */
276
- mode: 'client' | 'server';
277
- /** Optional logger */
278
- logger?: RuntimeLogger;
869
+ /** Working directory for FRP files */
870
+ workDir?: string;
871
+ /** Path to config file (overrides default) */
872
+ configPath?: string;
873
+ /** Config directory for preset configs (overrides workDir/config) */
874
+ configDir?: string;
875
+ /** FRP version (defaults to latest) */
876
+ version?: string;
877
+ /** Mode: client or server */
878
+ mode: 'client' | 'server';
279
879
  }
280
880
  interface NodeInfo {
281
- /** Node ID */
282
- id: string;
283
- /** Node name */
284
- name: string;
285
- /** Server address */
286
- serverAddr: string;
287
- /** Server port */
288
- serverPort?: number;
289
- /** Authentication token */
290
- token?: string;
291
- /** Additional config */
292
- config?: Partial<ClientConfig | ServerConfig>;
881
+ /** Node ID */
882
+ id: string;
883
+ /** Node name */
884
+ name: string;
885
+ /** Server address */
886
+ serverAddr: string;
887
+ /** Server port */
888
+ serverPort?: number;
889
+ /** Authentication token */
890
+ token?: string;
891
+ /** Additional config */
892
+ config?: Partial<ClientConfig | ServerConfig>;
293
893
  }
294
894
  /**
295
895
  * Manages FRP client/server lifecycle, config, and tunnels
896
+ *
897
+ * This class now serves as a facade that delegates to specialized components:
898
+ * - ProcessController: Process lifecycle management
899
+ * - ConfigurationStore: Configuration file operations
900
+ * - TunnelManager: Tunnel/proxy management
901
+ * - NodeManager: Node information management
902
+ * - BinaryManager: Binary file management
296
903
  */
297
904
  declare class FrpProcessManager extends EventEmitter {
298
- private readonly workDir;
299
- private version;
300
- private readonly mode;
301
- private readonly specifiedVersion?;
302
- private readonly logger;
303
- private process;
304
- private configPath;
305
- private binaryPath;
306
- private uptime;
307
- private isManualStop;
308
- constructor(options: FrpProcessManagerOptions);
309
- /** Ensure version is fetched and binary path is set */
310
- private ensureVersion;
311
- /** Download FRP binary for current platform */
312
- downloadFrpBinary(): Promise<void>;
313
- /** Update FRP binary to latest version */
314
- updateFrpBinary(newVersion?: string): Promise<void>;
315
- /** Check if binary exists */
316
- hasBinary(): boolean;
317
- /** Get current configuration */
318
- getConfig(): ClientConfig | ServerConfig | null;
319
- /** Update configuration */
320
- updateConfig(config: Partial<ClientConfig | ServerConfig>): void;
321
- /** Backup configuration */
322
- backupConfig(): Promise<string>;
323
- /** Return the absolute config file path */
324
- getConfigPath(): string;
325
- /** Read raw config file contents */
326
- getConfigRaw(): string | null;
327
- /** Overwrite config file with provided content */
328
- updateConfigRaw(content: string): void;
329
- /** Start FRP process */
330
- start(): Promise<void>;
331
- /** Stop FRP process */
332
- stop(): Promise<void>;
333
- /** Check if process is running */
334
- isRunning(): boolean;
335
- /** Add node (for client mode) */
336
- addNode(node: NodeInfo): void;
337
- /** Get node info */
338
- getNode(): NodeInfo | null;
339
- /** Update node info */
340
- updateNode(node: Partial<NodeInfo>): void;
341
- /** Remove node */
342
- removeNode(): void;
343
- /** Add tunnel (proxy) */
344
- addTunnel(proxy: ProxyConfig): void;
345
- /** Check if proxy type uses remotePort */
346
- private typeUsesRemotePort;
347
- /** Get tunnel by name */
348
- getTunnel(name: string): ProxyConfig | null;
349
- /** Update tunnel */
350
- updateTunnel(name: string, proxy: Partial<ProxyConfig>): void;
351
- /** Remove tunnel */
352
- removeTunnel(name: string): void;
353
- /** List all tunnels */
354
- listTunnels(): ProxyConfig[];
355
- /**
356
- * Query current process status
357
- */
358
- queryProcess(): {
359
- pid: number | undefined;
360
- uptime: number;
361
- };
362
- private setupProcessListeners;
905
+ private readonly workDir;
906
+ private readonly mode;
907
+ private readonly specifiedVersion?;
908
+ private readonly configPath;
909
+ private readonly configDir;
910
+ private readonly processController;
911
+ private readonly configStore;
912
+ private readonly binaryManager;
913
+ private readonly presetConfigManager;
914
+ private tunnelManager;
915
+ private nodeManager;
916
+ private uptime;
917
+ private isManualStop;
918
+ constructor(options: FrpProcessManagerOptions);
919
+ /** Ensure version is fetched and binary path is set */
920
+ private ensureVersion;
921
+ /** Download FRP binary for current platform */
922
+ downloadFrpBinary(): Promise<void>;
923
+ /** Update FRP binary to latest version */
924
+ updateFrpBinary(newVersion?: string): Promise<void>;
925
+ /** Check if binary exists */
926
+ hasBinary(): boolean;
927
+ /** Get current configuration */
928
+ getConfig(): Promise<ClientConfig | ServerConfig | null>;
929
+ /** Update configuration */
930
+ updateConfig(config: Partial<ClientConfig | ServerConfig>): Promise<void>;
931
+ /** Backup configuration */
932
+ backupConfig(): Promise<string>;
933
+ /** Return the absolute config file path */
934
+ getConfigPath(): string;
935
+ /** Read raw config file contents */
936
+ getConfigRaw(): string | null;
937
+ /** Overwrite config file with provided content */
938
+ updateConfigRaw(content: string): void;
939
+ /** Start FRP process */
940
+ start(): Promise<void>;
941
+ /** Stop FRP process */
942
+ stop(): Promise<void>;
943
+ /** Check if process is running */
944
+ isRunning(): boolean;
945
+ /** Add node (for client mode) */
946
+ addNode(node: NodeInfo): Promise<void>;
947
+ /** Get node info */
948
+ getNode(): Promise<NodeInfo | null>;
949
+ /** Update node info */
950
+ updateNode(node: Partial<NodeInfo>): Promise<void>;
951
+ /** Remove node */
952
+ removeNode(): Promise<void>;
953
+ /** Add tunnel (proxy) */
954
+ addTunnel(proxy: ProxyConfig): Promise<void>;
955
+ /** Get tunnel by name */
956
+ getTunnel(name: string): Promise<ProxyConfig | null>;
957
+ /** Update tunnel */
958
+ updateTunnel(name: string, proxy: Partial<ProxyConfig>): Promise<void>;
959
+ /** Remove tunnel */
960
+ removeTunnel(name: string): Promise<void>;
961
+ /** List all tunnels */
962
+ listTunnels(): Promise<ProxyConfig[]>;
963
+ /**
964
+ * 生成 FRP 配置文件(合并预设配置和用户 tunnels)
965
+ * @param force 是否强制重新生成
966
+ */
967
+ generateConfig(force?: boolean): Promise<void>;
968
+ /**
969
+ * 获取预设配置
970
+ */
971
+ getPresetConfig(): PresetConfig;
972
+ /**
973
+ * 保存预设配置
974
+ */
975
+ savePresetConfig(config: Record<string, any>): void;
976
+ /**
977
+ * Query current process status
978
+ */
979
+ queryProcess(): {
980
+ pid?: number;
981
+ uptime: number;
982
+ };
983
+ /**
984
+ * Dispose and clean up resources
985
+ */
986
+ dispose(): Promise<void>;
363
987
  }
364
-
988
+ //#endregion
989
+ //#region src/rpc/message-types.d.ts
990
+ /**
991
+ * RPC 消息类型定义
992
+ * 提供类型安全的消息结构和类型守卫
993
+ */
994
+ /**
995
+ * RPC 消息类型枚举
996
+ */
997
+ declare enum RpcMessageType {
998
+ REGISTER = "register",
999
+ COMMAND = "command",
1000
+ RESPONSE = "response",
1001
+ PING = "ping",
1002
+ PONG = "pong"
1003
+ }
1004
+ /**
1005
+ * 节点注册消息
1006
+ */
1007
+ interface RegisterMessage {
1008
+ type: RpcMessageType.REGISTER;
1009
+ nodeId: string;
1010
+ payload: Record<string, unknown>;
1011
+ }
1012
+ /**
1013
+ * RPC 请求
1014
+ */
1015
+ interface RpcRequest {
1016
+ id: string;
1017
+ method: string;
1018
+ params: Record<string, unknown>;
1019
+ timeout?: number;
1020
+ }
1021
+ /**
1022
+ * RPC 响应状态
1023
+ */
1024
+ type RpcResponseStatus = 'success' | 'error';
1025
+ /**
1026
+ * RPC 响应
1027
+ */
1028
+ interface RpcResponse {
1029
+ id: string;
1030
+ status: RpcResponseStatus;
1031
+ result?: unknown;
1032
+ error?: {
1033
+ code: string;
1034
+ message: string;
1035
+ };
1036
+ }
1037
+ /**
1038
+ * Ping 消息
1039
+ */
1040
+ interface PingMessage {
1041
+ type: RpcMessageType.PING;
1042
+ timestamp: number;
1043
+ }
1044
+ /**
1045
+ * Pong 消息
1046
+ */
1047
+ interface PongMessage {
1048
+ type: RpcMessageType.PONG;
1049
+ timestamp: number;
1050
+ }
1051
+ /**
1052
+ * 所有 RPC 消息类型
1053
+ */
1054
+ type RpcMessage = RegisterMessage | RpcRequest | RpcResponse | PingMessage | PongMessage;
1055
+ /**
1056
+ * Event-based RPC message type (matching document spec)
1057
+ */
1058
+ interface EventRpcMessage {
1059
+ type: 'command' | 'event';
1060
+ action: string;
1061
+ payload: unknown;
1062
+ id?: string;
1063
+ targetNodeId?: string;
1064
+ [key: string]: unknown;
1065
+ }
1066
+ /**
1067
+ * Command message (frps -> frpc)
1068
+ */
1069
+ interface CommandRpcMessage extends EventRpcMessage {
1070
+ type: 'command';
1071
+ id: string;
1072
+ }
1073
+ /**
1074
+ * Event message (frpc -> frps)
1075
+ */
1076
+ interface EventRpcMessageEvent extends EventRpcMessage {
1077
+ type: 'event';
1078
+ id?: string;
1079
+ }
1080
+ /**
1081
+ * Tunnel add payload
1082
+ */
1083
+ interface TunnelAddPayload {
1084
+ name: string;
1085
+ type: 'tcp' | 'http' | 'https' | 'stcp' | 'sudp' | 'xtcp';
1086
+ localPort: number;
1087
+ remotePort?: number;
1088
+ customDomains?: string[];
1089
+ subdomain?: string;
1090
+ nodeId?: string;
1091
+ [key: string]: unknown;
1092
+ }
1093
+ /**
1094
+ * Tunnel delete payload
1095
+ */
1096
+ interface TunnelDeletePayload {
1097
+ name: string;
1098
+ nodeId?: string;
1099
+ }
1100
+ /**
1101
+ * Tunnel response payload
1102
+ */
1103
+ interface TunnelResponsePayload {
1104
+ success: boolean;
1105
+ error?: string;
1106
+ tunnel?: TunnelAddPayload;
1107
+ }
1108
+ /**
1109
+ * Node delete payload
1110
+ */
1111
+ interface NodeDeletePayload {
1112
+ name: string;
1113
+ }
1114
+ /**
1115
+ * Node response payload
1116
+ */
1117
+ interface NodeResponsePayload {
1118
+ success: boolean;
1119
+ error?: string;
1120
+ deletedNode?: string;
1121
+ }
1122
+ /**
1123
+ * All message types including event-based
1124
+ */
1125
+ type AllRpcMessage = RpcMessage | EventRpcMessage;
1126
+ /**
1127
+ * 类型守卫:检查是否为注册消息
1128
+ */
1129
+ declare function isRegisterMessage(msg: unknown): msg is RegisterMessage;
1130
+ /**
1131
+ * 类型守卫:检查是否为 RPC 请求
1132
+ */
1133
+ declare function isRpcRequest(msg: unknown): msg is RpcRequest;
1134
+ /**
1135
+ * 类型守卫:检查是否为 RPC 响应
1136
+ */
1137
+ declare function isRpcResponse(msg: unknown): msg is RpcResponse;
1138
+ /**
1139
+ * 类型守卫:检查是否为 Ping 消息
1140
+ */
1141
+ declare function isPingMessage(msg: unknown): msg is PingMessage;
1142
+ /**
1143
+ * 类型守卫:检查是否为 Pong 消息
1144
+ */
1145
+ declare function isPongMessage(msg: unknown): msg is PongMessage;
1146
+ /**
1147
+ * 类型守卫:检查是否为 Event-based RPC 消息
1148
+ */
1149
+ declare function isEventRpcMessage(msg: unknown): msg is EventRpcMessage;
1150
+ /**
1151
+ * 类型守卫:检查是否为 Command 消息
1152
+ */
1153
+ declare function isCommandMessage(msg: unknown): msg is CommandRpcMessage;
1154
+ /**
1155
+ * 类型守卫:检查是否为 Event 消息
1156
+ */
1157
+ declare function isEventMessage(msg: unknown): msg is EventRpcMessageEvent;
1158
+ /**
1159
+ * 类型守卫:检查是否为 TunnelAddPayload
1160
+ */
1161
+ declare function isTunnelAddPayload(data: unknown): data is TunnelAddPayload;
1162
+ /**
1163
+ * 类型守卫:检查是否为 TunnelDeletePayload
1164
+ */
1165
+ declare function isTunnelDeletePayload(data: unknown): data is TunnelDeletePayload;
1166
+ /**
1167
+ * 类型守卫:检查是否为 NodeDeletePayload
1168
+ */
1169
+ declare function isNodeDeletePayload(data: unknown): data is NodeDeletePayload;
1170
+ //#endregion
1171
+ //#region src/rpc/middleware.d.ts
1172
+ /**
1173
+ * 中间件上下文
1174
+ */
1175
+ interface MiddlewareContext {
1176
+ request: RpcRequest;
1177
+ response: Partial<RpcResponse>;
1178
+ startTime: number;
1179
+ }
1180
+ /**
1181
+ * 中间件函数类型
1182
+ */
1183
+ type MiddlewareFn = (context: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
1184
+ /**
1185
+ * 中间件选项
1186
+ */
1187
+ interface MiddlewareOptions {
1188
+ preHooks?: MiddlewareFn[];
1189
+ postHooks?: MiddlewareFn[];
1190
+ }
1191
+ /**
1192
+ * 日志中间件
1193
+ */
1194
+ declare function loggingMiddleware(): MiddlewareFn;
1195
+ /**
1196
+ * 认证中间件
1197
+ */
1198
+ declare function authMiddleware(validateToken: (token: string | undefined) => boolean | Promise<boolean>): MiddlewareFn;
1199
+ /**
1200
+ * 超时中间件
1201
+ */
1202
+ declare function timeoutMiddleware(timeoutMs: number): MiddlewareFn;
1203
+ /**
1204
+ * 错误处理中间件
1205
+ */
1206
+ declare function errorHandlerMiddleware(): MiddlewareFn;
1207
+ /**
1208
+ * 中间件管道
1209
+ */
1210
+ declare class MiddlewarePipeline {
1211
+ private middlewares;
1212
+ /**
1213
+ * 添加中间件
1214
+ */
1215
+ use(middleware: MiddlewareFn): this;
1216
+ /**
1217
+ * 执行中间件管道
1218
+ */
1219
+ execute(request: RpcRequest, handler: () => Promise<unknown>): Promise<Partial<RpcResponse>>;
1220
+ /**
1221
+ * 执行处理器
1222
+ */
1223
+ private executeHandler;
1224
+ /**
1225
+ * 清空中间件
1226
+ */
1227
+ clear(): void;
1228
+ }
1229
+ //#endregion
1230
+ //#region src/rpc/reconnect-strategy.d.ts
1231
+ /**
1232
+ * RPC 重连策略
1233
+ * 提供可配置的重连机制,包括指数退避
1234
+ */
1235
+ /**
1236
+ * 重连策略接口
1237
+ */
1238
+ interface ReconnectStrategy {
1239
+ /**
1240
+ * 判断是否应该重连
1241
+ */
1242
+ shouldReconnect: (attempt: number) => boolean;
1243
+ /**
1244
+ * 获取重连延迟时间(毫秒)
1245
+ */
1246
+ getDelay: (attempt: number) => number;
1247
+ /**
1248
+ * 达到最大重连次数时的回调
1249
+ */
1250
+ onMaxAttemptsReached: () => void;
1251
+ }
1252
+ /**
1253
+ * 指数退避重连策略
1254
+ */
1255
+ declare class ExponentialBackoffStrategy implements ReconnectStrategy {
1256
+ private maxAttempts;
1257
+ private baseDelay;
1258
+ private maxDelay;
1259
+ constructor(maxAttempts?: number, baseDelay?: number, maxDelay?: number);
1260
+ shouldReconnect(attempt: number): boolean;
1261
+ getDelay(attempt: number): number;
1262
+ onMaxAttemptsReached(): void;
1263
+ }
1264
+ /**
1265
+ * 固定间隔重连策略
1266
+ */
1267
+ declare class FixedIntervalStrategy implements ReconnectStrategy {
1268
+ private maxAttempts;
1269
+ private interval;
1270
+ constructor(maxAttempts?: number, interval?: number);
1271
+ shouldReconnect(attempt: number): boolean;
1272
+ getDelay(): number;
1273
+ onMaxAttemptsReached(): void;
1274
+ }
1275
+ /**
1276
+ * 线性增长重连策略
1277
+ */
1278
+ declare class LinearBackoffStrategy implements ReconnectStrategy {
1279
+ private maxAttempts;
1280
+ private baseDelay;
1281
+ private increment;
1282
+ private maxDelay;
1283
+ constructor(maxAttempts?: number, baseDelay?: number, increment?: number, maxDelay?: number);
1284
+ shouldReconnect(attempt: number): boolean;
1285
+ getDelay(attempt: number): number;
1286
+ onMaxAttemptsReached(): void;
1287
+ }
1288
+ /**
1289
+ * 无限重连策略(永不停止)
1290
+ */
1291
+ declare class InfiniteReconnectStrategy implements ReconnectStrategy {
1292
+ private baseDelay;
1293
+ private maxDelay;
1294
+ constructor(baseDelay?: number, maxDelay?: number);
1295
+ shouldReconnect(): boolean;
1296
+ getDelay(attempt: number): number;
1297
+ onMaxAttemptsReached(): void;
1298
+ }
1299
+ //#endregion
1300
+ //#region src/rpc/rpc-client.d.ts
365
1301
  interface RpcClientOptions {
366
- url: string;
367
- nodeId: string;
368
- getRegisterPayload: () => Promise<NodeInfo$1> | NodeInfo$1;
369
- handleRequest: (req: RpcRequest) => Promise<unknown>;
370
- reconnectInterval?: number;
371
- logger?: {
372
- info?: (msg: string, data?: unknown) => void;
373
- warn?: (msg: string, data?: unknown) => void;
374
- error?: (msg: string, data?: unknown) => void;
375
- };
1302
+ url: string;
1303
+ nodeId: string;
1304
+ getRegisterPayload: () => Promise<NodeInfo$1> | NodeInfo$1;
1305
+ handleRequest: (req: RpcRequest$1) => Promise<unknown>;
1306
+ handleCommand?: (command: CommandRpcMessage) => Promise<unknown>;
1307
+ reconnectStrategy?: ReconnectStrategy;
376
1308
  }
377
1309
  declare class RpcClient {
378
- private readonly options;
379
- private ws;
380
- private reconnectTimer?;
381
- private readonly reconnectInterval;
382
- constructor(options: RpcClientOptions);
383
- connect(): Promise<void>;
384
- disconnect(): void;
385
- private createConnection;
386
- private handleMessage;
387
- private handleRpcRequest;
388
- private send;
389
- private scheduleReconnect;
1310
+ private readonly options;
1311
+ private ws;
1312
+ private reconnectTimer?;
1313
+ private reconnectAttempt;
1314
+ private readonly reconnectStrategy;
1315
+ private connectionState;
1316
+ private readonly log;
1317
+ constructor(options: RpcClientOptions);
1318
+ connect(): Promise<void>;
1319
+ disconnect(): void;
1320
+ /**
1321
+ * Get current connection state
1322
+ */
1323
+ getConnectionState(): 'connecting' | 'connected' | 'disconnected';
1324
+ /**
1325
+ * Check if connected
1326
+ */
1327
+ isConnected(): boolean;
1328
+ /**
1329
+ * Send an event message to server (matching document spec)
1330
+ */
1331
+ sendEvent(event: EventRpcMessageEvent): boolean;
1332
+ private createConnection;
1333
+ private handleMessage;
1334
+ /**
1335
+ * Handle event-based command messages from server (matching document spec)
1336
+ */
1337
+ private handleCommandEvent;
1338
+ private handleRpcRequest;
1339
+ private send;
1340
+ private scheduleReconnect;
1341
+ }
1342
+ //#endregion
1343
+ //#region src/rpc/rpc-server.d.ts
1344
+ /**
1345
+ * Command status for tracking
1346
+ */
1347
+ interface RpcCommandStatus {
1348
+ commandId: string;
1349
+ nodeId: string;
1350
+ action: string;
1351
+ status: 'pending' | 'completed' | 'failed';
1352
+ result?: unknown;
1353
+ error?: string;
1354
+ timestamp: number;
390
1355
  }
391
-
392
1356
  interface RpcServerOptions {
393
- port: number;
394
- heartbeatInterval?: number;
395
- logger?: {
396
- info?: (msg: string, data?: unknown) => void;
397
- warn?: (msg: string, data?: unknown) => void;
398
- error?: (msg: string, data?: unknown) => void;
399
- };
400
- validateToken?: (token: string | undefined, nodeId: string | undefined) => boolean | Promise<boolean>;
401
- authorize?: (nodeId: string, method: string) => boolean | Promise<boolean>;
402
- onRegister?: (nodeId: string, payload: NodeInfo$1) => void | Promise<void>;
1357
+ port: number;
1358
+ heartbeatInterval?: number;
1359
+ validateToken?: (token: string | undefined, nodeId: string | undefined) => boolean | Promise<boolean>;
1360
+ authorize?: (nodeId: string, method: string) => boolean | Promise<boolean>;
1361
+ onRegister?: (nodeId: string, payload: NodeInfo$1) => void | Promise<void>;
1362
+ onEvent?: (nodeId: string, event: EventRpcMessage) => void | Promise<void>;
1363
+ commandTimeout?: number;
403
1364
  }
404
1365
  declare class RpcServer {
405
- private readonly options;
406
- private readonly clients;
407
- private readonly pendingRequests;
408
- private readonly wsToNode;
409
- private heartbeatTimer?;
410
- private server?;
411
- constructor(options: RpcServerOptions);
412
- start(): void;
413
- stop(): void;
414
- rpcCall(nodeId: string, method: string, params: Record<string, unknown>, timeout?: number): Promise<unknown>;
415
- private handleMessage;
416
- private handleRpcResponse;
417
- private handleClose;
418
- private startHeartbeat;
1366
+ private readonly options;
1367
+ private readonly clients;
1368
+ private readonly pendingRequests;
1369
+ private readonly commandStatuses;
1370
+ private readonly commandTimers;
1371
+ private readonly wsToNode;
1372
+ private heartbeatTimer?;
1373
+ private cleanupTimer?;
1374
+ private server?;
1375
+ private readonly defaultCommandTimeout;
1376
+ private readonly log;
1377
+ constructor(options: RpcServerOptions);
1378
+ start(): void;
1379
+ stop(): void;
1380
+ rpcCall(nodeId: string, method: string, params: Record<string, unknown>, timeout?: number): Promise<unknown>;
1381
+ /**
1382
+ * Send event-based message to a specific node (matching document spec)
1383
+ */
1384
+ sendToNode(nodeId: string, message: EventRpcMessage): boolean;
1385
+ /**
1386
+ * Broadcast event-based message to all connected nodes
1387
+ */
1388
+ broadcast(message: EventRpcMessage): void;
1389
+ /**
1390
+ * Get list of all online node IDs
1391
+ */
1392
+ getOnlineNodes(): string[];
1393
+ /**
1394
+ * Check if a specific node is online
1395
+ */
1396
+ isNodeOnline(nodeId: string): boolean;
1397
+ /**
1398
+ * Get the count of online nodes
1399
+ */
1400
+ getOnlineNodeCount(): number;
1401
+ /**
1402
+ * Get command status by ID
1403
+ */
1404
+ getRpcCommandStatus(commandId: string): RpcCommandStatus | undefined;
1405
+ /**
1406
+ * Get all command statuses
1407
+ */
1408
+ getAllRpcCommandStatuses(): RpcCommandStatus[];
1409
+ /**
1410
+ * Clear completed/failed command statuses older than specified milliseconds
1411
+ */
1412
+ clearOldStatuses(maxAge?: number): void;
1413
+ private handleMessage;
1414
+ /**
1415
+ * Handle event-based messages from clients
1416
+ */
1417
+ private handleEventMessage;
1418
+ private handleRegister;
1419
+ private handleRpcResponse;
1420
+ private handleClose;
1421
+ private startHeartbeat;
419
1422
  }
420
-
1423
+ //#endregion
1424
+ //#region src/bridge/initializer.d.ts
421
1425
  interface FrpBridgeRuntimeOptions {
422
- id?: string;
423
- mode?: RuntimeMode;
424
- logger?: RuntimeLogger;
425
- clock?: () => number;
426
- platform?: string;
427
- workDir?: string;
1426
+ id?: string;
1427
+ mode?: RuntimeMode;
1428
+ clock?: () => number;
1429
+ platform?: string;
1430
+ workDir?: string;
428
1431
  }
429
1432
  interface FrpBridgeProcessOptions extends Partial<Omit<FrpProcessManagerOptions, 'mode'>> {
430
- mode?: 'client' | 'server';
1433
+ mode?: 'client' | 'server';
431
1434
  }
432
1435
  interface FrpBridgeRpcOptions {
433
- serverPort?: number;
434
- serverHeartbeatInterval?: number;
435
- serverValidateToken?: (token: string | undefined, nodeId: string | undefined) => boolean | Promise<boolean>;
436
- serverAuthorize?: (nodeId: string, method: string) => boolean | Promise<boolean>;
437
- clientUrl?: string;
438
- clientNodeId?: string;
439
- clientToken?: string;
440
- clientReconnectInterval?: number;
441
- getRegisterPayload?: () => Promise<NodeInfo$1> | NodeInfo$1;
442
- handleRequest?: (req: RpcRequest) => Promise<unknown>;
1436
+ serverPort?: number;
1437
+ serverHeartbeatInterval?: number;
1438
+ serverValidateToken?: (token: string | undefined, nodeId: string | undefined) => boolean | Promise<boolean>;
1439
+ serverAuthorize?: (nodeId: string, method: string) => boolean | Promise<boolean>;
1440
+ serverOnRegister?: (nodeId: string, payload: NodeInfo$1) => void | Promise<void>;
1441
+ serverOnEvent?: (nodeId: string, event: EventRpcMessage) => void | Promise<void>;
1442
+ serverCommandTimeout?: number;
1443
+ clientUrl?: string;
1444
+ clientNodeId?: string;
1445
+ clientToken?: string;
1446
+ clientReconnectInterval?: number;
1447
+ getRegisterPayload?: () => Promise<NodeInfo$1> | NodeInfo$1;
1448
+ handleRequest?: (req: RpcRequest$1) => Promise<unknown>;
443
1449
  }
444
-
1450
+ //#endregion
1451
+ //#region src/bridge/index.d.ts
445
1452
  interface FrpBridgeOptions {
446
- mode: 'client' | 'server';
447
- workDir?: string;
448
- configPath?: string;
449
- runtime?: FrpBridgeRuntimeOptions;
450
- process?: FrpBridgeProcessOptions;
451
- rpc?: FrpBridgeRpcOptions;
452
- storage?: SnapshotStorage;
453
- commands?: Record<string, CommandHandler>;
454
- queries?: Record<string, QueryHandler>;
455
- eventSink?: (event: RuntimeEvent) => void;
1453
+ mode: 'client' | 'server';
1454
+ workDir?: string;
1455
+ configPath?: string;
1456
+ runtime?: FrpBridgeRuntimeOptions;
1457
+ process?: FrpBridgeProcessOptions;
1458
+ rpc?: FrpBridgeRpcOptions;
1459
+ storage?: SnapshotStorage;
1460
+ commands?: Record<string, CommandHandler>;
1461
+ queries?: Record<string, QueryHandler>;
1462
+ eventSink?: (event: RuntimeEvent) => void;
456
1463
  }
457
1464
  /**
458
1465
  * FrpBridge - Main facade class for managing FRP bridge operations.
@@ -469,51 +1476,52 @@ interface FrpBridgeOptions {
469
1476
  * - Factory Pattern: Handlers created via factory functions
470
1477
  */
471
1478
  declare class FrpBridge {
472
- private readonly runtime;
473
- private readonly process;
474
- private readonly mode;
475
- private readonly eventSink?;
476
- private readonly nodeManager?;
477
- private readonly clientCollector?;
478
- private readonly rpcServer?;
479
- private readonly rpcClient?;
480
- constructor(options: FrpBridgeOptions);
481
- /**
482
- * Execute a command
483
- */
484
- execute<TPayload, TResult = unknown>(command: RuntimeCommand<TPayload>): Promise<CommandResult<TResult>>;
485
- /**
486
- * Execute a query
487
- */
488
- query<TPayload, TResult = unknown>(query: RuntimeQuery<TPayload>): Promise<QueryResult<TResult>>;
489
- /**
490
- * Get current runtime state snapshot
491
- */
492
- snapshot(): RuntimeState;
493
- /**
494
- * Drain and return all pending events
495
- */
496
- drainEvents(): RuntimeEvent[];
497
- getProcessManager(): FrpProcessManager;
498
- getRuntime(): FrpRuntime;
499
- getNodeManager(): NodeManager | undefined;
500
- getClientCollector(): ClientNodeCollector | undefined;
501
- getRpcServer(): RpcServer | undefined;
502
- getRpcClient(): RpcClient | undefined;
503
- /**
504
- * Initialize all async components
505
- */
506
- initialize(): Promise<void>;
507
- /**
508
- * Cleanup and dispose all resources
509
- */
510
- dispose(): Promise<void>;
511
- /**
512
- * Forward runtime events to external event sink
513
- */
514
- private forwardEvents;
1479
+ private readonly runtime;
1480
+ private readonly process;
1481
+ private readonly mode;
1482
+ private readonly eventSink?;
1483
+ private readonly nodeManager?;
1484
+ private readonly clientCollector?;
1485
+ private readonly rpcServer?;
1486
+ private readonly rpcClient?;
1487
+ constructor(options: FrpBridgeOptions);
1488
+ /**
1489
+ * Execute a command
1490
+ */
1491
+ execute<TPayload, TResult = unknown>(command: RuntimeCommand<TPayload>): Promise<CommandResult<TResult>>;
1492
+ /**
1493
+ * Execute a query
1494
+ */
1495
+ query<TPayload, TResult = unknown>(query: RuntimeQuery<TPayload>): Promise<QueryResult<TResult>>;
1496
+ /**
1497
+ * Get current runtime state snapshot
1498
+ */
1499
+ snapshot(): RuntimeState;
1500
+ /**
1501
+ * Drain and return all pending events
1502
+ */
1503
+ drainEvents(): RuntimeEvent[];
1504
+ getProcessManager(): FrpProcessManager;
1505
+ getRuntime(): FrpRuntime;
1506
+ getNodeManager(): NodeManager | undefined;
1507
+ getClientCollector(): ClientNodeCollector | undefined;
1508
+ getRpcServer(): RpcServer | undefined;
1509
+ getRpcClient(): RpcClient | undefined;
1510
+ /**
1511
+ * Initialize all async components
1512
+ */
1513
+ initialize(): Promise<void>;
1514
+ /**
1515
+ * Cleanup and dispose all resources
1516
+ */
1517
+ dispose(): Promise<void>;
1518
+ /**
1519
+ * Forward runtime events to external event sink
1520
+ */
1521
+ private forwardEvents;
515
1522
  }
516
-
1523
+ //#endregion
1524
+ //#region src/constants/index.d.ts
517
1525
  /**
518
1526
  * Core constants
519
1527
  */
@@ -523,69 +1531,218 @@ declare const GITHUB_OWNER = "fatedier";
523
1531
  declare const GITHUB_REPO = "frp";
524
1532
  /** Platform-specific binary names */
525
1533
  declare const BINARY_NAMES: {
526
- readonly client: "frpc.exe" | "frpc";
527
- readonly server: "frps.exe" | "frps";
1534
+ readonly client: "frpc.exe" | "frpc";
1535
+ readonly server: "frps.exe" | "frps";
528
1536
  };
529
1537
  /** Platform architecture mapping */
530
1538
  declare const ARCH_MAP: Record<string, string>;
531
1539
  /** Platform OS mapping */
532
1540
  declare const OS_MAP: Record<string, string>;
533
-
534
- /** Custom error for FRP Bridge operations */
535
- declare class FrpBridgeError extends Error {
536
- readonly code: string;
537
- readonly details?: unknown | undefined;
538
- constructor(message: string, code: string, details?: unknown | undefined);
539
- }
540
- /** Error codes */
541
- declare enum ErrorCode {
542
- BINARY_NOT_FOUND = "BINARY_NOT_FOUND",
543
- DOWNLOAD_FAILED = "DOWNLOAD_FAILED",
544
- EXTRACTION_FAILED = "EXTRACTION_FAILED",
545
- CONFIG_NOT_FOUND = "CONFIG_NOT_FOUND",
546
- CONFIG_INVALID = "CONFIG_INVALID",
547
- PROCESS_ALREADY_RUNNING = "PROCESS_ALREADY_RUNNING",
548
- PROCESS_NOT_RUNNING = "PROCESS_NOT_RUNNING",
549
- PROCESS_START_FAILED = "PROCESS_START_FAILED",
550
- UNSUPPORTED_PLATFORM = "UNSUPPORTED_PLATFORM",
551
- VERSION_FETCH_FAILED = "VERSION_FETCH_FAILED",
552
- MODE_ERROR = "MODE_ERROR",
553
- NOT_FOUND = "NOT_FOUND"
1541
+ //#endregion
1542
+ //#region src/errors/base-error.d.ts
1543
+ /**
1544
+ * Base error class for all FRP Bridge errors
1545
+ * Provides consistent error structure and handling
1546
+ */
1547
+ declare abstract class FrpBridgeErrorBase extends Error {
1548
+ /**
1549
+ * Error code for programmatic error handling
1550
+ */
1551
+ abstract readonly code: string;
1552
+ /**
1553
+ * HTTP status code (optional, for API responses)
1554
+ */
1555
+ readonly statusCode?: number;
1556
+ /**
1557
+ * Additional error details
1558
+ */
1559
+ readonly details?: unknown;
1560
+ constructor(message: string, details?: unknown);
1561
+ /**
1562
+ * Convert error to plain object for serialization
1563
+ */
1564
+ toJSON(): {
1565
+ code: string;
1566
+ message: string;
1567
+ statusCode?: number;
1568
+ details?: unknown;
1569
+ };
554
1570
  }
555
-
1571
+ /**
1572
+ * Generic error for uncategorized errors
1573
+ */
1574
+ declare class GenericError extends FrpBridgeErrorBase {
1575
+ readonly code: string;
1576
+ constructor(message: string, code: string, details?: unknown);
1577
+ }
1578
+ //#endregion
1579
+ //#region src/errors/categories.d.ts
1580
+ /**
1581
+ * Configuration errors (400 Bad Request)
1582
+ */
1583
+ declare class ConfigNotFoundError extends FrpBridgeErrorBase {
1584
+ readonly code = "CONFIG_NOT_FOUND";
1585
+ readonly statusCode = 400;
1586
+ }
1587
+ declare class ConfigInvalidError extends FrpBridgeErrorBase {
1588
+ readonly code = "CONFIG_INVALID";
1589
+ readonly statusCode = 400;
1590
+ }
1591
+ /**
1592
+ * Process errors
1593
+ */
1594
+ declare class ProcessNotRunningError extends FrpBridgeErrorBase {
1595
+ readonly code = "PROCESS_NOT_RUNNING";
1596
+ readonly statusCode = 409;
1597
+ }
1598
+ declare class ProcessAlreadyRunningError extends FrpBridgeErrorBase {
1599
+ readonly code = "PROCESS_ALREADY_RUNNING";
1600
+ readonly statusCode = 409;
1601
+ }
1602
+ declare class ProcessStartFailedError extends FrpBridgeErrorBase {
1603
+ readonly code = "PROCESS_START_FAILED";
1604
+ readonly statusCode = 500;
1605
+ }
1606
+ /**
1607
+ * Binary errors (500 Internal Server Error)
1608
+ */
1609
+ declare class BinaryNotFoundError extends FrpBridgeErrorBase {
1610
+ readonly code = "BINARY_NOT_FOUND";
1611
+ readonly statusCode = 500;
1612
+ }
1613
+ declare class DownloadFailedError extends FrpBridgeErrorBase {
1614
+ readonly code = "DOWNLOAD_FAILED";
1615
+ readonly statusCode = 500;
1616
+ }
1617
+ declare class ExtractionFailedError extends FrpBridgeErrorBase {
1618
+ readonly code = "EXTRACTION_FAILED";
1619
+ readonly statusCode = 500;
1620
+ }
1621
+ /**
1622
+ * Network/Version errors (503 Service Unavailable)
1623
+ */
1624
+ declare class VersionFetchError extends FrpBridgeErrorBase {
1625
+ readonly code = "VERSION_FETCH_FAILED";
1626
+ readonly statusCode = 503;
1627
+ }
1628
+ /**
1629
+ * Validation errors (400 Bad Request)
1630
+ */
1631
+ declare class ValidationError extends FrpBridgeErrorBase {
1632
+ readonly code = "VALIDATION_ERROR";
1633
+ readonly statusCode = 400;
1634
+ }
1635
+ /**
1636
+ * Mode/State errors (409 Conflict)
1637
+ */
1638
+ declare class ModeError extends FrpBridgeErrorBase {
1639
+ readonly code = "MODE_ERROR";
1640
+ readonly statusCode = 409;
1641
+ }
1642
+ /**
1643
+ * Resource not found (404 Not Found)
1644
+ */
1645
+ declare class NotFoundError extends FrpBridgeErrorBase {
1646
+ readonly code = "NOT_FOUND";
1647
+ readonly statusCode = 404;
1648
+ }
1649
+ /**
1650
+ * Platform errors (500 Internal Server Error)
1651
+ */
1652
+ declare class PlatformError extends FrpBridgeErrorBase {
1653
+ readonly code = "UNSUPPORTED_PLATFORM";
1654
+ readonly statusCode = 500;
1655
+ }
1656
+ //#endregion
1657
+ //#region src/runtime/file-snapshot-storage.d.ts
556
1658
  declare class FileSnapshotStorage implements SnapshotStorage {
557
- private readonly directory;
558
- constructor(directory: string);
559
- save(snapshot: ConfigSnapshot): Promise<void>;
560
- load(version: number): Promise<ConfigSnapshot | undefined>;
561
- list(): Promise<ConfigSnapshot[]>;
562
- private buildPath;
1659
+ private readonly directory;
1660
+ constructor(directory: string);
1661
+ save(snapshot: ConfigSnapshot): Promise<void>;
1662
+ load(version: number): Promise<ConfigSnapshot | undefined>;
1663
+ list(): Promise<ConfigSnapshot[]>;
1664
+ private buildPath;
563
1665
  }
564
-
1666
+ //#endregion
1667
+ //#region src/toml/index.d.ts
565
1668
  /**
566
- * Utility functions
1669
+ * Unified TOML parsing and serialization module
1670
+ * Wraps smol-toml with consistent error handling
567
1671
  */
1672
+ interface ParseOptions {
1673
+ /**
1674
+ * Parse integers as BigInt
1675
+ */
1676
+ integersAsBigInt?: boolean | 'asNeeded';
1677
+ }
1678
+ interface StringifyOptions {
1679
+ /**
1680
+ * Serialize numbers as floats
1681
+ */
1682
+ numbersAsFloat?: boolean;
1683
+ }
1684
+ /**
1685
+ * Parse TOML string to JavaScript object
1686
+ * @param content - TOML string content
1687
+ * @param options - Parse options
1688
+ * @returns Parsed JavaScript object
1689
+ * @throws {Error} If TOML is invalid
1690
+ */
1691
+ declare function parse<T = Record<string, any>>(content: string, options?: ParseOptions): T;
1692
+ /**
1693
+ * Serialize JavaScript object to TOML string
1694
+ * @param obj - JavaScript object to serialize
1695
+ * @param options - Stringify options
1696
+ * @returns TOML string
1697
+ * @throws {Error} If object contains unserializable values
1698
+ */
1699
+ declare function stringify(obj: Record<string, any>, options?: StringifyOptions): string;
1700
+ /**
1701
+ * Check if a string is valid TOML
1702
+ * @param content - String content to check
1703
+ * @returns true if valid TOML, false otherwise
1704
+ */
1705
+ declare function isValidToml(content: string): boolean;
1706
+ /**
1707
+ * Parse TOML file content safely (returns null on error)
1708
+ * @param content - TOML string content
1709
+ * @returns Parsed object or null if parsing fails
1710
+ */
1711
+ declare function safeParse<T = Record<string, any>>(content: string): T | null;
1712
+ //#endregion
1713
+ //#region src/utils/proxy-utils.d.ts
1714
+ /**
1715
+ * Proxy/_tunnel related utility functions
1716
+ */
1717
+ /**
1718
+ * Check if proxy type uses remotePort field
1719
+ */
1720
+ declare function typeUsesRemotePort(type: string): boolean;
1721
+ //#endregion
1722
+ //#region src/utils/index.d.ts
568
1723
  /** Get latest FRP version from GitHub releases */
569
1724
  declare function getLatestVersion(): Promise<string>;
570
1725
  /** Get platform identifier for FRP release */
571
1726
  declare function getPlatform(): string;
572
1727
  /** Get GitHub release download URL */
573
1728
  declare function getDownloadUrl(version: string, platform: string): string;
574
- /** Download file from URL */
575
- declare function downloadFile(url: string, dest: string): Promise<void>;
1729
+ /** Download file from URL with redirect limit */
1730
+ declare function downloadFile(url: string, dest: string, maxRedirects?: number): Promise<void>;
576
1731
  /** Execute command */
577
1732
  declare function executeCommand(command: string): Promise<{
578
- stdout: string;
579
- stderr: string;
1733
+ stdout: string;
1734
+ stderr: string;
580
1735
  }>;
581
1736
  /** Check if command exists */
582
1737
  declare function commandExists(command: string): Promise<boolean>;
583
1738
  /** Ensure directory exists */
584
1739
  declare function ensureDir(dirPath: string): void;
585
- /** Parse TOML-like config to JSON */
586
- declare function parseToml(content: string): Record<string, any>;
587
- /** Convert JSON to TOML-like config */
588
- declare function toToml(obj: Record<string, any>): string;
589
-
590
- export { ARCH_MAP, BINARY_NAMES, ClientNodeCollector, ErrorCode, FileNodeStorage, FileSnapshotStorage, FrpBridge, FrpBridgeError, FrpProcessManager, FrpRuntime, GITHUB_OWNER, GITHUB_REPO, NodeManager, OS_MAP, RpcClient, RpcServer, commandExists, downloadFile, ensureDir, executeCommand, getDownloadUrl, getLatestVersion, getPlatform, parseToml, toToml };
591
- export type { Awaitable, ClientCollectorOptions, CommandHandler, CommandHandlerContext, CommandMetadata, CommandResult, CommandStatus, ConfigSnapshot, FrpBridgeOptions, FrpProcessManagerOptions, NodeEvent, NodeInfo, NodeManagerOptions, NodeStorage, QueryHandler, QueryResult, RpcClientOptions, RpcServerOptions, RuntimeAdapters, RuntimeCommand, RuntimeContext, RuntimeError, RuntimeErrorCode, RuntimeEvent, RuntimeLogger, RuntimeMode, RuntimeQuery, RuntimeState, RuntimeStatus, SnapshotStorage };
1740
+ /** Find existing FRP version in work directory */
1741
+ declare function findExistingVersion(workDir: string): string | null;
1742
+ /**
1743
+ * Omit undefined values from an object
1744
+ * Returns a new object with only defined values
1745
+ */
1746
+ declare function omitUndefined<T extends Record<string, unknown>>(obj: T): T;
1747
+ //#endregion
1748
+ export { ARCH_MAP, AllRpcMessage, Awaitable, BINARY_NAMES, BinaryNotFoundError, type ClientCollectorOptions, ClientNodeCollector, CommandHandler, CommandHandlerContext, CommandMetadata, CommandResult, CommandRpcMessage, CommandStatus, ConfigInvalidError, ConfigNotFoundError, ConfigSnapshot, DEFAULT_PRESET_CONFIG, DownloadFailedError, FrpBridgeErrorBase as Error, FrpBridgeErrorBase, EventRpcMessage, EventRpcMessageEvent, ExponentialBackoffStrategy, ExtractionFailedError, FileNodeStorage, FileSnapshotStorage, FixedIntervalStrategy, FrpBridge, type FrpBridgeOptions, FrpProcessManager, type FrpProcessManagerOptions, FrpRuntime, FrpcPresetConfig, FrpsPresetConfig, GITHUB_OWNER, GITHUB_REPO, GenericError, InfiniteReconnectStrategy, LinearBackoffStrategy, MiddlewareContext, MiddlewareFn, MiddlewareOptions, MiddlewarePipeline, ModeError, NodeDeletePayload, type NodeEvent, type NodeInfo, NodeManager, type NodeManagerOptions, NodeResponsePayload, type NodeStorage, NotFoundError, OS_MAP, ParseOptions, PingMessage, PlatformError, PongMessage, PresetConfig, ProcessAlreadyRunningError, type ProcessEvent, type ProcessEventType, ProcessNotRunningError, ProcessStartFailedError, QueryHandler, QueryResult, ReconnectStrategy, RegisterMessage, RpcClient, RpcClientOptions, RpcCommandStatus, RpcMessage, RpcMessageType, RpcRequest, RpcResponse, RpcResponseStatus, RpcServer, RpcServerOptions, RuntimeAdapters, RuntimeCommand, RuntimeContext, RuntimeError, RuntimeErrorCode, RuntimeEvent, RuntimeLogger, RuntimeMode, RuntimeQuery, RuntimeState, RuntimeStatus, SnapshotStorage, StringifyOptions, TunnelAddPayload, TunnelDeletePayload, TunnelResponsePayload, ValidationError, VersionFetchError, authMiddleware, commandExists, configToToml, downloadFile, ensureDir, errorHandlerMiddleware, executeCommand, findExistingVersion, getDownloadUrl, getLatestVersion, getPlatform, isCommandMessage, isEventMessage, isEventRpcMessage, isNodeDeletePayload, isPingMessage, isPongMessage, isRegisterMessage, isRpcRequest, isRpcResponse, isTunnelAddPayload, isTunnelDeletePayload, isValidToml, loggingMiddleware, mergeConfigs, omitUndefined, parse, safeParse, saveFrpConfigFile, stringify, timeoutMiddleware, typeUsesRemotePort, validatePresetConfig };