davexbaileys 2.5.13 → 2.5.14

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.
@@ -174,10 +174,23 @@ export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connect
174
174
  * Use to ensure your WA connection is always on the latest version
175
175
  */
176
176
  export const fetchLatestBaileysVersion = async (options = {}) => {
177
- return {
178
- version: baileysVersion,
179
- isLatest: true
180
- };
177
+ // Fetch live from WhatsApp web so bots always get the current version
178
+ // Falls back to hardcoded baileysVersion if fetch fails
179
+ try {
180
+ const defaultHeaders = {
181
+ 'sec-fetch-site': 'none',
182
+ 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
183
+ };
184
+ const headers = { ...defaultHeaders, ...options.headers };
185
+ const response = await fetch('https://web.whatsapp.com/sw.js', { ...options, method: 'GET', headers });
186
+ if (!response.ok) throw new Error('fetch failed');
187
+ const data = await response.text();
188
+ const match = data.match(/\"?client_revision\"?:\s*(\d+)/);
189
+ if (match?.[1]) {
190
+ return { version: [2, 3000, +match[1]], isLatest: true };
191
+ }
192
+ } catch {}
193
+ return { version: baileysVersion, isLatest: false };
181
194
  };
182
195
  /**
183
196
  * A utility that fetches the latest web version of whatsapp.
@@ -303,15 +316,13 @@ export const getCodeFromWSError = (error) => {
303
316
  statusCode = code;
304
317
  }
305
318
  }
306
- else if (error?.message?.includes('timed out') || error?.code === 'ETIMEDOUT') {
307
- // genuine timeout — map to connectionLost (408) for retry
319
+ else if (
320
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
+ error?.code?.startsWith('E') ||
322
+ error?.message?.includes('timed out')) {
323
+ // handle ETIMEOUT, ENOTFOUND etc
308
324
  statusCode = 408;
309
325
  }
310
- else if (error?.code?.startsWith('E')) {
311
- // network reset/unavailable (ECONNRESET, ENOTFOUND etc) — NOT a 408 timeout loop
312
- // use 503 so bots can distinguish and apply a smarter reconnect strategy
313
- statusCode = 503;
314
- }
315
326
  return statusCode;
316
327
  };
317
328
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "davexbaileys",
3
- "version": "2.5.13",
3
+ "version": "2.5.14",
4
4
  "type": "module",
5
5
  "description": "A lightweight, full-featured WhatsApp Web API library for Node.js",
6
6
  "main": "lib/index.js",