@raevon/n8n-nodes-whatsapp 2.0.11 → 2.0.13

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.
@@ -11,6 +11,7 @@ export interface WhatsAppCredentials {
11
11
  }
12
12
  export declare function getServerUrl(cfg: WhatsAppCredentials): string;
13
13
  export declare function ensureServerRunning(cfg: WhatsAppCredentials): Promise<void>;
14
+ export declare function startServerIfNeeded(cfg: WhatsAppCredentials): Promise<void>;
14
15
  export declare function stopServer(cfg: WhatsAppCredentials): Promise<void>;
15
16
  export declare function disconnect(): Promise<void>;
16
17
  export declare function getWhatsAppCredentials(credentials: Record<string, any>): Promise<WhatsAppCredentials>;
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getServerUrl = getServerUrl;
40
40
  exports.ensureServerRunning = ensureServerRunning;
41
+ exports.startServerIfNeeded = startServerIfNeeded;
41
42
  exports.stopServer = stopServer;
42
43
  exports.disconnect = disconnect;
43
44
  exports.getWhatsAppCredentials = getWhatsAppCredentials;
@@ -345,33 +346,30 @@ async function startServer(cfg) {
345
346
  }
346
347
  async function ensureServerRunning(cfg) {
347
348
  const port = getPort(cfg);
348
- // Check if server is already running and healthy
349
+ // Just check if server is running don't start it
349
350
  try {
350
351
  const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
351
352
  if (res.ok)
352
353
  return; // Server alive
353
354
  }
354
355
  catch { }
355
- // Port is in use but server not responding stale from another worker, can't kill it
356
- // Just try to use it anyway (might have recovered)
356
+ throw new Error(`WhatsApp server not running on port ${port}. Run "Start Server" or "Connect" first.`);
357
+ }
358
+ async function startServerIfNeeded(cfg) {
359
+ const port = getPort(cfg);
360
+ // Check if already running
357
361
  try {
358
- const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(5000) });
362
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
359
363
  if (res.ok)
360
- return;
364
+ return; // Already running
361
365
  }
362
366
  catch { }
363
- // Port truly free — start server
367
+ // Port free — start server
364
368
  if (await isPortOpen(port)) {
365
369
  await startServer(cfg);
366
370
  return;
367
371
  }
368
- // Port occupied, can't start — try to use existing anyway
369
- try {
370
- const res = await fetch(`http://127.0.0.1:${port}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
371
- if (res.ok)
372
- return; // It worked
373
- }
374
- catch { }
372
+ // Port occupied by something else
375
373
  throw new Error(`Port ${port} occupied. Restart n8n container, then try again.`);
376
374
  }
377
375
  async function stopServer(cfg) {
@@ -54,7 +54,7 @@ class WhatsAppConnect {
54
54
  for (let i = 0; i < items.length; i++) {
55
55
  try {
56
56
  if (operation === 'startServer') {
57
- await (0, WhatsAppApiHelper_1.ensureServerRunning)(cfg);
57
+ await (0, WhatsAppApiHelper_1.startServerIfNeeded)(cfg);
58
58
  returnData.push({
59
59
  json: { success: true, message: 'Server started', port: (0, WhatsAppApiHelper_1.getServerUrl)(cfg), sessionPath: cfg.sessionPath },
60
60
  pairedItem: { item: i },
@@ -78,7 +78,7 @@ class WhatsAppConnect {
78
78
  }
79
79
  else if (operation === 'connect') {
80
80
  try {
81
- await (0, WhatsAppApiHelper_1.ensureServerRunning)(cfg);
81
+ await (0, WhatsAppApiHelper_1.startServerIfNeeded)(cfg);
82
82
  }
83
83
  catch (err) {
84
84
  returnData.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raevon/n8n-nodes-whatsapp",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
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",