@raevon/n8n-nodes-whatsapp 2.0.8 → 2.0.10

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.
@@ -41,7 +41,6 @@ exports.ensureServerRunning = ensureServerRunning;
41
41
  exports.stopServer = stopServer;
42
42
  exports.disconnect = disconnect;
43
43
  exports.getWhatsAppCredentials = getWhatsAppCredentials;
44
- const node_child_process_1 = require("node:child_process");
45
44
  const node_path_1 = __importDefault(require("node:path"));
46
45
  const node_fs_1 = __importDefault(require("node:fs"));
47
46
  const node_net_1 = __importDefault(require("node:net"));
@@ -346,50 +345,29 @@ async function startServer(cfg) {
346
345
  }
347
346
  async function ensureServerRunning(cfg) {
348
347
  const port = getPort(cfg);
349
- // Port is free start server
350
- if (await isPortOpen(port)) {
351
- await startServer(cfg);
352
- return;
353
- }
354
- // Port is in use — server already running, just verify it responds
348
+ // Try to connect to existing server first
355
349
  try {
356
- const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
350
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(5000) });
357
351
  if (res.ok)
358
- return; // Server alive, use it
359
- }
360
- catch { }
361
- // Port in use but not responding — try to kill via /proc
362
- try {
363
- const out = (0, node_child_process_1.execSync)(`cat /proc/net/tcp | awk '{if(NR>1){split($2,a,\":\");if(strtonum("0x"a[2])==${port})print $10}}'`, { encoding: 'utf-8' }).trim();
364
- if (out) {
365
- // Find PID from inode
366
- const inode = out;
367
- const pidOut = (0, node_child_process_1.execSync)(`for p in /proc/[0-9]*/fd/*; do if readlink "$p" 2>/dev/null | grep -q "socket:\\[${inode}]"; then echo "$p" | cut -d/ -f3; break; fi; done`, { encoding: 'utf-8' }).trim();
368
- if (pidOut)
369
- (0, node_child_process_1.execSync)(`kill -9 ${pidOut}`);
370
- await new Promise(r => setTimeout(r, 1500));
371
- }
352
+ return; // Server alive
372
353
  }
373
354
  catch { }
374
- // Try again
355
+ // Server not running — start it
375
356
  if (await isPortOpen(port)) {
376
357
  await startServer(cfg);
377
358
  return;
378
359
  }
379
- throw new Error(`Port ${port} occupied by unknown process. Restart n8n container to clear.`);
360
+ // Port occupied by something else
361
+ throw new Error(`Port ${port} occupied by another process. Restart n8n container to clear.`);
380
362
  }
381
363
  async function stopServer(cfg) {
382
364
  const port = getPort(cfg);
383
- // First try to shut down gracefully via the server's own /signout endpoint
365
+ // Try graceful shutdown via the server's own /signout endpoint
384
366
  try {
385
- const res = await fetch(`http://127.0.0.1:${port}/signout`, { method: 'POST', signal: AbortSignal.timeout(3000) });
386
- if (res.ok) {
387
- servers.delete(port);
388
- return;
389
- }
367
+ await fetch(`http://127.0.0.1:${port}/signout`, { method: 'POST', signal: AbortSignal.timeout(3000) });
390
368
  }
391
369
  catch { }
392
- // If that fails, clean up in-memory state
370
+ // Clean up in-memory state
393
371
  const state = servers.get(port);
394
372
  if (state) {
395
373
  if (state.socket) {
@@ -79,13 +79,14 @@ class WhatsAppConnect {
79
79
  continue;
80
80
  }
81
81
  try {
82
- const response = await fetch(`${(0, WhatsAppApiHelper_1.getServerUrl)(cfg)}/connect`, { method: 'POST' });
82
+ const serverUrl = (0, WhatsAppApiHelper_1.getServerUrl)(cfg);
83
+ const response = await fetch(`${serverUrl}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
83
84
  const result = await response.json();
84
85
  returnData.push({ json: { ...result, sessionPath: cfg.sessionPath }, pairedItem: { item: i } });
85
86
  }
86
87
  catch (err) {
87
88
  returnData.push({
88
- json: { connected: false, error: `Server unreachable: ${err.message}`, sessionPath: cfg.sessionPath },
89
+ json: { connected: false, error: `Connect failed: ${err.message}`, sessionPath: cfg.sessionPath },
89
90
  pairedItem: { item: i },
90
91
  });
91
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raevon/n8n-nodes-whatsapp",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "n8n community node for WhatsApp — send and receive messages with anti-ban protection via the Baileys library",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",