@meshline/transport-node 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Meshline contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Node.js relay transport
2
+
3
+ Cookie-free HTTPS and WebSocket adapters for Meshline on **Node.js 24 or later**.
4
+ This ESM package includes TypeScript declarations.
5
+
6
+ ## Install and configure
7
+
8
+ Install this adapter and the matching core together:
9
+
10
+ ```sh
11
+ npm install @meshline/sdk@0.1.0-alpha.1 @meshline/transport-node@0.1.0-alpha.1
12
+ ```
13
+
14
+ ```ts
15
+ import { createNodeRelayFetch, createNodeSocketFactory } from '@meshline/transport-node';
16
+
17
+ const transport = {
18
+ fetch: createNodeRelayFetch(),
19
+ socketFactory: createNodeSocketFactory(),
20
+ };
21
+ ```
22
+
23
+ Spread these transport fields into `RelayClientPool` options alongside the
24
+ network context and account ID. Pass the application registry as the pool's
25
+ second argument. See the
26
+ [Node session example](https://github.com/meshline-network/sdk/blob/main/typescript/examples/node.ts)
27
+ for SQLite integration and resource ownership.
28
+
29
+ ## Transport behavior
30
+
31
+ The adapters disable redirects, cookies, and implicit retries. HTTPS and WSS
32
+ retain normal TLS certificate and hostname verification. The optional `ca`
33
+ configuration trusts an explicit private network root only for this transport;
34
+ it does not change process-wide trust settings.
35
+
36
+ The WebSocket adapter uses `ws`, enforces the protocol's 1 MiB frame limit,
37
+ rejects invalid UTF-8, and can send RFC 1003/1009 rejection close codes.
38
+ Managers handle durable retries separately from the transport.
39
+
40
+ [Transport guide](https://github.com/meshline-network/sdk/blob/main/typescript/docs/guides/transport.md)
41
+ · [Platform requirements](https://github.com/meshline-network/sdk/blob/main/typescript/docs/platforms.md)
@@ -0,0 +1,10 @@
1
+ import { type RelayFetch, type RelaySocketFactory } from '@meshline/sdk';
2
+ /** Optional explicit trust roots, e.g. a private network CA. TLS verification remains enabled. */
3
+ export interface NodeTransportOptions {
4
+ readonly ca?: string | Uint8Array;
5
+ }
6
+ /** Cookie-free HTTPS with no redirects, caching, implicit retries or global TLS changes. */
7
+ export declare function createNodeRelayFetch(options?: NodeTransportOptions): RelayFetch;
8
+ /** Full RFC close codes and bounded frames; no cookies, redirects or compression negotiation. */
9
+ export declare function createNodeSocketFactory(options?: NodeTransportOptions): RelaySocketFactory;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsC,KAAK,UAAU,EAAmD,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE9J,kGAAkG;AAClG,MAAM,WAAW,oBAAoB;IAAG,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE;AAE3E,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,oBAAyB,GAAG,UAAU,CAsBnF;AAED,iGAAiG;AACjG,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,oBAAyB,GAAG,kBAAkB,CAyB9F"}
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ import { request } from 'node:https';
2
+ import WebSocket from 'ws';
3
+ import { maxSocketMessageBytes, webEndpoint } from '@meshline/sdk';
4
+ /** Cookie-free HTTPS with no redirects, caching, implicit retries or global TLS changes. */
5
+ export function createNodeRelayFetch(options = {}) {
6
+ const ca = typeof options.ca === 'string' || options.ca === undefined ? options.ca : Buffer.from(options.ca);
7
+ return (url, init) => new Promise((resolve, reject) => {
8
+ const endpoint = new URL(url);
9
+ if (endpoint.protocol !== 'https:' || endpoint.username || endpoint.password)
10
+ throw new TypeError('Expected a credential-free HTTPS request URL.');
11
+ const outgoing = request(endpoint, { method: init.method, headers: init.headers, signal: init.signal, ...(ca === undefined ? {} : { ca }) }, response => {
12
+ const headers = new Headers();
13
+ for (let index = 0; index < response.rawHeaders.length; index += 2)
14
+ headers.append(response.rawHeaders[index], response.rawHeaders[index + 1]);
15
+ resolve({
16
+ status: response.statusCode, headers,
17
+ body: { async cancel() { response.destroy(); } },
18
+ async arrayBuffer() {
19
+ const chunks = [];
20
+ for await (const chunk of response)
21
+ chunks.push(chunk);
22
+ const buffer = Buffer.concat(chunks);
23
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
24
+ },
25
+ });
26
+ });
27
+ outgoing.on('error', reject);
28
+ outgoing.end(init.body);
29
+ });
30
+ }
31
+ /** Full RFC close codes and bounded frames; no cookies, redirects or compression negotiation. */
32
+ export function createNodeSocketFactory(options = {}) {
33
+ const ca = typeof options.ca === 'string' || options.ca === undefined ? options.ca : Buffer.from(options.ca);
34
+ return endpoint => {
35
+ webEndpoint(endpoint, 'wss:');
36
+ // ws 8.22 supports closeTimeout; @types/ws 8.18 does not yet declare it.
37
+ const socketOptions = { followRedirects: false, perMessageDeflate: false,
38
+ maxPayload: maxSocketMessageBytes, handshakeTimeout: 60000, closeTimeout: 3000, ...(ca === undefined ? {} : { ca }) };
39
+ const socket = new WebSocket(endpoint, socketOptions);
40
+ return {
41
+ get readyState() { return socket.readyState; },
42
+ get bufferedAmount() { return socket.bufferedAmount; },
43
+ send(text) { socket.send(text); },
44
+ close(code, reason) { socket.close(code, reason); return code; },
45
+ on(event, listener) {
46
+ const handler = (...args) => {
47
+ const value = event === 'open' ? undefined : event === 'error' ? args[0]
48
+ : event === 'close' ? { code: args[0], reason: String(args[1]) }
49
+ : args[1] ? args[0] : String(args[0]);
50
+ listener(value);
51
+ };
52
+ socket.on(event, handler);
53
+ return () => { socket.off(event, handler); };
54
+ },
55
+ };
56
+ };
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAA6F,MAAM,eAAe,CAAC;AAK9J,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAAC,OAAO,GAAyB,EAAE;IACnE,MAAM,EAAE,GAAG,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7G,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,OAAO,CAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;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M,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;YAChE,EAAE,CAAC,KAAK,EAAE,QAAQ;gBACd,MAAM,OAAO,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;oBACzC,MAAM,KAAK,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;wBACpE,CAAC,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;4BAC5D,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC9C,QAAQ,CAAC,KAAwC,CAAC,CAAC;gBACvD,CAAC,CAAC;gBACF,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;gBAC1B,OAAO,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACjD,CAAC;SACJ,CAAC;IACN,CAAC,CAAC;AACN,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@meshline/transport-node",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Node.js HTTPS and WebSocket adapters for Meshline",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "engines": {
9
+ "node": ">=24.0.0"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "src",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "peerDependencies": {
24
+ "@meshline/sdk": "0.1.0-alpha.1"
25
+ },
26
+ "dependencies": {
27
+ "ws": "8.22.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/ws": "8.18.1"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/meshline-network/sdk.git",
35
+ "directory": "typescript/packages/transport-node"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "registry": "https://registry.npmjs.org"
40
+ }
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { request } from 'node:https';
2
+ import WebSocket from 'ws';
3
+ import { maxSocketMessageBytes, webEndpoint, type RelayFetch, type RelayFetchResponse, type RelaySocketEvents, type RelaySocketFactory } from '@meshline/sdk';
4
+
5
+ /** Optional explicit trust roots, e.g. a private network CA. TLS verification remains enabled. */
6
+ export interface NodeTransportOptions { readonly ca?: string | Uint8Array }
7
+
8
+ /** Cookie-free HTTPS with no redirects, caching, implicit retries or global TLS changes. */
9
+ export function createNodeRelayFetch(options: NodeTransportOptions = {}): RelayFetch {
10
+ const ca = typeof options.ca === 'string' || options.ca === undefined ? options.ca : Buffer.from(options.ca);
11
+ return (url, init) => new Promise<RelayFetchResponse>((resolve, reject) => {
12
+ const endpoint = new URL(url);
13
+ if (endpoint.protocol !== 'https:' || endpoint.username || endpoint.password) throw new TypeError('Expected a credential-free HTTPS request URL.');
14
+ const outgoing = request(endpoint, { method: init.method, headers: init.headers, signal: init.signal, ...(ca === undefined ? {} : { ca }) }, response => {
15
+ const headers = new Headers();
16
+ for (let index = 0; index < response.rawHeaders.length; index += 2) headers.append(response.rawHeaders[index]!, response.rawHeaders[index + 1]!);
17
+ resolve({
18
+ status: response.statusCode!, headers,
19
+ body: { async cancel() { response.destroy(); } },
20
+ async arrayBuffer() {
21
+ const chunks: Uint8Array[] = [];
22
+ for await (const chunk of response) chunks.push(chunk as Uint8Array);
23
+ const buffer = Buffer.concat(chunks);
24
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength) as ArrayBuffer;
25
+ },
26
+ });
27
+ });
28
+ outgoing.on('error', reject);
29
+ outgoing.end(init.body);
30
+ });
31
+ }
32
+
33
+ /** Full RFC close codes and bounded frames; no cookies, redirects or compression negotiation. */
34
+ export function createNodeSocketFactory(options: NodeTransportOptions = {}): RelaySocketFactory {
35
+ const ca = typeof options.ca === 'string' || options.ca === undefined ? options.ca : Buffer.from(options.ca);
36
+ return endpoint => {
37
+ webEndpoint(endpoint, 'wss:');
38
+ // ws 8.22 supports closeTimeout; @types/ws 8.18 does not yet declare it.
39
+ const socketOptions: WebSocket.ClientOptions & { closeTimeout: number } = { followRedirects: false, perMessageDeflate: false,
40
+ maxPayload: maxSocketMessageBytes, handshakeTimeout: 60000, closeTimeout: 3000, ...(ca === undefined ? {} : { ca }) };
41
+ const socket = new WebSocket(endpoint, socketOptions);
42
+ return {
43
+ get readyState() { return socket.readyState; },
44
+ get bufferedAmount() { return socket.bufferedAmount; },
45
+ send(text) { socket.send(text); },
46
+ close(code, reason) { socket.close(code, reason); return code; },
47
+ on(event, listener) {
48
+ const handler = (...args: unknown[]): void => {
49
+ const value = event === 'open' ? undefined : event === 'error' ? args[0]
50
+ : event === 'close' ? { code: args[0], reason: String(args[1]) }
51
+ : args[1] ? args[0] : String(args[0]);
52
+ listener(value as RelaySocketEvents[typeof event]);
53
+ };
54
+ socket.on(event, handler);
55
+ return () => { socket.off(event, handler); };
56
+ },
57
+ };
58
+ };
59
+ }