Skip to content

Commit dafed78

Browse files
authored
Add typescript support (tewarid#36)
1 parent a092df5 commit dafed78

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

index.d.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Socket } from 'net';
2+
import { TLSSocket } from 'tls';
3+
4+
// Name or IP address of service host(s); if this is a list, performs round-robin load balancing
5+
type ServiceHost = string | string[];
6+
7+
// Service port number(s); if this a list, it should have as many entries as serviceHost
8+
type ServicePort = string | number | number[];
9+
10+
interface ContextBase {
11+
buffers: Buffer[];
12+
connect: boolean;
13+
}
14+
15+
interface UpstreamContext extends ContextBase {
16+
proxySocket: Socket | TLSSocket;
17+
}
18+
19+
interface DownstreamContext extends ContextBase {
20+
serviceSocket: Socket | TLSSocket;
21+
}
22+
23+
interface TcpProxyOptions {
24+
// Name or IP address of host
25+
hostname: string;
26+
// IP address of interface to use to connect to service
27+
localAddress: string;
28+
// Port number to use to connect to service
29+
localPort: number;
30+
// Be quiet, default: true
31+
quiet: boolean;
32+
// Use TLS 1.2 with clients; specify both to also use TLS 1.2 with service
33+
tls: boolean;
34+
// Do not accept invalid certificate, default: true
35+
rejectUnauthorized: boolean;
36+
// Private key file path, for example: ./cert.pfx
37+
pfx: string;
38+
// Passphrase to access private key file
39+
passphrase: string;
40+
// List of authorized users
41+
identUsers: string[];
42+
// List of allowed IPs
43+
allowedIPs: string[];
44+
serviceHostSelected: (proxySocket: Socket | TLSSocket, i: number) => number;
45+
upstream: (context: UpstreamContext, data: Buffer) => Buffer;
46+
downstream: (context: DownstreamContext, data: Buffer) => Buffer;
47+
}
48+
49+
declare class TcpProxy {
50+
constructor(
51+
proxyPort: number,
52+
serviceHost: ServiceHost,
53+
servicePort: ServicePort,
54+
options?: Partial<TcpProxyOptions>
55+
);
56+
end(): void;
57+
}
58+
59+
export function createProxy(
60+
proxyPort: number,
61+
serviceHost: ServiceHost,
62+
servicePort: ServicePort,
63+
options?: Partial<TcpProxyOptions>
64+
): TcpProxy;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "MIT",
55
"version": "0.0.26",
66
"main": "index.js",
7+
"types": "./index.d.ts",
78
"repository": {
89
"type": "git",
910
"url": "https://github.com/tewarid/node-tcp-proxy.git"

0 commit comments

Comments
 (0)