@opentunnel/client 0.2.0 → 0.2.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/package.json +2 -2
- package/src/effect/api.ts +7 -1
- package/src/effect/tunnel.ts +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentunnel/client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "OpenTunnel SDK for Bun: expose local services through a blind TLS tunnel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"test": "bun test"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@opentunnel/protocol": "0.2.
|
|
31
|
+
"@opentunnel/protocol": "0.2.2",
|
|
32
32
|
"effect": "4.0.0-rc.112"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
package/src/effect/api.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Effect, Layer, Context } from "effect";
|
|
2
2
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
3
|
+
import pkg from "../../package.json" with { type: "json" };
|
|
3
4
|
import { HttpApiClient } from "effect/unstable/httpapi";
|
|
4
5
|
import { Api } from "@opentunnel/protocol/api/api";
|
|
5
6
|
import { Tunnel } from "@opentunnel/protocol/tunnel";
|
|
6
7
|
|
|
8
|
+
/** How the SDK identifies itself to the server, on API calls and the bridge. */
|
|
9
|
+
export const USER_AGENT = `opentunnel-sdk/${pkg.version}`;
|
|
10
|
+
|
|
7
11
|
type Client = HttpApiClient.ForApi<typeof Api>;
|
|
8
12
|
|
|
9
13
|
interface OpenTunnelApi {
|
|
@@ -18,7 +22,9 @@ export class OpenTunnelApiClient extends Context.Service<OpenTunnelApiClient, Op
|
|
|
18
22
|
return Layer.effect(
|
|
19
23
|
OpenTunnelApiClient,
|
|
20
24
|
Effect.gen(function* () {
|
|
21
|
-
const httpClient = yield* HttpClient.HttpClient
|
|
25
|
+
const httpClient = (yield* HttpClient.HttpClient).pipe(
|
|
26
|
+
HttpClient.mapRequest(HttpClientRequest.setHeader("user-agent", USER_AGENT)),
|
|
27
|
+
);
|
|
22
28
|
const client = yield* HttpApiClient.makeWith(Api, {
|
|
23
29
|
baseUrl: options.api,
|
|
24
30
|
httpClient,
|
package/src/effect/tunnel.ts
CHANGED
|
@@ -4,6 +4,13 @@ import { Duplex } from "node:stream";
|
|
|
4
4
|
import * as Tls from "node:tls";
|
|
5
5
|
import { BridgeProtocol } from "@opentunnel/protocol/bridge-protocol";
|
|
6
6
|
import { Names } from "@opentunnel/protocol/names";
|
|
7
|
+
import { USER_AGENT } from "./api.js";
|
|
8
|
+
|
|
9
|
+
/** Bun's WebSocket also takes options with request headers, which the DOM typings don't know about. */
|
|
10
|
+
const BunWebSocket = WebSocket as unknown as new (
|
|
11
|
+
url: URL,
|
|
12
|
+
options: { readonly protocols: string[]; readonly headers: Record<string, string> },
|
|
13
|
+
) => WebSocket;
|
|
7
14
|
import type {
|
|
8
15
|
OpenTunnelClientEvent,
|
|
9
16
|
OpenTunnelIdentity,
|
|
@@ -308,7 +315,10 @@ class Session {
|
|
|
308
315
|
this.options.api,
|
|
309
316
|
);
|
|
310
317
|
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
311
|
-
const socket = new
|
|
318
|
+
const socket = new BunWebSocket(url, {
|
|
319
|
+
protocols: [BridgeProtocol.WEBSOCKET_SUBPROTOCOL],
|
|
320
|
+
headers: { "user-agent": USER_AGENT },
|
|
321
|
+
});
|
|
312
322
|
socket.binaryType = "arraybuffer";
|
|
313
323
|
this.socket = socket;
|
|
314
324
|
this.attachTimeout = setTimeout(
|