@fer2809fl/baileys 1.4.6 → 1.4.9

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.
@@ -27,57 +27,77 @@ const getFileLock = (path) => {
27
27
  *
28
28
  * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
29
29
  * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
30
- * */
30
+ */
31
31
  const useMultiFileAuthState = async (folder) => {
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ // 🔧 REPARADO: Escritura atómica con archivo temporal
33
33
  const writeData = async (data, file) => {
34
34
  const filePath = (0, path_1.join)(folder, fixFileName(file));
35
35
  const mutex = getFileLock(filePath);
36
- return mutex.acquire().then(async (release) => {
36
+
37
+ return mutex.runExclusive(async () => {
37
38
  try {
38
- await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
39
- }
40
- finally {
41
- release();
39
+ // Escribir a archivo temporal primero
40
+ const tempPath = filePath + '.tmp';
41
+ await (0, promises_1.writeFile)(tempPath, JSON.stringify(data, generics_1.BufferJSON.replacer));
42
+
43
+ // Renombrar atómicamente (evita corrupción)
44
+ await (0, promises_1.rename)(tempPath, filePath);
45
+ } catch (err) {
46
+ // Limpiar archivo temporal si existe
47
+ try {
48
+ await (0, promises_1.unlink)(filePath + '.tmp');
49
+ } catch (_) {}
50
+ throw err;
42
51
  }
43
52
  });
44
53
  };
54
+
55
+ // 🔧 REPARADO: Lectura con mejor manejo de errores
45
56
  const readData = async (file) => {
46
57
  try {
47
58
  const filePath = (0, path_1.join)(folder, fixFileName(file));
48
59
  const mutex = getFileLock(filePath);
49
- return await mutex.acquire().then(async (release) => {
60
+
61
+ return await mutex.runExclusive(async () => {
50
62
  try {
51
63
  const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
52
64
  return JSON.parse(data, generics_1.BufferJSON.reviver);
53
- }
54
- finally {
55
- release();
65
+ } catch (readErr) {
66
+ // Si el archivo no existe, retornar null sin error
67
+ if (readErr.code === 'ENOENT') {
68
+ return null;
69
+ }
70
+ throw readErr;
56
71
  }
57
72
  });
58
- }
59
- catch (error) {
73
+ } catch (error) {
74
+ // Solo log en errores graves, no "file not found"
75
+ if (error.code !== 'ENOENT') {
76
+ console.error(`[Auth] Error reading ${file}:`, error.message);
77
+ }
60
78
  return null;
61
79
  }
62
80
  };
81
+
63
82
  const removeData = async (file) => {
64
83
  try {
65
84
  const filePath = (0, path_1.join)(folder, fixFileName(file));
66
85
  const mutex = getFileLock(filePath);
67
- return mutex.acquire().then(async (release) => {
86
+ return mutex.runExclusive(async () => {
68
87
  try {
69
88
  await (0, promises_1.unlink)(filePath);
70
- }
71
- catch (_a) {
72
- }
73
- finally {
74
- release();
89
+ } catch (err) {
90
+ // Ignorar si el archivo no existe
91
+ if (err.code !== 'ENOENT') {
92
+ throw err;
93
+ }
75
94
  }
76
95
  });
77
- }
78
- catch (_a) {
96
+ } catch (_a) {
97
+ // Ignorar errores al eliminar
79
98
  }
80
99
  };
100
+
81
101
  const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
82
102
  if (folderInfo) {
83
103
  if (!folderInfo.isDirectory()) {
@@ -110,7 +110,7 @@ exports.DOUBLE_BYTE_TOKENS = [
110
110
  'audio_duration',
111
111
  'admin',
112
112
  'connected',
113
- 'delta',
113
+ 'Asta',
114
114
  'rcat',
115
115
  'disable',
116
116
  'collection',
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
  const chalk = require('chalk');
3
3
  console.clear();
4
- console.log(chalk.hex('#FFFFFF')('Baileys Delta ') + chalk.hex('#00FFFF')('By Melody Xz\n'));
4
+ console.log(chalk.hex('#FFFFFF')('Baileys Asta ') + chalk.hex('#00FFFF')('By Fer2809fl\n'));
5
5
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
7
  var desc = Object.getOwnPropertyDescriptor(m, k);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fer2809fl/baileys",
3
- "version": "1.4.6",
3
+ "version": "1.4.9",
4
4
  "description": "API de WhatsApp Web para Node.js",
5
5
  "keywords": [
6
6
  "baileys",
@@ -10,10 +10,10 @@
10
10
  "multi-device",
11
11
  "websocket"
12
12
  ],
13
- "homepage": "https://github.com/Fer2809fl/Baileys",
13
+ "homepage": "https://github.com/Fer2809fl/Bail",
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/Fer2809fl/Baileys"
16
+ "url": "https://github.com/Fer2809fl/Bail"
17
17
  },
18
18
  "license": "MIT",
19
19
  "author": "Fer2809fl",
@@ -47,7 +47,7 @@
47
47
  "cheerio": "^1.0.0-rc.10",
48
48
  "gradient-string": "^2.0.2",
49
49
  "libphonenumber-js": "^1.10.20",
50
- "libsignal": "^2.0.1",
50
+ "libsignal": "github:adiwajshing/libsignal-node",
51
51
  "lodash": "^4.17.21",
52
52
  "music-metadata": "^7.12.3",
53
53
  "pino": "^9.6.0",
@@ -100,4 +100,4 @@
100
100
  "engines": {
101
101
  "node": ">=20.0.0"
102
102
  }
103
- }
103
+ }