@hediet/linkrpc-hub 0.0.1

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.
Files changed (50) hide show
  1. package/README.md +101 -0
  2. package/dist/chunks/config-BCvkg7jv.d.ts +566 -0
  3. package/dist/chunks/configFile-y6Phntqu.d.ts +9 -0
  4. package/dist/chunks/connectionTokenBinder.interfaces-B-beCg06.js +40 -0
  5. package/dist/chunks/connectionTokenBinder.interfaces-B-beCg06.js.map +1 -0
  6. package/dist/chunks/connectionTokenBinder.interfaces-BhzQ1DTS.d.ts +36 -0
  7. package/dist/chunks/hubConnectionAcceptor-B5-8JsFY.js +2768 -0
  8. package/dist/chunks/hubConnectionAcceptor-B5-8JsFY.js.map +1 -0
  9. package/dist/chunks/hubConnectionAcceptor-BwydvFa4.d.ts +1560 -0
  10. package/dist/chunks/index-CLIUrV88.d.ts +481 -0
  11. package/dist/chunks/node-CTXsQ6oa.js +460 -0
  12. package/dist/chunks/node-CTXsQ6oa.js.map +1 -0
  13. package/dist/chunks/nodeTransit-CWeFnbwt.js +444 -0
  14. package/dist/chunks/nodeTransit-CWeFnbwt.js.map +1 -0
  15. package/dist/chunks/nodeTransit-cmtZgdpW.d.ts +226 -0
  16. package/dist/chunks/runHub-P3YUwwdv.js +1797 -0
  17. package/dist/chunks/runHub-P3YUwwdv.js.map +1 -0
  18. package/dist/chunks/server-BAxchQhy.js +1368 -0
  19. package/dist/chunks/server-BAxchQhy.js.map +1 -0
  20. package/dist/cli.d.ts +1 -0
  21. package/dist/cli.js +38 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/config.d.ts +2 -0
  24. package/dist/config.js +305 -0
  25. package/dist/config.js.map +1 -0
  26. package/dist/configFile.d.ts +2 -0
  27. package/dist/configFile.js +27 -0
  28. package/dist/configFile.js.map +1 -0
  29. package/dist/engine/runHub.d.ts +42 -0
  30. package/dist/engine/runHub.js +2 -0
  31. package/dist/hub/server/client.d.ts +2 -0
  32. package/dist/hub/server/client.js +2 -0
  33. package/dist/hub/server/connectionTokenBinder.d.ts +2 -0
  34. package/dist/hub/server/connectionTokenBinder.js +2 -0
  35. package/dist/hub/server/index.d.ts +5 -0
  36. package/dist/hub/server/index.js +5 -0
  37. package/dist/hub/server/node/index.d.ts +218 -0
  38. package/dist/hub/server/node/index.js +2 -0
  39. package/dist/hub/server/transit.d.ts +2 -0
  40. package/dist/hub/server/transit.js +2 -0
  41. package/dist/index.d.ts +512 -0
  42. package/dist/index.js +309 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/serve.d.ts +14 -0
  45. package/dist/serve.js +31 -0
  46. package/dist/serve.js.map +1 -0
  47. package/dist/spawn.d.ts +12 -0
  48. package/dist/spawn.js +25 -0
  49. package/dist/spawn.js.map +1 -0
  50. package/package.json +83 -0
@@ -0,0 +1,218 @@
1
+ import { IMessageTransport, JsonRpcMessage } from "@hediet/linkrpc";
2
+ import { ITransportServer, Transport } from "@hediet/linkrpc/hub/common";
3
+ import { TopologyTransportInfo } from "@hediet/linkrpc/inspection";
4
+ import * as net from "node:net";
5
+ import * as http from "node:http";
6
+ import { WebSocket } from "ws";
7
+ //#region src/hub/server/node/socketServer.d.ts
8
+ /**
9
+ * A {@link Transport} over a Node socket that still exposes the underlying
10
+ * {@link net.Socket}. Provenance providers (peercred, etc.) read `socket`;
11
+ * the hub core never does. Framing is newline-delimited JSON, and the
12
+ * connection has already completed the `hubrpc::initialize` handshake.
13
+ */
14
+ declare class NodeSocketTransport implements Transport {
15
+ readonly socket: net.Socket;
16
+ private readonly _inner;
17
+ readonly topologyInfo?: TopologyTransportInfo | undefined;
18
+ private readonly _closeHandlers;
19
+ private _closed;
20
+ /**
21
+ * Token presented by the peer in the `hubrpc::initialize` handshake. When
22
+ * the server was started with {@link SocketServerOptions.isTokenAccepted}
23
+ * the token has already been validated (the connection would otherwise have
24
+ * been dropped); a {@link ConnectionProvenanceProvider} can read it to
25
+ * further attest the peer (e.g. map a one-shot run token to an identity).
26
+ * `undefined` when the handshake carried no token.
27
+ */
28
+ initializeToken: string | undefined;
29
+ constructor(socket: net.Socket, _inner: IMessageTransport, topologyInfo?: TopologyTransportInfo | undefined);
30
+ send(message: JsonRpcMessage): void | Promise<void>;
31
+ setListener(listener: ((message: JsonRpcMessage) => void) | undefined): void;
32
+ onDidClose(handler: () => void): void;
33
+ dispose(): void;
34
+ private _fireClose;
35
+ }
36
+ interface SocketServerOptions {
37
+ /**
38
+ * Named pipe (Windows) / UDS path (Unix) to listen on. Defaults to a
39
+ * per-instance computed path.
40
+ */
41
+ readonly endpoint?: string;
42
+ /**
43
+ * Validate the token presented in the client's `hubrpc::initialize`
44
+ * handshake. Resolve `true` to admit the connection, `false` to reject it
45
+ * (the socket is dropped before it reaches the connection handler). Called
46
+ * live on every connection, so a dynamic allow-list (e.g. one-shot run
47
+ * tokens added for the lifetime of a spawned child) is re-read per connect.
48
+ *
49
+ * Omit to accept any token: the handshake is still required and the token
50
+ * is captured onto {@link NodeSocketTransport.initializeToken} for a
51
+ * provenance provider, but it is not gated.
52
+ */
53
+ readonly isTokenAccepted?: (token: string | undefined) => Promise<boolean>;
54
+ }
55
+ /**
56
+ * A hub-agnostic {@link ITransportServer} over a named pipe / UDS. It listens,
57
+ * accepts, runs the `hubrpc::initialize` handshake (authentication + protocol
58
+ * negotiation), frames each socket as a {@link NodeSocketTransport}, and hands
59
+ * it to the connection handler — no hub coupling. Compose
60
+ * attestation/identity on top via `withProvenance` and
61
+ * {@link HubConnectionAcceptor}.
62
+ *
63
+ * The handshake's token is validated via
64
+ * {@link SocketServerOptions.isTokenAccepted} when provided; otherwise any
65
+ * token is accepted and merely captured for a provenance provider.
66
+ */
67
+ declare class SocketServer implements ITransportServer<NodeSocketTransport> {
68
+ private readonly _server;
69
+ private readonly _endpoint;
70
+ private readonly _live;
71
+ private readonly _isTokenAccepted;
72
+ private _handler;
73
+ private _disposed;
74
+ private constructor();
75
+ /** Bind + listen (with stale-UDS unlink retry), resolving once ready. */
76
+ static start(options?: SocketServerOptions): Promise<SocketServer>;
77
+ /** Allocate a fresh, unused socket path (named pipe on Windows, UDS elsewhere). */
78
+ static allocSocketPath(): string;
79
+ get endpoint(): string;
80
+ setConnectionHandler(handler: (transport: NodeSocketTransport) => void): void;
81
+ dispose(): void;
82
+ private _onConnection;
83
+ /**
84
+ * Run the `hubrpc::initialize` handshake on the freshly accepted socket,
85
+ * then frame it as a {@link NodeSocketTransport} and hand it to the
86
+ * connection handler. A failed handshake (bad/missing token, wrong first
87
+ * message, or timeout) drops the socket without reaching the handler.
88
+ */
89
+ private _acceptConnection;
90
+ private _listenWithRetry;
91
+ private _listenOnce;
92
+ }
93
+ //#endregion
94
+ //#region src/hub/server/node/webSocketServer.d.ts
95
+ /**
96
+ * A {@link Transport} over a server-side `ws` WebSocket. One JSON-RPC message
97
+ * per text frame; binary frames are decoded as UTF-8 and unparseable frames
98
+ * are dropped (the same lenient behaviour as {@link NodeSocketTransport}).
99
+ *
100
+ * The transport takes ownership of the socket: {@link dispose} closes it, and
101
+ * a peer close / error fires {@link onDidClose} handlers exactly once.
102
+ */
103
+ declare class NodeWebSocketTransport implements Transport {
104
+ readonly socket: WebSocket;
105
+ readonly topologyInfo?: TopologyTransportInfo | undefined;
106
+ private _listener;
107
+ private readonly _buffer;
108
+ private readonly _closeHandlers;
109
+ private _closed;
110
+ /**
111
+ * Token presented by the peer in the `hubrpc::initialize` handshake, when
112
+ * the server ran one. A {@link ConnectionProvenanceProvider} can read it to
113
+ * attest the peer. `undefined` when the handshake carried no token.
114
+ */
115
+ initializeToken: string | undefined;
116
+ constructor(socket: WebSocket, topologyInfo?: TopologyTransportInfo | undefined);
117
+ send(message: JsonRpcMessage): void;
118
+ setListener(listener: ((m: JsonRpcMessage) => void) | undefined): void;
119
+ onDidClose(handler: () => void): void;
120
+ dispose(): void;
121
+ private _fireClose;
122
+ private _deliver;
123
+ }
124
+ type WebSocketServerEvent = {
125
+ readonly kind: 'accepted';
126
+ readonly remoteAddress: string | undefined;
127
+ } | {
128
+ readonly kind: 'rejected';
129
+ readonly reason: string;
130
+ readonly remoteAddress: string | undefined;
131
+ } | {
132
+ readonly kind: 'closed';
133
+ readonly remoteAddress: string | undefined;
134
+ };
135
+ interface WebSocketServerOptions {
136
+ /** TCP port to listen on. Defaults to an OS-assigned free port (`0`). */
137
+ readonly port?: number;
138
+ /** Host/interface to bind. Defaults to all interfaces. */
139
+ readonly host?: string;
140
+ /**
141
+ * Validate the token presented in the client's `hubrpc::initialize`
142
+ * handshake. Resolve `true` to admit the connection, `false` to reject it.
143
+ * Required unless {@link allowAnonymous} is set. Browsers cannot set the
144
+ * `Authorization` header on the `WebSocket` constructor, so auth happens
145
+ * over the in-band handshake rather than the HTTP upgrade.
146
+ */
147
+ readonly isTokenAccepted?: (token: string | undefined) => Promise<boolean>;
148
+ /**
149
+ * Allow connections without validating a token: the `hubrpc::initialize`
150
+ * handshake still runs (and its token is captured), but any token is
151
+ * accepted. Use ONLY behind a trusted reverse proxy that performs auth
152
+ * itself, or on a private interface.
153
+ */
154
+ readonly allowAnonymous?: boolean;
155
+ /**
156
+ * Optional `Origin` allow-list for browser clients. When set, the upgrade
157
+ * is rejected if `Origin` is present and not in the list. Non-browser
158
+ * clients (which send no `Origin`) are unaffected.
159
+ */
160
+ readonly allowedOrigins?: readonly string[];
161
+ /**
162
+ * URL path the WebSocket endpoint is mounted at. Defaults to `/`. Any
163
+ * other path gets a `404`, so the same server can host health checks.
164
+ */
165
+ readonly path?: string;
166
+ /** Bytes. Frames larger than this close the connection. Defaults to 16 MiB. */
167
+ readonly maxPayload?: number;
168
+ /** Optional logger called on accept / reject / close. */
169
+ readonly onEvent?: (event: WebSocketServerEvent) => void;
170
+ /**
171
+ * Optional handler for ordinary (non-upgrade) HTTP requests on the same
172
+ * port. An Express app is a valid {@link http.RequestListener}, so this
173
+ * lets the WebSocket endpoint and e.g. a `/health` route share one port.
174
+ * Defaults to replying `426 upgrade required` to every request.
175
+ */
176
+ readonly requestListener?: http.RequestListener;
177
+ }
178
+ /**
179
+ * A hub-agnostic {@link ITransportServer} over WebSocket. It owns an
180
+ * `http.Server`, gates each upgrade by origin, runs the `hubrpc::initialize`
181
+ * handshake (authentication + protocol negotiation) over each accepted socket,
182
+ * and frames it as a {@link NodeWebSocketTransport}. Compose identity/claim
183
+ * policy on top via {@link HubConnectionAcceptor} — this server never couples
184
+ * to the hub.
185
+ *
186
+ * Sibling of {@link SocketServer} (named pipe / UDS) for reaching the hub from
187
+ * outside the host over `ws://` / `wss://`.
188
+ */
189
+ declare class WebSocketServer implements ITransportServer<NodeWebSocketTransport> {
190
+ private readonly _opts;
191
+ private readonly _httpServer;
192
+ private readonly _wss;
193
+ private readonly _path;
194
+ private readonly _attached;
195
+ private readonly _sockets;
196
+ private _handler;
197
+ private _disposed;
198
+ private constructor();
199
+ /** Bind + listen, resolving once the port is open. */
200
+ static start(options?: WebSocketServerOptions): Promise<WebSocketServer>;
201
+ /** The bound port (resolved even when started with port `0`). */
202
+ get port(): number;
203
+ setConnectionHandler(handler: (transport: NodeWebSocketTransport) => void): void;
204
+ dispose(): void;
205
+ private _onUpgrade;
206
+ private _onConnection;
207
+ /**
208
+ * Frame the upgraded socket, run the `hubrpc::initialize` handshake
209
+ * (authentication + protocol negotiation), then hand the transport to the
210
+ * connection handler. A failed handshake (bad/missing token, wrong first
211
+ * message, or timeout) drops the socket without reaching the handler.
212
+ */
213
+ private _acceptConnection;
214
+ private _reject;
215
+ }
216
+ //#endregion
217
+ export { NodeSocketTransport, NodeWebSocketTransport, SocketServer, type SocketServerOptions, WebSocketServer, type WebSocketServerEvent, type WebSocketServerOptions };
218
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ import { i as SocketServer, n as WebSocketServer, r as NodeSocketTransport, t as NodeWebSocketTransport } from "../../../chunks/node-CTXsQ6oa.js";
2
+ export { NodeSocketTransport, NodeWebSocketTransport, SocketServer, WebSocketServer };
@@ -0,0 +1,2 @@
1
+ import { v as tapTransport } from "../../chunks/nodeTransit-cmtZgdpW.js";
2
+ export { tapTransport };
@@ -0,0 +1,2 @@
1
+ import { a as tapTransport } from "../../chunks/nodeTransit-CWeFnbwt.js";
2
+ export { tapTransport };