@tmlmobilidade/ssh 20260714.1322.11 → 20260714.1333.48
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/client.d.ts +2 -1
- package/dist/client.js +6 -2
- package/dist/ssh.factory.js +9 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -12,9 +12,10 @@ export interface SshTunnelOptions {
|
|
|
12
12
|
export declare class SshTunnel {
|
|
13
13
|
private _server;
|
|
14
14
|
private config;
|
|
15
|
+
private onDisconnect?;
|
|
15
16
|
private options;
|
|
16
17
|
private retries;
|
|
17
|
-
constructor(config: SshConfig, options?: SshTunnelOptions);
|
|
18
|
+
constructor(config: SshConfig, options?: SshTunnelOptions, onDisconnect?: () => void);
|
|
18
19
|
get server(): Server | undefined;
|
|
19
20
|
/**
|
|
20
21
|
* Establishes an SSH tunnel connection using the provided configuration options.
|
package/dist/client.js
CHANGED
|
@@ -5,10 +5,12 @@ import { createTunnel } from 'tunnel-ssh';
|
|
|
5
5
|
export class SshTunnel {
|
|
6
6
|
_server;
|
|
7
7
|
config;
|
|
8
|
+
onDisconnect;
|
|
8
9
|
options;
|
|
9
10
|
retries = 0;
|
|
10
|
-
constructor(config, options) {
|
|
11
|
+
constructor(config, options, onDisconnect) {
|
|
11
12
|
this.config = config;
|
|
13
|
+
this.onDisconnect = onDisconnect;
|
|
12
14
|
if (options)
|
|
13
15
|
this.options = options;
|
|
14
16
|
}
|
|
@@ -69,7 +71,9 @@ export class SshTunnel {
|
|
|
69
71
|
*/
|
|
70
72
|
async disconnect() {
|
|
71
73
|
try {
|
|
72
|
-
this._server
|
|
74
|
+
this._server?.close();
|
|
75
|
+
this._server = undefined;
|
|
76
|
+
this.onDisconnect?.();
|
|
73
77
|
console.log(`⤷ SSH Tunnel disconnected.`);
|
|
74
78
|
}
|
|
75
79
|
catch (error) {
|
package/dist/ssh.factory.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { randomInt } from 'node:crypto';
|
|
3
3
|
import { readFileSync } from 'node:fs';
|
|
4
4
|
import { SshTunnel } from './client.js';
|
|
5
|
+
const tunnelCache = new Map();
|
|
5
6
|
/**
|
|
6
7
|
* Creates an SSH tunnel factory for the given type.
|
|
7
8
|
*
|
|
@@ -68,5 +69,12 @@ function buildSshTunnel(type, options) {
|
|
|
68
69
|
const sshOptions = {
|
|
69
70
|
maxRetries: maxRetries ?? 3,
|
|
70
71
|
};
|
|
71
|
-
|
|
72
|
+
const cacheKey = `${type}:${dstAddr}:${dstPort}`;
|
|
73
|
+
const cached = tunnelCache.get(cacheKey);
|
|
74
|
+
if (cached) {
|
|
75
|
+
return cached;
|
|
76
|
+
}
|
|
77
|
+
const tunnel = new SshTunnel(sshConfig, sshOptions, () => tunnelCache.delete(cacheKey));
|
|
78
|
+
tunnelCache.set(cacheKey, tunnel);
|
|
79
|
+
return tunnel;
|
|
72
80
|
}
|