kage-baileys 2.0.1 → 3.0.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  const [major, minor] = process.versions.node.split('.').map(Number);
3
3
  if (major < 22 || (major === 22 && minor < 12)) {
4
- console.error('Kage Baileys requires Node.js >=22.12.0. Use a supported Node.js LTS release.');
4
+ console.error('Kage Baileys necesita Node >=22.12.0 por interoperabilidad CommonJS/ESM. Selecciona Node 22 o 24 en el panel. No basta con borrar engines.');
5
5
  process.exitCode = 1;
6
6
  }
@@ -46,7 +46,7 @@ const axios_1 = __importDefault(require("axios"));
46
46
  const crypto_1 = require("crypto");
47
47
  const os_1 = require("os");
48
48
  const WAProto_1 = require("../../WAProto");
49
- const kage-baileys_version_json_1 = require("../Defaults/kage-baileys-version.json");
49
+ const kageVersionJson = require("../Defaults/wileys-version.json");
50
50
  const Types_1 = require("../Types");
51
51
  const WABinary_1 = require("../WABinary");
52
52
  const COMPANION_PLATFORM_MAP = {
@@ -261,19 +261,22 @@ exports.printQRIfNecessaryListener = printQRIfNecessaryListener;
261
261
 
262
262
  const fetchLatestKageVersion = async (options = {}) => {
263
263
  try {
264
- const { data } = await axios_1.default.get('https://registry.npmjs.org/kage-baileys', {
264
+ const { data } = await axios_1.default.get('https://registry.npmjs.org/kage-baileys/latest', {
265
+ timeout: 15000,
265
266
  ...options,
266
267
  responseType: 'json'
267
268
  });
268
- const versionStr = data.version;
269
- const [major, minor, patch] = versionStr.split('.').map(Number);
269
+ const versionStr = data.version;
270
+ const match = /^(\d+)\.(\d+)\.(\d+)/.exec(versionStr || '');
271
+ if (!match) throw new Error('Invalid Kage package version');
272
+ const [major, minor, patch] = match.slice(1).map(Number);
270
273
  return {
271
274
  version: [major, minor, patch],
272
275
  isLatest: true
273
276
  };
274
277
  } catch (error) {
275
278
  return {
276
- version: kage-baileys_version_json_1.version,
279
+ version: require('../../package.json').version.split('-')[0].split('.').map(Number),
277
280
  isLatest: false,
278
281
  error
279
282
  };
@@ -281,26 +284,8 @@ const fetchLatestKageVersion = async (options = {}) => {
281
284
  };
282
285
  exports.fetchLatestKageVersion = fetchLatestKageVersion;
283
286
 
284
- const fetchLatestBaileysVersion = async (options = {}) => {
285
- try {
286
- const { data } = await axios_1.default.get('https://registry.npmjs.org/kage-baileys', {
287
- ...options,
288
- responseType: 'json'
289
- });
290
- const versionStr = data.version;
291
- const [major, minor, patch] = versionStr.split('.').map(Number);
292
- return {
293
- version: [major, minor, patch],
294
- isLatest: true
295
- };
296
- } catch (error) {
297
- return {
298
- version: kage-baileys_version_json_1.version,
299
- isLatest: false,
300
- error
301
- };
302
- }
303
- };
287
+ // WhatsApp needs its WEB protocol version, not the npm library semver.
288
+ const fetchLatestBaileysVersion = async (options = {}) => fetchLatestWaWebVersion(options);
304
289
  exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
305
290
 
306
291
  /**
@@ -310,14 +295,15 @@ exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
310
295
  const fetchLatestWaWebVersion = async (options) => {
311
296
  try {
312
297
  const { data } = await axios_1.default.get('https://web.whatsapp.com/sw.js', {
298
+ timeout: 15000,
313
299
  ...options,
314
- responseType: 'json'
300
+ responseType: 'text'
315
301
  });
316
302
  const regex = /\\?"client_revision\\?":\s*(\d+)/;
317
303
  const match = data.match(regex);
318
304
  if (!(match === null || match === void 0 ? void 0 : match[1])) {
319
305
  return {
320
- version: kage-baileys_version_json_1.version,
306
+ version: kageVersionJson.version,
321
307
  isLatest: false,
322
308
  error: {
323
309
  message: 'Could not find client revision in the fetched content'
@@ -332,7 +318,7 @@ const fetchLatestWaWebVersion = async (options) => {
332
318
  }
333
319
  catch (error) {
334
320
  return {
335
- version: kage-baileys_version_json_1.version,
321
+ version: kageVersionJson.version,
336
322
  isLatest: false,
337
323
  error
338
324
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kage-baileys",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "Kage Baileys una libreria de WhatsApp.",
5
5
  "keywords": [
6
6
  "kage-baileys",
@@ -38,8 +38,8 @@
38
38
  "test": "node --test test/*.test.cjs",
39
39
  "check": "npm run lint && npm test",
40
40
  "example": "node Example/connection.cjs",
41
- "preinstall": "node engine-requirements.js",
42
- "gen:types": "node scripts/generate-public-types.cjs"
41
+ "gen:types": "node scripts/generate-public-types.cjs",
42
+ "check:engine": "node engine-requirements.js"
43
43
  },
44
44
  "dependencies": {
45
45
  "@adiwajshing/keyed-db": "^0.2.4",
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+ const test = require('node:test');
3
+ const assert = require('node:assert/strict');
4
+ const axios = require('axios');
5
+ const { fetchLatestBaileysVersion, fetchLatestKageVersion } = require('../lib/Utils/generics');
6
+ const fallback = require('../lib/Defaults/wileys-version.json').version;
7
+ async function mocked(get, fn) {
8
+ const old = axios.get;
9
+ axios.get = get;
10
+ try { await fn(); } finally { axios.get = old; }
11
+ }
12
+ test('connection version is WhatsApp WEB revision, not npm library semver', async () => {
13
+ await mocked(async (url, options) => {
14
+ assert.equal(url,'https://web.whatsapp.com/sw.js');
15
+ assert.equal(options.responseType,'text');
16
+ assert.equal(options.timeout,15000);
17
+ return {data:'self.config={"client_revision":1043857761}'};
18
+ }, async () => {
19
+ assert.deepEqual(await fetchLatestBaileysVersion(),{version:[2,3000,1043857761],isLatest:true});
20
+ });
21
+ });
22
+ test('network failure retains the included WhatsApp protocol version and original error', async () => {
23
+ const error = new Error('offline test');
24
+ await mocked(async () => {throw error}, async () => {
25
+ const result = await fetchLatestBaileysVersion();
26
+ assert.deepEqual(result.version,fallback);assert.equal(result.isLatest,false);assert.equal(result.error,error);
27
+ });
28
+ });
29
+ test('malformed version response cannot pass an undefined or npm version to socket', async () => {
30
+ await mocked(async () => ({data:'<html>service unavailable</html>'}), async () => {
31
+ const result = await fetchLatestBaileysVersion();assert.deepEqual(result.version,fallback);assert.equal(result.isLatest,false);
32
+ });
33
+ });
34
+ test('package update helper requests a real npm version document', async () => {
35
+ await mocked(async url => {assert.equal(url,'https://registry.npmjs.org/kage-baileys/latest');return {data:{version:'2.0.1'}}},async()=>{
36
+ const result=await fetchLatestKageVersion();assert.deepEqual(result.version,[2,0,1]);assert.equal(result.isLatest,true);
37
+ });
38
+ });
39
+ test('package fallback is the installed library version, not a WhatsApp version', async () => {
40
+ await mocked(async()=>{throw new Error('offline')},async()=>{
41
+ const result=await fetchLatestKageVersion();assert.deepEqual(result.version,[1,1,8]);assert.equal(result.isLatest,false);
42
+ });
43
+ });