@limrun/api 0.5.1 → 0.6.2
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/CHANGELOG.md +23 -97
- package/client.d.mts +6 -6
- package/client.d.mts.map +1 -1
- package/client.d.ts +6 -6
- package/client.d.ts.map +1 -1
- package/client.js +12 -6
- package/client.js.map +1 -1
- package/client.mjs +12 -6
- package/client.mjs.map +1 -1
- package/index.d.mts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -2
- package/index.js.map +1 -1
- package/index.mjs +0 -1
- package/package.json +1 -1
- package/resources/android-instances-helpers.d.mts +51 -24
- package/resources/android-instances-helpers.d.mts.map +1 -1
- package/resources/android-instances-helpers.d.ts +51 -24
- package/resources/android-instances-helpers.d.ts.map +1 -1
- package/resources/android-instances-helpers.js +199 -107
- package/resources/android-instances-helpers.js.map +1 -1
- package/resources/android-instances-helpers.mjs +198 -103
- package/resources/android-instances-helpers.mjs.map +1 -1
- package/resources/android-instances.d.mts +4 -7
- package/resources/android-instances.d.mts.map +1 -1
- package/resources/android-instances.d.ts +4 -7
- package/resources/android-instances.d.ts.map +1 -1
- package/resources/android-instances.js.map +1 -1
- package/resources/android-instances.mjs.map +1 -1
- package/resources/assets-helpers.d.mts.map +1 -1
- package/resources/assets-helpers.d.ts.map +1 -1
- package/resources/assets-helpers.js +6 -4
- package/resources/assets-helpers.js.map +1 -1
- package/resources/assets-helpers.mjs +6 -4
- package/resources/assets-helpers.mjs.map +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/tunnel.d.mts +25 -0
- package/resources/tunnel.d.mts.map +1 -0
- package/resources/tunnel.d.ts +25 -0
- package/resources/tunnel.d.ts.map +1 -0
- package/resources/tunnel.js +102 -0
- package/resources/tunnel.js.map +1 -0
- package/resources/tunnel.mjs +98 -0
- package/resources/tunnel.mjs.map +1 -0
- package/src/client.ts +18 -14
- package/src/index.ts +0 -2
- package/src/resources/android-instances-helpers.ts +318 -127
- package/src/resources/android-instances.ts +3 -8
- package/src/resources/assets-helpers.ts +7 -4
- package/src/resources/index.ts +0 -1
- package/src/resources/tunnel.ts +126 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as net from 'net';
|
|
2
|
+
import { WebSocket } from 'ws';
|
|
3
|
+
|
|
4
|
+
export interface Tunnel {
|
|
5
|
+
address: {
|
|
6
|
+
address: string;
|
|
7
|
+
port: number;
|
|
8
|
+
};
|
|
9
|
+
close: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Starts a one-shot TCP → WebSocket proxy.
|
|
14
|
+
*
|
|
15
|
+
* The function creates a local TCP server that listens on an ephemeral port on
|
|
16
|
+
* 127.0.0.1. As soon as the **first** TCP client connects the server stops
|
|
17
|
+
* accepting further connections and forwards all traffic between that client
|
|
18
|
+
* and `remoteURL` through an authenticated WebSocket. If you need to proxy
|
|
19
|
+
* more than one TCP connection, call `startTcpTunnel` again to create a new
|
|
20
|
+
* proxy instance.
|
|
21
|
+
*
|
|
22
|
+
* @param remoteURL Remote WebSocket endpoint (e.g. wss://example.com/instance)
|
|
23
|
+
* @param token Bearer token sent as `Authorization` header
|
|
24
|
+
* @param hostname Optional IP address to listen on. Default is 127.0.0.1
|
|
25
|
+
* @param port Optional port number to listen on. Default is to ask Node.js
|
|
26
|
+
* to find an available non-privileged port.
|
|
27
|
+
*/
|
|
28
|
+
export async function startTcpTunnel(
|
|
29
|
+
remoteURL: string,
|
|
30
|
+
token: string,
|
|
31
|
+
hostname: string,
|
|
32
|
+
port: number,
|
|
33
|
+
): Promise<Tunnel> {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const server = net.createServer();
|
|
36
|
+
|
|
37
|
+
let ws: WebSocket | undefined;
|
|
38
|
+
let pingInterval: NodeJS.Timeout | undefined;
|
|
39
|
+
|
|
40
|
+
// close helper
|
|
41
|
+
const close = () => {
|
|
42
|
+
if (pingInterval) {
|
|
43
|
+
clearInterval(pingInterval);
|
|
44
|
+
pingInterval = undefined;
|
|
45
|
+
}
|
|
46
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
47
|
+
ws.close(1000, 'close');
|
|
48
|
+
}
|
|
49
|
+
if (server.listening) {
|
|
50
|
+
server.close();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// No AbortController support – proxy can be closed via the returned handle
|
|
55
|
+
|
|
56
|
+
// TCP server error
|
|
57
|
+
server.once('error', (err) => {
|
|
58
|
+
close();
|
|
59
|
+
reject(new Error(`TCP server error: ${err.message}`));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Listening
|
|
63
|
+
server.once('listening', () => {
|
|
64
|
+
const address = server.address();
|
|
65
|
+
if (!address || typeof address === 'string') {
|
|
66
|
+
close();
|
|
67
|
+
return reject(new Error('Failed to obtain listening address'));
|
|
68
|
+
}
|
|
69
|
+
resolve({ address, close });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// On first TCP connection
|
|
73
|
+
server.on('connection', (tcpSocket) => {
|
|
74
|
+
// Single-connection proxy
|
|
75
|
+
server.close();
|
|
76
|
+
|
|
77
|
+
ws = new WebSocket(remoteURL, {
|
|
78
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
79
|
+
perMessageDeflate: false,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// WebSocket error
|
|
83
|
+
ws.once('error', (err: any) => {
|
|
84
|
+
console.error('WebSocket error:', err);
|
|
85
|
+
tcpSocket.destroy();
|
|
86
|
+
close();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
ws.once('open', () => {
|
|
90
|
+
const socket = ws as WebSocket; // non-undefined after open
|
|
91
|
+
|
|
92
|
+
pingInterval = setInterval(() => {
|
|
93
|
+
if (socket.readyState === WebSocket.OPEN) {
|
|
94
|
+
(socket as any).ping();
|
|
95
|
+
}
|
|
96
|
+
}, 30_000);
|
|
97
|
+
|
|
98
|
+
// TCP → WS
|
|
99
|
+
tcpSocket.on('data', (chunk) => {
|
|
100
|
+
if (socket.readyState === WebSocket.OPEN) {
|
|
101
|
+
socket.send(chunk);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// WS → TCP
|
|
106
|
+
socket.on('message', (data: any) => {
|
|
107
|
+
if (!tcpSocket.destroyed) {
|
|
108
|
+
tcpSocket.write(data as Buffer);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Mutual close
|
|
114
|
+
tcpSocket.on('close', close);
|
|
115
|
+
tcpSocket.on('error', (err: any) => {
|
|
116
|
+
console.error('TCP socket error:', err);
|
|
117
|
+
close();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
ws.on('close', () => tcpSocket.destroy());
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Start listening
|
|
124
|
+
server.listen(port, hostname);
|
|
125
|
+
});
|
|
126
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.6.2'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.6.2";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.6.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.6.2'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|