@vibecook/truffle 0.7.0 → 0.7.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.
- package/dist/create-mesh-node.d.ts +46 -0
- package/dist/create-mesh-node.d.ts.map +1 -1
- package/dist/create-mesh-node.js +23 -2
- package/dist/create-mesh-node.js.map +1 -1
- package/dist/http.d.ts +50 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +100 -11
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/net.d.ts +45 -4
- package/dist/net.d.ts.map +1 -1
- package/dist/net.js +45 -8
- package/dist/net.js.map +1 -1
- package/dist/serve.d.ts +142 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +347 -0
- package/dist/serve.js.map +1 -0
- package/dist/ws.d.ts +8 -1
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js +14 -17
- package/dist/ws.js.map +1 -1
- package/package.json +7 -7
- package/sidecar-checksums.json +7 -0
|
@@ -4,6 +4,7 @@ import { type TruffleHttp } from './http.js';
|
|
|
4
4
|
import { type TruffleQuic } from './quic.js';
|
|
5
5
|
import { type TruffleDgram } from './dgram.js';
|
|
6
6
|
import { type TruffleWs } from './ws.js';
|
|
7
|
+
import { type TruffleServe } from './serve.js';
|
|
7
8
|
import { Peer, PeerRegistry, type PeerLike, type PeerRef } from './peer.js';
|
|
8
9
|
export type { PeerLike, PeerRef };
|
|
9
10
|
export { Peer };
|
|
@@ -18,6 +19,41 @@ export type MeshNode = Omit<NapiNode, 'getPeers' | 'peer' | 'send' | 'ping' | 'o
|
|
|
18
19
|
dgram: TruffleDgram;
|
|
19
20
|
ws: TruffleWs;
|
|
20
21
|
native: NapiNode;
|
|
22
|
+
/**
|
|
23
|
+
* Publish a local service or directory to the whole tailnet (RFC 023 §6.2).
|
|
24
|
+
* The declarative counterpart to `http.createServer`: use `serve` when the
|
|
25
|
+
* bytes are a directory or another process, `http.createServer` when you
|
|
26
|
+
* wrote the handler. TLS defaults on (the audience is browsers). Resolves
|
|
27
|
+
* with a {@link ServeHandle} (`{ id, url, port, config, close() }`, an
|
|
28
|
+
* `EventEmitter` for runtime errors).
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Expose a local dev server
|
|
32
|
+
* const h = await mesh.serve({ port: 443, target: 'http://localhost:3000' });
|
|
33
|
+
* console.log(h.url); // https://myapp.tail1234.ts.net
|
|
34
|
+
*
|
|
35
|
+
* // Static SPA
|
|
36
|
+
* await mesh.serve({ port: 443, dir: './public', fallback: '/index.html' });
|
|
37
|
+
*
|
|
38
|
+
* // Mixed routes (SPA + API)
|
|
39
|
+
* await mesh.serve({
|
|
40
|
+
* port: 443,
|
|
41
|
+
* routes: {
|
|
42
|
+
* '/api': 'http://localhost:8000',
|
|
43
|
+
* '/grafana': { target: 'http://localhost:3001' },
|
|
44
|
+
* '/': { dir: './public', fallback: '/index.html' },
|
|
45
|
+
* },
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
serve: TruffleServe;
|
|
50
|
+
/**
|
|
51
|
+
* The node's MagicDNS FQDN (`myapp.tail1234.ts.net`) — use it to build
|
|
52
|
+
* serving URLs (`https://${mesh.dnsName}/`). Null before the tailnet
|
|
53
|
+
* grants one (or after stop). Read this instead of string-building from
|
|
54
|
+
* the hostname: Tailscale dedupes collisions with `-1`/`-2` suffixes.
|
|
55
|
+
*/
|
|
56
|
+
readonly dnsName: string | null;
|
|
21
57
|
/** Interned Peer handles (`===` stable per peerRef). */
|
|
22
58
|
getPeers(): Promise<Peer[]>;
|
|
23
59
|
/**
|
|
@@ -78,6 +114,16 @@ export interface CreateMeshNodeOptions {
|
|
|
78
114
|
appId: string;
|
|
79
115
|
deviceName?: string;
|
|
80
116
|
deviceId?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Explicit Tailscale hostname (RFC 023 §6.4), bypassing the
|
|
119
|
+
* `truffle-{appId}-{slug}` convention for pretty serving URLs
|
|
120
|
+
* (`https://dashboard.{tailnet}.ts.net`). Single lowercase DNS label
|
|
121
|
+
* (1–63 chars of `[a-z0-9-]`, no dots). Tradeoff: hello-less peers with a
|
|
122
|
+
* custom hostname lose bare device-name resolution (full hostname / IP /
|
|
123
|
+
* deviceId / post-hello identity still resolve). Read the granted name
|
|
124
|
+
* from `mesh.dnsName` — Tailscale dedupes collisions with `-1`/`-2`.
|
|
125
|
+
*/
|
|
126
|
+
hostname?: string;
|
|
81
127
|
sidecarPath?: string;
|
|
82
128
|
stateDir?: string;
|
|
83
129
|
authKey?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-mesh-node.d.ts","sourceRoot":"","sources":["../src/create-mesh-node.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAGR,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"create-mesh-node.d.ts","sourceRoot":"","sources":["../src/create-mesh-node.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EAGR,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,0BA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,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmLtF"}
|
package/dist/create-mesh-node.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createHttpNamespace } from './http.js';
|
|
|
5
5
|
import { createQuicNamespace } from './quic.js';
|
|
6
6
|
import { createDgramNamespace } from './dgram.js';
|
|
7
7
|
import { createWsNamespace } from './ws.js';
|
|
8
|
+
import { createServeNamespace } from './serve.js';
|
|
8
9
|
import { resolveSidecarPath } from './sidecar.js';
|
|
9
10
|
import { Peer, PeerRegistry, peerLikeToQuery } from './peer.js';
|
|
10
11
|
export { Peer };
|
|
@@ -63,7 +64,7 @@ export function toMeshPeerEvent(reg, raw) {
|
|
|
63
64
|
* ```
|
|
64
65
|
*/
|
|
65
66
|
export async function createMeshNode(options) {
|
|
66
|
-
const { appId, deviceName, deviceId, autoAuth = true, openUrl: customOpenUrl, onAuthRequired, onPeerChange, sidecarPath, stateDir, authKey, ephemeral, wsPort, eagerIdentity, } = options;
|
|
67
|
+
const { appId, deviceName, deviceId, hostname, autoAuth = true, openUrl: customOpenUrl, onAuthRequired, onPeerChange, sidecarPath, stateDir, authKey, ephemeral, wsPort, eagerIdentity, } = options;
|
|
67
68
|
if (!/^[a-z][a-z0-9-]{1,31}$/.test(appId)) {
|
|
68
69
|
throw new Error(`[truffle] Invalid appId ${JSON.stringify(appId)}: must match ^[a-z][a-z0-9-]{1,31}$ ` +
|
|
69
70
|
`(2–32 chars; lowercase letters, digits, hyphens; must start with a letter).`);
|
|
@@ -80,6 +81,7 @@ export async function createMeshNode(options) {
|
|
|
80
81
|
appId,
|
|
81
82
|
deviceName,
|
|
82
83
|
deviceId,
|
|
84
|
+
hostname,
|
|
83
85
|
sidecarPath: resolvedSidecarPath,
|
|
84
86
|
stateDir,
|
|
85
87
|
authKey,
|
|
@@ -101,6 +103,19 @@ export async function createMeshNode(options) {
|
|
|
101
103
|
}
|
|
102
104
|
const registry = new PeerRegistry(node);
|
|
103
105
|
const mesh = node;
|
|
106
|
+
// Live accessor, not a snapshot: dnsName may be granted after start and
|
|
107
|
+
// goes away when the node stops (getLocalInfo throws → null).
|
|
108
|
+
Object.defineProperty(mesh, 'dnsName', {
|
|
109
|
+
configurable: true,
|
|
110
|
+
get: () => {
|
|
111
|
+
try {
|
|
112
|
+
return node.getLocalInfo().dnsName ?? null;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
});
|
|
104
119
|
// `mesh` IS the native node object, so each wrapper assignment shadows the
|
|
105
120
|
// NAPI prototype method — the native method must be bound BEFORE the
|
|
106
121
|
// assignment or the wrapper calls itself (infinite recursion).
|
|
@@ -181,11 +196,17 @@ export async function createMeshNode(options) {
|
|
|
181
196
|
if (onPeerChange) {
|
|
182
197
|
mesh.onPeerChange(onPeerChange);
|
|
183
198
|
}
|
|
184
|
-
mesh.net = createNetNamespace(node
|
|
199
|
+
mesh.net = createNetNamespace(node, {
|
|
200
|
+
// Live registry lookup behind TruffleSocket.remotePeer (RFC 023 §6.1).
|
|
201
|
+
resolvePeer: (tailscaleId) => registry.getByTailscaleId(tailscaleId) ?? null,
|
|
202
|
+
});
|
|
185
203
|
mesh.http = createHttpNamespace(mesh.net);
|
|
186
204
|
mesh.quic = createQuicNamespace(node);
|
|
187
205
|
mesh.dgram = createDgramNamespace(node);
|
|
188
206
|
mesh.ws = createWsNamespace(mesh.net);
|
|
207
|
+
// `serve` is a new property (NapiNode has no such method), so no shadowing
|
|
208
|
+
// rule applies. A fresh NapiProxy per call — its handles are per-call.
|
|
209
|
+
mesh.serve = createServeNamespace(() => node.proxy());
|
|
189
210
|
mesh.native = node;
|
|
190
211
|
return mesh;
|
|
191
212
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-mesh-node.js","sourceRoot":"","sources":["../src/create-mesh-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAA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CHANGED
|
@@ -24,6 +24,43 @@ export declare class MeshAgent extends http.Agent {
|
|
|
24
24
|
*/
|
|
25
25
|
createConnection(options: http.ClientRequestArgs, callback?: (err: Error | null, stream: Duplex) => void): Duplex;
|
|
26
26
|
}
|
|
27
|
+
/** Options for {@link TruffleHttp.createServer} (RFC 023 §6.1). */
|
|
28
|
+
export interface MeshHttpServerOptions extends http.ServerOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Terminate TLS in the sidecar with automatic MagicDNS certificates.
|
|
31
|
+
* Requires MagicDNS + HTTPS certificates enabled on the tailnet; the
|
|
32
|
+
* first handshake per name does ACME issuance (the mesh pre-warms it at
|
|
33
|
+
* listen time). Inbound sockets carry `encrypted: true`, so Express-style
|
|
34
|
+
* `req.secure` / `req.protocol === 'https'` are correct. Default false:
|
|
35
|
+
* WireGuard already encrypts peer-to-peer traffic — TLS is for browser
|
|
36
|
+
* consumers (padlock, secure-context APIs, wss:).
|
|
37
|
+
*/
|
|
38
|
+
tls?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A real `node:http.Server` whose `listen()`/`close()`/`address()` drive a
|
|
42
|
+
* mesh listener instead of a host socket. `instanceof http.Server` holds, so
|
|
43
|
+
* Express, Koa, socket.io and `ws` attach unmodified; `req.socket` is a
|
|
44
|
+
* {@link TruffleSocket} (with `remotePeer`/`remotePeerId` identity).
|
|
45
|
+
*/
|
|
46
|
+
export type MeshHttpServer = http.Server & {
|
|
47
|
+
/** Bound mesh port; set once `'listening'` fires (resolved when 0 was requested). */
|
|
48
|
+
port?: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Build a mesh-listening `http.Server` (the shared engine behind
|
|
52
|
+
* `mesh.http.createServer` and `mesh.ws.createServer`).
|
|
53
|
+
*
|
|
54
|
+
* Contract differences from a host-bound server, all inherent to the mesh:
|
|
55
|
+
* `listen()` accepts only a port (no host/backlog/ipc path — the mesh has
|
|
56
|
+
* exactly one address); idle keep-alive sockets are not reaped on a timer
|
|
57
|
+
* (see TruffleSocket.setTimeout) — `close()` sweeps them via
|
|
58
|
+
* `closeIdleConnections()`, and `closeAllConnections()` works because the
|
|
59
|
+
* server tracks every socket fed to it; `'close'` fires when the mesh
|
|
60
|
+
* listener is released (in-flight responses run to completion, as with
|
|
61
|
+
* `closeIdleConnections` semantics).
|
|
62
|
+
*/
|
|
63
|
+
export declare function createMeshHttpServer(net: TruffleNet, options?: MeshHttpServerOptions, requestListener?: http.RequestListener): MeshHttpServer;
|
|
27
64
|
/** node:http-shaped namespace bound to a mesh node's `net` namespace. */
|
|
28
65
|
export interface TruffleHttp {
|
|
29
66
|
/**
|
|
@@ -52,6 +89,19 @@ export interface TruffleHttp {
|
|
|
52
89
|
headers: http.IncomingHttpHeaders;
|
|
53
90
|
body: string;
|
|
54
91
|
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Drop-in `http.createServer` that serves to the tailnet (RFC 023 §6.1):
|
|
94
|
+
* a real `http.Server` whose `listen(port)` binds a mesh listener, so any
|
|
95
|
+
* Tailscale device — browsers included — can reach it, and `req.socket`
|
|
96
|
+
* carries WhoIs identity (`remotePeer`, `remotePeerId`, `remotePeerName`).
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* const server = mesh.http.createServer({ tls: true }, app); // app = Express
|
|
100
|
+
* server.listen(443, () => console.log(`https://${mesh.dnsName}/`));
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
createServer(requestListener?: http.RequestListener): MeshHttpServer;
|
|
104
|
+
createServer(options: MeshHttpServerOptions, requestListener?: http.RequestListener): MeshHttpServer;
|
|
55
105
|
}
|
|
56
106
|
export declare function createHttpNamespace(net: TruffleNet): TruffleHttp;
|
|
57
107
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAmB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AE,UAAU,GAAG,WAAW,CAkGhE"}
|
package/dist/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// node:http interop for the mesh (RFC 021 Phase 2).
|
|
1
|
+
// node:http interop for the mesh (RFC 021 Phase 2; server half RFC 023 §6.1).
|
|
2
2
|
//
|
|
3
3
|
// `mesh.http` lets existing node:http / Express code talk to peers over the
|
|
4
4
|
// mesh with a one-line change. Two directions:
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
// • Outbound: point a request at a peer through a MeshAgent
|
|
7
7
|
// mesh.http.get('http://100.64.0.7:8080/api/status', (res) => …)
|
|
8
8
|
// await mesh.http.fetchText('kitchen-pi', 8080, '/api/status')
|
|
9
|
-
// • Inbound:
|
|
10
|
-
// const
|
|
11
|
-
//
|
|
12
|
-
// .createServer((socket) => httpServer.emit('connection', socket))
|
|
13
|
-
// .listen(8080);
|
|
9
|
+
// • Inbound: a drop-in http.createServer whose listen() binds the mesh
|
|
10
|
+
// const server = mesh.http.createServer(app); // e.g. Express
|
|
11
|
+
// server.listen(8080);
|
|
14
12
|
//
|
|
15
|
-
// Nothing here is mesh-specific beyond
|
|
16
|
-
// createConnection` is documented to accept any `stream.Duplex
|
|
17
|
-
//
|
|
18
|
-
//
|
|
13
|
+
// Nothing here is mesh-specific beyond two seams: `http.Agent#
|
|
14
|
+
// createConnection` is documented to accept any `stream.Duplex` (outbound),
|
|
15
|
+
// and an `http.Server` parses any duplex fed to it as a `'connection'` event
|
|
16
|
+
// (inbound) — TruffleSocket (see ./net.ts) is one, so node:http drives it
|
|
17
|
+
// exactly like a real net.Socket. The compat shims that make that true live
|
|
18
|
+
// in ./net.ts.
|
|
19
19
|
import http from 'node:http';
|
|
20
20
|
/**
|
|
21
21
|
* An `http.Agent` that dials its connections over the mesh instead of the
|
|
@@ -71,6 +71,90 @@ function portOf(options) {
|
|
|
71
71
|
const port = typeof options.port === 'string' ? Number(options.port) : options.port;
|
|
72
72
|
return port && Number.isFinite(port) ? port : 80;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a mesh-listening `http.Server` (the shared engine behind
|
|
76
|
+
* `mesh.http.createServer` and `mesh.ws.createServer`).
|
|
77
|
+
*
|
|
78
|
+
* Contract differences from a host-bound server, all inherent to the mesh:
|
|
79
|
+
* `listen()` accepts only a port (no host/backlog/ipc path — the mesh has
|
|
80
|
+
* exactly one address); idle keep-alive sockets are not reaped on a timer
|
|
81
|
+
* (see TruffleSocket.setTimeout) — `close()` sweeps them via
|
|
82
|
+
* `closeIdleConnections()`, and `closeAllConnections()` works because the
|
|
83
|
+
* server tracks every socket fed to it; `'close'` fires when the mesh
|
|
84
|
+
* listener is released (in-flight responses run to completion, as with
|
|
85
|
+
* `closeIdleConnections` semantics).
|
|
86
|
+
*/
|
|
87
|
+
export function createMeshHttpServer(net, options = {}, requestListener) {
|
|
88
|
+
const { tls, ...serverOptions } = options;
|
|
89
|
+
const server = (requestListener
|
|
90
|
+
? http.createServer(serverOptions, requestListener)
|
|
91
|
+
: http.createServer(serverOptions));
|
|
92
|
+
const onConnection = (socket) => server.emit('connection', socket);
|
|
93
|
+
// Plain single-arg form when tls is off, so the namespace stays usable
|
|
94
|
+
// against pre-RFC-023 net implementations (and their test mocks).
|
|
95
|
+
const meshServer = tls ? net.createServer({ tls }, onConnection) : net.createServer(onConnection);
|
|
96
|
+
meshServer.on('error', (err) => server.emit('error', err));
|
|
97
|
+
let meshListening = false;
|
|
98
|
+
meshServer.on('listening', () => {
|
|
99
|
+
meshListening = true;
|
|
100
|
+
server.port = meshServer.port;
|
|
101
|
+
server.emit('listening');
|
|
102
|
+
});
|
|
103
|
+
meshServer.on('close', () => {
|
|
104
|
+
meshListening = false;
|
|
105
|
+
});
|
|
106
|
+
// net.Server#listening is a prototype getter over the libuv handle; give
|
|
107
|
+
// this instance one that reflects the mesh listener instead.
|
|
108
|
+
Object.defineProperty(server, 'listening', {
|
|
109
|
+
configurable: true,
|
|
110
|
+
get: () => meshListening,
|
|
111
|
+
});
|
|
112
|
+
// Mesh listeners have no local IP/family — address() is `{ port } | null`
|
|
113
|
+
// (same contract as TruffleServer.address), narrower than AddressInfo.
|
|
114
|
+
server.address = (() => meshServer.address());
|
|
115
|
+
server.listen = ((...args) => {
|
|
116
|
+
let port;
|
|
117
|
+
let cb;
|
|
118
|
+
for (const arg of args) {
|
|
119
|
+
if (typeof arg === 'function')
|
|
120
|
+
cb = arg;
|
|
121
|
+
else if (typeof arg === 'number' || typeof arg === 'string')
|
|
122
|
+
port = Number(arg);
|
|
123
|
+
else if (arg && typeof arg === 'object') {
|
|
124
|
+
const p = arg.port;
|
|
125
|
+
if (p !== undefined)
|
|
126
|
+
port = Number(p);
|
|
127
|
+
const host = arg.host;
|
|
128
|
+
if (host !== undefined) {
|
|
129
|
+
throw new TypeError('mesh http server: listen() takes no host — the mesh has exactly one address (see mesh.dnsName)');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
port ??= 0;
|
|
134
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
135
|
+
throw new TypeError(`mesh http server: invalid port ${String(port)}`);
|
|
136
|
+
}
|
|
137
|
+
if (cb)
|
|
138
|
+
server.once('listening', cb);
|
|
139
|
+
meshServer.listen(port);
|
|
140
|
+
return server;
|
|
141
|
+
});
|
|
142
|
+
let closeEmitted = false;
|
|
143
|
+
server.close = ((callback) => {
|
|
144
|
+
// Reap idle keep-alive sockets (no timer does it on the mesh); in-flight
|
|
145
|
+
// responses finish naturally — closeAllConnections() is the hard stop.
|
|
146
|
+
server.closeIdleConnections();
|
|
147
|
+
meshServer.close(() => {
|
|
148
|
+
if (!closeEmitted) {
|
|
149
|
+
closeEmitted = true;
|
|
150
|
+
server.emit('close');
|
|
151
|
+
}
|
|
152
|
+
callback?.();
|
|
153
|
+
});
|
|
154
|
+
return server;
|
|
155
|
+
});
|
|
156
|
+
return server;
|
|
157
|
+
}
|
|
74
158
|
export function createHttpNamespace(net) {
|
|
75
159
|
const agent = new MeshAgent(net);
|
|
76
160
|
// Inject the mesh agent unless the caller supplied their own (or `false`).
|
|
@@ -111,6 +195,11 @@ export function createHttpNamespace(net) {
|
|
|
111
195
|
req.end();
|
|
112
196
|
});
|
|
113
197
|
}
|
|
114
|
-
|
|
198
|
+
function createServer(arg1, arg2) {
|
|
199
|
+
const options = typeof arg1 === 'object' && arg1 !== null ? arg1 : {};
|
|
200
|
+
const listener = typeof arg1 === 'function' ? arg1 : arg2;
|
|
201
|
+
return createMeshHttpServer(net, options, listener);
|
|
202
|
+
}
|
|
203
|
+
return { agent, Agent: MeshAgent, request, get, fetchText, createServer };
|
|
115
204
|
}
|
|
116
205
|
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,EAAE;AACF,4EAA4E;AAC5E,+CAA+C;AAC/C,EAAE;AACF,8DAA8D;AAC9D,uEAAuE;AACvE,qEAAqE;AACrE,yEAAyE;AACzE,0EAA0E;AAC1E,6BAA6B;AAC7B,EAAE;AACF,+DAA+D;AAC/D,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,4EAA4E;AAC5E,eAAe;AAEf,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAU,SAAQ,IAAI,CAAC,KAAK;IAC9B,IAAI,CAAa;IAE1B,YAAY,GAAe,EAAE,IAAwB;QACnD,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACM,gBAAgB,CACvB,OAA+B,EAC/B,QAAsD;QAEtD,MAAM,MAAM,GAAG,I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,OAAO,EAAE,MAAM,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACxB,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;IAOD,SAAS,YAAY,CACnB,IAAmD,EACnD,IAA2B;QAE3B,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,MAAM,QAAQ,GAAG,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1D,OAAO,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;AAC5E,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { NapiNode, NapiFileTransfer, NapiOfferResponder, NapiSyncedStore, NapiProxy, NapiTcpSocket, NapiTcpListener, NapiUdpSocket, NapiQuicConnection, NapiQuicListener, NapiQuicStream, } from '@vibecook/truffle-native';
|
|
2
2
|
export type { NapiNodeConfig, NapiNodeIdentity, NapiPeer, NapiPingResult, NapiHealthInfo, NapiPeerEvent, NapiNamespacedMessage, NapiFileOffer, NapiTransferResult, NapiTransferProgress, NapiFileTransferEvent, NapiSlice, NapiStoreEvent, NapiProxyConfig, NapiProxyInfo, NapiProxyEvent, NapiDatagram, } from '@vibecook/truffle-native';
|
|
3
3
|
export { resolveSidecarPath } from './sidecar.js';
|
|
4
|
-
export { TruffleSocket, TruffleServer, createNetNamespace, type TruffleNet, type NetConnectOptions, type ConnectionListener, } from './net.js';
|
|
5
|
-
export { MeshAgent, createHttpNamespace, type TruffleHttp } from './http.js';
|
|
4
|
+
export { TruffleSocket, TruffleServer, createNetNamespace, type TruffleNet, type NetConnectOptions, type NetServerOptions, type NetHooks, type ConnectionListener, } from './net.js';
|
|
5
|
+
export { MeshAgent, createHttpNamespace, createMeshHttpServer, type TruffleHttp, type MeshHttpServer, type MeshHttpServerOptions, } from './http.js';
|
|
6
6
|
export { TruffleQuicStream, TruffleQuicConnection, TruffleQuicServer, createQuicNamespace, type TruffleQuic, } from './quic.js';
|
|
7
7
|
export { TruffleDgramSocket, createDgramNamespace, type TruffleDgram, type TruffleRemoteInfo, } from './dgram.js';
|
|
8
8
|
export { createWsNamespace, type TruffleWs, type TruffleWsServer, type TruffleWsServerOptions, type WsLoader, } from './ws.js';
|
|
9
|
+
export { ServeHandle, createServeNamespace, normalizeServeConfig, type TruffleServe, type ServeConfig, type ServeOptions, type ServeTargetConfig, type ServeStaticConfig, type ServeRoutesConfig, type ServeRouteValue, type ServeErrorInfo, } from './serve.js';
|
|
9
10
|
export { createMeshNode, type CreateMeshNodeOptions, type MeshNode, type MeshPeerEvent, type MeshNamespacedMessage, } from './create-mesh-node.js';
|
|
10
11
|
export { Peer, PeerRegistry, isPeer, peerLikeToQuery, type PeerLike, type PeerRef, type PeerSnapshot, } from './peer.js';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,cAAc,EACd,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC;AAGlB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAGlC,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,EACT,cAAc,EACd,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,GACb,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,WAAW,GACjB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,GACvB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,iBAAiB,EACjB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,QAAQ,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,14 +4,16 @@ export { NapiNode, NapiFileTransfer, NapiOfferResponder, NapiSyncedStore, NapiPr
|
|
|
4
4
|
export { resolveSidecarPath } from './sidecar.js';
|
|
5
5
|
// node:net-shaped raw TCP API over the mesh (RFC 021)
|
|
6
6
|
export { TruffleSocket, TruffleServer, createNetNamespace, } from './net.js';
|
|
7
|
-
// node:http interop over the mesh (RFC 021)
|
|
8
|
-
export { MeshAgent, createHttpNamespace } from './http.js';
|
|
7
|
+
// node:http interop over the mesh (RFC 021; server half RFC 023)
|
|
8
|
+
export { MeshAgent, createHttpNamespace, createMeshHttpServer, } from './http.js';
|
|
9
9
|
// QUIC over the mesh (RFC 021)
|
|
10
10
|
export { TruffleQuicStream, TruffleQuicConnection, TruffleQuicServer, createQuicNamespace, } from './quic.js';
|
|
11
11
|
// node:dgram-shaped raw UDP API over the mesh (RFC 021)
|
|
12
12
|
export { TruffleDgramSocket, createDgramNamespace, } from './dgram.js';
|
|
13
13
|
// WebSocket over the mesh via the `ws` package (RFC 021)
|
|
14
14
|
export { createWsNamespace, } from './ws.js';
|
|
15
|
+
// Declarative HTTP serving over the tailnet (RFC 023 §6.2)
|
|
16
|
+
export { ServeHandle, createServeNamespace, normalizeServeConfig, } from './serve.js';
|
|
15
17
|
// High-level API
|
|
16
18
|
export { createMeshNode, } from './create-mesh-node.js';
|
|
17
19
|
// RFC 022 Peer handles
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAuBlC,4BAA4B;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,sDAAsD;AACtD,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAuBlC,4BAA4B;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,sDAAsD;AACtD,OAAO,EACL,aAAa,EACb,aAAa,EACb,kBAAkB,GAMnB,MAAM,UAAU,CAAC;AAElB,iEAAiE;AACjE,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,GAIrB,MAAM,WAAW,CAAC;AAEnB,+BAA+B;AAC/B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM,WAAW,CAAC;AAEnB,wDAAwD;AACxD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GAGrB,MAAM,YAAY,CAAC;AAEpB,yDAAyD;AACzD,OAAO,EACL,iBAAiB,GAKlB,MAAM,SAAS,CAAC;AAEjB,2DAA2D;AAC3D,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,oBAAoB,GASrB,MAAM,YAAY,CAAC;AAEpB,iBAAiB;AACjB,OAAO,EACL,cAAc,GAKf,MAAM,uBAAuB,CAAC;AAE/B,uBAAuB;AACvB,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,eAAe,GAIhB,MAAM,WAAW,CAAC"}
|
package/dist/net.d.ts
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
import { Duplex } from 'node:stream';
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
3
|
import type { NapiNode, NapiTcpSocket } from '@vibecook/truffle-native';
|
|
4
|
-
import { type PeerLike } from './peer.js';
|
|
4
|
+
import { type Peer, type PeerLike } from './peer.js';
|
|
5
|
+
/**
|
|
6
|
+
* Hooks threaded from `createMeshNode` into the namespaces (RFC 023 §6.1).
|
|
7
|
+
* Namespaces stay constructible without them (tests, low-level use); the
|
|
8
|
+
* Peer-handle surfaces just return null then.
|
|
9
|
+
*/
|
|
10
|
+
export interface NetHooks {
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a Tailscale node id to the interned RFC 022 `Peer` handle.
|
|
13
|
+
* Wired to the mesh node's peer registry by `createMeshNode`.
|
|
14
|
+
*/
|
|
15
|
+
resolvePeer?: (tailscaleId: string) => Peer | null;
|
|
16
|
+
}
|
|
17
|
+
/** Options for {@link TruffleNet.createServer}. */
|
|
18
|
+
export interface NetServerOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Terminate TLS in the sidecar with automatic MagicDNS certificates
|
|
21
|
+
* (RFC 023 §6.1). Requires MagicDNS + HTTPS enabled on the tailnet.
|
|
22
|
+
* Inbound sockets carry `encrypted: true` so http frameworks report
|
|
23
|
+
* `req.secure` correctly. Default false — WireGuard already encrypts
|
|
24
|
+
* peer-to-peer traffic; TLS is for browser consumers.
|
|
25
|
+
*/
|
|
26
|
+
tls?: boolean;
|
|
27
|
+
}
|
|
5
28
|
export interface NetConnectOptions {
|
|
6
29
|
/**
|
|
7
30
|
* Peer to connect to: {@link PeerLike} handle, or a query string
|
|
@@ -33,7 +56,13 @@ export declare class TruffleSocket extends Duplex {
|
|
|
33
56
|
remotePeerId?: string;
|
|
34
57
|
/** Human-readable peer name from the WhoIs identity (inbound sockets). */
|
|
35
58
|
remotePeerName?: string;
|
|
36
|
-
|
|
59
|
+
/**
|
|
60
|
+
* True on sockets accepted by a `tls: true` mesh listener (TLS terminated
|
|
61
|
+
* in the sidecar). This is the undocumented-but-universal property http
|
|
62
|
+
* frameworks sniff for `req.secure` / `req.protocol === 'https'`.
|
|
63
|
+
*/
|
|
64
|
+
encrypted?: boolean;
|
|
65
|
+
constructor(native: NapiTcpSocket | Promise<NapiTcpSocket>, hooks?: NetHooks);
|
|
37
66
|
_read(size: number): void;
|
|
38
67
|
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
39
68
|
_final(callback: (error?: Error | null) => void): void;
|
|
@@ -68,6 +97,15 @@ export declare class TruffleSocket extends Duplex {
|
|
|
68
97
|
family?: string;
|
|
69
98
|
port?: number;
|
|
70
99
|
};
|
|
100
|
+
/**
|
|
101
|
+
* The interned RFC 022 `Peer` handle for the remote end, resolved live from
|
|
102
|
+
* the mesh node's registry by this socket's `remotePeerId`. Null when the
|
|
103
|
+
* id is not yet known (dial in flight), the peer isn't interned, or the
|
|
104
|
+
* namespace was built without registry hooks (outside `createMeshNode`).
|
|
105
|
+
* Inbound sockets have it from accept time — use it for gating:
|
|
106
|
+
* `req.socket.remotePeer?.displayName`.
|
|
107
|
+
*/
|
|
108
|
+
get remotePeer(): Peer | null;
|
|
71
109
|
}
|
|
72
110
|
/**
|
|
73
111
|
* A TCP server on the mesh, mimicking `net.Server`.
|
|
@@ -86,7 +124,9 @@ export declare class TruffleServer extends EventEmitter {
|
|
|
86
124
|
#private;
|
|
87
125
|
/** Bound port; set once `'listening'` fires (resolved when 0 was requested). */
|
|
88
126
|
port?: number;
|
|
89
|
-
constructor(node: NapiNode, connectionListener?: ConnectionListener
|
|
127
|
+
constructor(node: NapiNode, connectionListener?: ConnectionListener, options?: NetServerOptions & {
|
|
128
|
+
hooks?: NetHooks;
|
|
129
|
+
});
|
|
90
130
|
/**
|
|
91
131
|
* Start listening on `port` (0 = ephemeral; read `server.port` after
|
|
92
132
|
* `'listening'`). Returns `this`, like `net.Server#listen`.
|
|
@@ -113,6 +153,7 @@ export interface TruffleNet {
|
|
|
113
153
|
createConnection(port: number, host: PeerLike): TruffleSocket;
|
|
114
154
|
/** Create a server; call `.listen(port)` to bind, like `net.createServer`. */
|
|
115
155
|
createServer(connectionListener?: ConnectionListener): TruffleServer;
|
|
156
|
+
createServer(options: NetServerOptions, connectionListener?: ConnectionListener): TruffleServer;
|
|
116
157
|
}
|
|
117
|
-
export declare function createNetNamespace(node: NapiNode): TruffleNet;
|
|
158
|
+
export declare function createNetNamespace(node: NapiNode, hooks?: NetHooks): TruffleNet;
|
|
118
159
|
//# sourceMappingURL=net.d.ts.map
|
package/dist/net.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY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