@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 +1606 -449
- package/dist/index.js +258 -0
- package/package.json +8 -11
- package/dist/index.d.mts +0 -591
- package/dist/index.mjs +0 -3
package/dist/index.d.mts
DELETED
|
@@ -1,591 +0,0 @@
|
|
|
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';
|
|
3
|
-
|
|
4
|
-
type Awaitable<T> = T | Promise<T>;
|
|
5
|
-
type RuntimeMode = 'client' | 'server';
|
|
6
|
-
type RuntimeStatus = 'idle' | 'starting' | 'running' | 'stopping' | 'error';
|
|
7
|
-
interface RuntimeContext {
|
|
8
|
-
id: string;
|
|
9
|
-
mode: RuntimeMode;
|
|
10
|
-
workDir: string;
|
|
11
|
-
platform: string;
|
|
12
|
-
clock?: () => number;
|
|
13
|
-
logger?: RuntimeLogger;
|
|
14
|
-
}
|
|
15
|
-
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;
|
|
20
|
-
}
|
|
21
|
-
interface RuntimeState {
|
|
22
|
-
status: RuntimeStatus;
|
|
23
|
-
version: number;
|
|
24
|
-
lastAppliedAt?: number;
|
|
25
|
-
lastError?: RuntimeError;
|
|
26
|
-
}
|
|
27
|
-
interface CommandMetadata {
|
|
28
|
-
requestId?: string;
|
|
29
|
-
correlationId?: string;
|
|
30
|
-
author?: string;
|
|
31
|
-
issuedAt?: number;
|
|
32
|
-
}
|
|
33
|
-
interface RuntimeCommand<TPayload = unknown> {
|
|
34
|
-
name: string;
|
|
35
|
-
payload: TPayload;
|
|
36
|
-
metadata?: CommandMetadata;
|
|
37
|
-
}
|
|
38
|
-
interface CommandResult<TResult = unknown> {
|
|
39
|
-
status: CommandStatus;
|
|
40
|
-
version?: number;
|
|
41
|
-
events?: RuntimeEvent[];
|
|
42
|
-
result?: TResult;
|
|
43
|
-
error?: RuntimeError;
|
|
44
|
-
snapshot?: ConfigSnapshot;
|
|
45
|
-
}
|
|
46
|
-
type CommandStatus = 'success' | 'failed' | 'pending';
|
|
47
|
-
interface RuntimeQuery<TPayload = unknown> {
|
|
48
|
-
name: string;
|
|
49
|
-
payload?: TPayload;
|
|
50
|
-
}
|
|
51
|
-
interface QueryResult<TResult = unknown> {
|
|
52
|
-
result: TResult;
|
|
53
|
-
version: number;
|
|
54
|
-
}
|
|
55
|
-
interface RuntimeEvent<TPayload = unknown> {
|
|
56
|
-
type: string;
|
|
57
|
-
timestamp: number;
|
|
58
|
-
version?: number;
|
|
59
|
-
payload?: TPayload;
|
|
60
|
-
}
|
|
61
|
-
interface RuntimeError {
|
|
62
|
-
code: RuntimeErrorCode;
|
|
63
|
-
message: string;
|
|
64
|
-
details?: Record<string, unknown>;
|
|
65
|
-
}
|
|
66
|
-
type RuntimeErrorCode = 'VALIDATION_ERROR' | 'RUNTIME_ERROR' | 'SYSTEM_ERROR' | 'PORT_CONFLICT' | 'RPC_NOT_AVAILABLE' | 'RPC_ERROR';
|
|
67
|
-
interface ConfigSnapshot {
|
|
68
|
-
version: number;
|
|
69
|
-
checksum: string;
|
|
70
|
-
appliedAt: number;
|
|
71
|
-
author?: string;
|
|
72
|
-
summary?: string;
|
|
73
|
-
}
|
|
74
|
-
interface SnapshotStorage {
|
|
75
|
-
save: (snapshot: ConfigSnapshot) => Awaitable<void>;
|
|
76
|
-
load: (version: number) => Awaitable<ConfigSnapshot | undefined>;
|
|
77
|
-
list: () => Awaitable<ConfigSnapshot[]>;
|
|
78
|
-
}
|
|
79
|
-
interface CommandHandlerContext {
|
|
80
|
-
context: RuntimeContext;
|
|
81
|
-
state: RuntimeState;
|
|
82
|
-
emit: (events: RuntimeEvent[]) => void;
|
|
83
|
-
requestVersionBump: () => number;
|
|
84
|
-
}
|
|
85
|
-
type CommandHandler<TPayload = unknown, TResult = unknown> = (command: RuntimeCommand<TPayload>, ctx: CommandHandlerContext) => Awaitable<CommandResult<TResult>>;
|
|
86
|
-
type QueryHandler<TPayload = unknown, TResult = unknown> = (query: RuntimeQuery<TPayload>, ctx: RuntimeContext) => Awaitable<QueryResult<TResult>>;
|
|
87
|
-
interface RuntimeAdapters {
|
|
88
|
-
storage?: SnapshotStorage;
|
|
89
|
-
commands?: Record<string, CommandHandler>;
|
|
90
|
-
queries?: Record<string, QueryHandler>;
|
|
91
|
-
}
|
|
92
|
-
|
|
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;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Client-side node information collector
|
|
119
|
-
* Gathers system information and reports to server via heartbeat
|
|
120
|
-
*/
|
|
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;
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Collects node information on client side
|
|
136
|
-
* Used in client mode to send system info and heartbeat to server
|
|
137
|
-
*/
|
|
138
|
-
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;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Node Manager for server-side node management
|
|
163
|
-
* Handles node registration, heartbeat, tunnel registry, and queries
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
interface NodeManagerOptions {
|
|
167
|
-
heartbeatTimeout?: number;
|
|
168
|
-
logger?: any;
|
|
169
|
-
}
|
|
170
|
-
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[];
|
|
175
|
-
}
|
|
176
|
-
type NodeEvent = 'node:registered' | 'node:heartbeat' | 'node:unregistered' | 'node:statusChanged' | 'tunnel:synced';
|
|
177
|
-
/**
|
|
178
|
-
* Manages nodes in server mode
|
|
179
|
-
* Stores node info, handles heartbeat, manages global tunnel registry, emits events
|
|
180
|
-
*/
|
|
181
|
-
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>;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* File-based node storage implementation
|
|
237
|
-
* Persists node information to disk
|
|
238
|
-
*/
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Stores nodes in JSON files
|
|
242
|
-
* Directory structure:
|
|
243
|
-
* ~/.frp-bridge/runtime/nodes/
|
|
244
|
-
* ├── nodes.json (index of all nodes)
|
|
245
|
-
* └── node-{id}.json (individual node data)
|
|
246
|
-
*/
|
|
247
|
-
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;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* FRP process management utilities
|
|
266
|
-
*/
|
|
267
|
-
|
|
268
|
-
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;
|
|
279
|
-
}
|
|
280
|
-
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>;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Manages FRP client/server lifecycle, config, and tunnels
|
|
296
|
-
*/
|
|
297
|
-
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;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
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
|
-
};
|
|
376
|
-
}
|
|
377
|
-
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;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
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>;
|
|
403
|
-
}
|
|
404
|
-
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;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
interface FrpBridgeRuntimeOptions {
|
|
422
|
-
id?: string;
|
|
423
|
-
mode?: RuntimeMode;
|
|
424
|
-
logger?: RuntimeLogger;
|
|
425
|
-
clock?: () => number;
|
|
426
|
-
platform?: string;
|
|
427
|
-
workDir?: string;
|
|
428
|
-
}
|
|
429
|
-
interface FrpBridgeProcessOptions extends Partial<Omit<FrpProcessManagerOptions, 'mode'>> {
|
|
430
|
-
mode?: 'client' | 'server';
|
|
431
|
-
}
|
|
432
|
-
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>;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
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;
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* FrpBridge - Main facade class for managing FRP bridge operations.
|
|
459
|
-
*
|
|
460
|
-
* This class serves as a facade that coordinates multiple components:
|
|
461
|
-
* - Runtime management (command/query execution)
|
|
462
|
-
* - Process management (FRP process lifecycle)
|
|
463
|
-
* - Node management (server mode only)
|
|
464
|
-
* - RPC communication
|
|
465
|
-
*
|
|
466
|
-
* Design patterns used:
|
|
467
|
-
* - Facade Pattern: Simplifies interface to complex subsystems
|
|
468
|
-
* - Dependency Injection: All dependencies injected via constructor
|
|
469
|
-
* - Factory Pattern: Handlers created via factory functions
|
|
470
|
-
*/
|
|
471
|
-
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;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Core constants
|
|
519
|
-
*/
|
|
520
|
-
/** GitHub repository owner */
|
|
521
|
-
declare const GITHUB_OWNER = "fatedier";
|
|
522
|
-
/** GitHub repository name */
|
|
523
|
-
declare const GITHUB_REPO = "frp";
|
|
524
|
-
/** Platform-specific binary names */
|
|
525
|
-
declare const BINARY_NAMES: {
|
|
526
|
-
readonly client: "frpc.exe" | "frpc";
|
|
527
|
-
readonly server: "frps.exe" | "frps";
|
|
528
|
-
};
|
|
529
|
-
/** Platform architecture mapping */
|
|
530
|
-
declare const ARCH_MAP: Record<string, string>;
|
|
531
|
-
/** Platform OS mapping */
|
|
532
|
-
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"
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
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;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Utility functions
|
|
567
|
-
*/
|
|
568
|
-
/** Get latest FRP version from GitHub releases */
|
|
569
|
-
declare function getLatestVersion(): Promise<string>;
|
|
570
|
-
/** Get platform identifier for FRP release */
|
|
571
|
-
declare function getPlatform(): string;
|
|
572
|
-
/** Get GitHub release download URL */
|
|
573
|
-
declare function getDownloadUrl(version: string, platform: string): string;
|
|
574
|
-
/** Download file from URL */
|
|
575
|
-
declare function downloadFile(url: string, dest: string): Promise<void>;
|
|
576
|
-
/** Execute command */
|
|
577
|
-
declare function executeCommand(command: string): Promise<{
|
|
578
|
-
stdout: string;
|
|
579
|
-
stderr: string;
|
|
580
|
-
}>;
|
|
581
|
-
/** Check if command exists */
|
|
582
|
-
declare function commandExists(command: string): Promise<boolean>;
|
|
583
|
-
/** Ensure directory exists */
|
|
584
|
-
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 };
|