@angadie/chittie-transport-node 0.1.0

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,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Asyncdot Engineering
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
+ Portions of this software are vendored from MIT-licensed projects and retain
16
+ their original copyright notices; see VENDOR.md.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @angadie/chittie-transport-node
2
+
3
+ Network (LAN/Wi-Fi) transport for chittie on **Node / Electron / print-servers**: opens a raw TCP socket to a network printer and streams ESC/POS bytes. **Zero dependencies** (uses `node:net`).
4
+
5
+ Network printers (Epson TM, Star TSP, most kitchen/counter units) listen on **TCP port 9100** (RAW / JetDirect) — the de-facto standard. This is the same approach as `node-thermal-printer`'s Network interface and the native NetPrinter adapters inside RN printer libraries.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @angadie/chittie-transport-node @angadie/chittie-transport
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { render, Printer, Text, Cut } from '@angadie/chittie';
17
+ import { print } from '@angadie/chittie-transport';
18
+ import { createNetworkTransport } from '@angadie/chittie-transport-node';
19
+
20
+ const bytes = render(<Printer width={48}><Text bold>KITCHEN</Text><Cut /></Printer>);
21
+
22
+ const transport = createNetworkTransport({ host: '192.168.1.50', port: 9100 });
23
+ await print(transport, bytes); // connect → write; call transport.disconnect() when done
24
+ ```
25
+
26
+ `createNetworkTransport({ host, port = 9100, timeoutMs = 5000 })`.
27
+
28
+ ## Network printing on other platforms
29
+
30
+ - **React Native (Wi-Fi printers):** Node's `net` isn't available — use [`react-native-tcp-socket`](https://github.com/Rapsssito/react-native-tcp-socket) (its `write` accepts a `Uint8Array` directly) with `createTransport` from [`@angadie/chittie-transport-react-native`](../chittie-transport-react-native):
31
+
32
+ ```ts
33
+ import TcpSocket from 'react-native-tcp-socket';
34
+ import { createTransport } from '@angadie/chittie-transport-react-native';
35
+
36
+ const socket = TcpSocket.createConnection({ host: '192.168.1.50', port: 9100 }, () => {});
37
+ const transport = createTransport({ write: (b) => { socket.write(Buffer.from(b)); return Promise.resolve(); } });
38
+ ```
39
+
40
+ - **Browser:** ⚠️ browsers **cannot open raw TCP sockets**, so a web page can't reach `host:9100` directly. Either route through a **backend proxy** (server holds the socket — use this package there), or use the printer's **HTTP API**: Epson **ePOS-Print** (XML over HTTP) or Star **WebPRNT**.
41
+
42
+ ## License
43
+
44
+ MIT.
@@ -0,0 +1,19 @@
1
+ import { Transport } from "@angadie/chittie-transport";
2
+
3
+ //#region src/index.d.ts
4
+ interface NetworkOptions {
5
+ host: string;
6
+ /** RAW/JetDirect port — 9100 is the de-facto standard for ESC/POS network printers. */
7
+ port?: number;
8
+ /** Connection timeout in ms (default 5000). */
9
+ timeoutMs?: number;
10
+ }
11
+ /**
12
+ * Network (LAN/Wi-Fi) transport for Node / Electron / print-servers: opens a raw
13
+ * TCP socket to a network printer (host:9100) and streams ESC/POS bytes — the
14
+ * same approach as node-thermal-printer's Network interface and the native
15
+ * NetPrinter adapters in RN printer libs. Zero dependencies (uses node:net).
16
+ */
17
+ declare function createNetworkTransport(options: NetworkOptions): Transport;
18
+ //#endregion
19
+ export { NetworkOptions, createNetworkTransport };
package/dist/index.mjs ADDED
@@ -0,0 +1,57 @@
1
+ import { createConnection } from "node:net";
2
+ //#region src/index.ts
3
+ /**
4
+ * Network (LAN/Wi-Fi) transport for Node / Electron / print-servers: opens a raw
5
+ * TCP socket to a network printer (host:9100) and streams ESC/POS bytes — the
6
+ * same approach as node-thermal-printer's Network interface and the native
7
+ * NetPrinter adapters in RN printer libs. Zero dependencies (uses node:net).
8
+ */
9
+ function createNetworkTransport(options) {
10
+ const port = options.port ?? 9100;
11
+ const timeoutMs = options.timeoutMs ?? 5e3;
12
+ let socket = null;
13
+ return {
14
+ connect() {
15
+ return new Promise((resolve, reject) => {
16
+ const s = createConnection({
17
+ host: options.host,
18
+ port
19
+ });
20
+ s.setTimeout(timeoutMs);
21
+ s.once("connect", () => {
22
+ s.setTimeout(0);
23
+ socket = s;
24
+ resolve();
25
+ });
26
+ s.once("timeout", () => {
27
+ s.destroy();
28
+ reject(/* @__PURE__ */ new Error(`chittie: connection to ${options.host}:${port} timed out after ${timeoutMs}ms`));
29
+ });
30
+ s.once("error", reject);
31
+ });
32
+ },
33
+ write(data) {
34
+ return new Promise((resolve, reject) => {
35
+ if (!socket) {
36
+ reject(/* @__PURE__ */ new Error("chittie: not connected — call connect() first"));
37
+ return;
38
+ }
39
+ socket.write(Buffer.from(data), (err) => err ? reject(err) : resolve());
40
+ });
41
+ },
42
+ disconnect() {
43
+ return new Promise((resolve) => {
44
+ if (!socket) {
45
+ resolve();
46
+ return;
47
+ }
48
+ socket.end(() => {
49
+ socket = null;
50
+ resolve();
51
+ });
52
+ });
53
+ }
54
+ };
55
+ }
56
+ //#endregion
57
+ export { createNetworkTransport };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@angadie/chittie-transport-node",
3
+ "version": "0.1.0",
4
+ "description": "Node/Electron network (LAN) transport for chittie — raw TCP to an ESC/POS printer on port 9100. Zero deps (node:net).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "types": "./dist/index.d.mts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.mts",
11
+ "import": "./dist/index.mjs"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "dependencies": {
18
+ "@angadie/chittie-transport": "0.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^22.0.0"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "tsdown",
28
+ "typecheck": "tsc --noEmit",
29
+ "test": "tsx spikes/network.spike.ts"
30
+ }
31
+ }