node-thermal-printer-js 1.0.3 → 1.0.5

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 (3) hide show
  1. package/.env.example +16 -0
  2. package/app.js +12 -10
  3. package/package.json +4 -3
package/.env.example ADDED
@@ -0,0 +1,16 @@
1
+ # Default: COM5 for Windows serial port, or use BLE bridge
2
+ PRINTER_TRANSPORT=com
3
+
4
+ # COM mode settings
5
+ PRINTER_COM_PORT=COM5
6
+
7
+ # BLE mode settings (if using BLE bridge)
8
+ PRINTER_BLE_NAME=PSF588
9
+ # PRINTER_BLE_ADDRESS=AA:BB:CC:DD:EE:FF
10
+ PRINTER_BLE_CHAR_UUID=49535343-8841-43f4-a8d4-ecbe34729bb3
11
+ PRINTER_BLE_CONNECT_TIMEOUT=15
12
+ PRINTER_BLE_SCAN_TIMEOUT=10
13
+ PRINTER_BLE_PAIR=0
14
+
15
+ # Python command for BLE bridge (only needed for BLE mode)
16
+ # PRINTER_PYTHON_CMD=python
package/app.js CHANGED
@@ -58,22 +58,24 @@ const runPythonProcess = ({ cmd, cmdArgs, scriptArgs }) =>
58
58
  });
59
59
 
60
60
  const printViaComPort = async (data, options = {}) => {
61
- const portPath = options.portPath || process.env.PRINTER_COM_PORT;
61
+ const portPath = options.portPath || process.env.PRINTER_COM_PORT || "COM5";
62
62
  const baudRate = options.baudRate || 9600;
63
63
 
64
64
  // Dynamically import `serialport` only when COM transport is requested.
65
- let SerialPortModule;
65
+ let SerialPortCtor;
66
66
  try {
67
- SerialPortModule = await import("serialport");
67
+ const SerialPortModule = await import("serialport");
68
+ SerialPortCtor = SerialPortModule.SerialPort || SerialPortModule.default;
69
+
70
+ if (!SerialPortCtor) {
71
+ throw new Error("SerialPort constructor not found in module exports");
72
+ }
68
73
  } catch (e) {
69
74
  return Promise.reject(
70
75
  new Error(`serialport module not available: ${e.message}`),
71
76
  );
72
77
  }
73
78
 
74
- const SerialPortCtor =
75
- SerialPortModule.default || SerialPortModule.SerialPort || SerialPortModule;
76
-
77
79
  const port = new SerialPortCtor({
78
80
  path: portPath,
79
81
  baudRate,
@@ -150,10 +152,10 @@ const printViaBleBridge = (data, options = {}) => {
150
152
  const candidates = envCmd
151
153
  ? [{ cmd: envCmd, cmdArgs: [] }]
152
154
  : [
153
- { cmd: "py", cmdArgs: ["-3.11"] },
154
- { cmd: "py", cmdArgs: ["-3"] },
155
- { cmd: "python", cmdArgs: [] },
156
- ];
155
+ { cmd: "py", cmdArgs: ["-3.11"] },
156
+ { cmd: "py", cmdArgs: ["-3"] },
157
+ { cmd: "python", cmdArgs: [] },
158
+ ];
157
159
 
158
160
  return new Promise(async (resolve, reject) => {
159
161
  const failures = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-thermal-printer-js",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "ESC/POS printer helper for PSF588 Bluetooth and COM printing.",
5
5
  "main": "app.js",
6
6
  "exports": {
@@ -10,7 +10,8 @@
10
10
  "app.js",
11
11
  "ble_print.py",
12
12
  "ble_scan.py",
13
- "README.md"
13
+ "README.md",
14
+ ".env.example"
14
15
  ],
15
16
  "scripts": {
16
17
  "test": "node test-api.js",
@@ -34,4 +35,4 @@
34
35
  "dotenv": "^16.6.1",
35
36
  "serialport": "^13.0.0"
36
37
  }
37
- }
38
+ }