@fer2809fl/baileys 7.0.4 → 7.0.5

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.
Files changed (51) hide show
  1. package/README.md +347 -50
  2. package/lib/Defaults/index.js +1 -1
  3. package/lib/Modded/message_builder.js +2356 -0
  4. package/lib/Socket/chats.d.ts +14 -0
  5. package/lib/Socket/chats.js +48 -0
  6. package/lib/Socket/index.d.ts +17 -0
  7. package/lib/Socket/messages-send.d.ts +18 -0
  8. package/lib/Socket/messages-send.js +50 -2
  9. package/lib/Utils/anti-ban.d.ts +41 -0
  10. package/lib/Utils/anti-ban.js +182 -0
  11. package/lib/Utils/banner.d.ts +8 -0
  12. package/lib/Utils/banner.js +76 -0
  13. package/lib/Utils/bot-utils.d.ts +57 -0
  14. package/lib/Utils/bot-utils.js +241 -0
  15. package/lib/Utils/enhanced-cache.d.ts +40 -0
  16. package/lib/Utils/enhanced-cache.js +242 -0
  17. package/lib/Utils/enhanced-logger.d.ts +41 -0
  18. package/lib/Utils/enhanced-logger.js +185 -0
  19. package/lib/Utils/index.d.ts +14 -0
  20. package/lib/Utils/index.js +13 -0
  21. package/lib/Utils/lid-utils.d.ts +139 -0
  22. package/lib/Utils/lid-utils.js +503 -0
  23. package/lib/Utils/message-queue.d.ts +47 -0
  24. package/lib/Utils/message-queue.js +226 -0
  25. package/lib/Utils/rich-message-utils.d.ts +21 -0
  26. package/lib/Utils/rich-message-utils.js +229 -0
  27. package/lib/Utils/rich-messages.d.ts +52 -0
  28. package/lib/Utils/rich-messages.js +185 -0
  29. package/lib/Utils/scheduled-messages.d.ts +122 -0
  30. package/lib/Utils/scheduled-messages.js +289 -0
  31. package/lib/Utils/smart-reconnect.d.ts +48 -0
  32. package/lib/Utils/smart-reconnect.js +207 -0
  33. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  34. package/lib/Utils/use-sqlite-auth-state.js +95 -0
  35. package/lib/VoIP/audio-feeder.d.ts +15 -0
  36. package/lib/VoIP/audio-feeder.js +132 -0
  37. package/lib/VoIP/index.js +277 -0
  38. package/lib/VoIP/relay-transport.d.ts +43 -0
  39. package/lib/VoIP/relay-transport.js +559 -0
  40. package/lib/VoIP/signaling.js +594 -0
  41. package/lib/VoIP/types.d.ts +69 -0
  42. package/lib/VoIP/types.js +17 -0
  43. package/lib/VoIP/wasm-engine.d.ts +103 -0
  44. package/lib/VoIP/wasm-engine.js +1214 -0
  45. package/lib/VoIP/worker-bootstrap.js +1042 -0
  46. package/lib/assets/wasm/loader.js +5 -0
  47. package/lib/assets/wasm/whatsapp.wasm +0 -0
  48. package/lib/assets/wasm/worker-modules.js +273 -0
  49. package/lib/index.d.ts +41 -0
  50. package/lib/index.js +3 -0
  51. package/package.json +10 -2
@@ -0,0 +1,185 @@
1
+ const LOG_LEVELS = {
2
+ fatal: 60,
3
+ error: 50,
4
+ warn: 40,
5
+ info: 30,
6
+ debug: 20,
7
+ trace: 10,
8
+ silent: Infinity
9
+ };
10
+
11
+ const COLORS = {
12
+ reset: '\x1b[0m',
13
+ bold: '\x1b[1m',
14
+ dim: '\x1b[2m',
15
+ fatal: '\x1b[35m\x1b[1m',
16
+ error: '\x1b[31m',
17
+ warn: '\x1b[33m',
18
+ info: '\x1b[36m',
19
+ debug: '\x1b[34m',
20
+ trace: '\x1b[90m',
21
+ socket: '\x1b[32m',
22
+ message: '\x1b[33m',
23
+ media: '\x1b[35m',
24
+ group: '\x1b[36m',
25
+ auth: '\x1b[31m',
26
+ cache: '\x1b[34m'
27
+ };
28
+
29
+ const CATEGORY_ICONS = {
30
+ socket: '[SOCKET]',
31
+ message: '[MSG]',
32
+ media: '[MEDIA]',
33
+ group: '[GROUP]',
34
+ auth: '[AUTH]',
35
+ cache: '[CACHE]',
36
+ queue: '[QUEUE]',
37
+ error: '[ERROR]',
38
+ warn: '[WARN]',
39
+ info: '[INFO]',
40
+ debug: '[DEBUG]',
41
+ success: '[OK]'
42
+ };
43
+
44
+ function formatTime(date = new Date()) {
45
+ return date.toLocaleTimeString('es-ES', { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
46
+ }
47
+
48
+ function formatConsoleMessage(level, category, message, data) {
49
+ const time = formatTime();
50
+ const levelColor = COLORS[level] || COLORS.info;
51
+ const categoryColor = COLORS[category] || COLORS.reset;
52
+ const icon = CATEGORY_ICONS[category] || CATEGORY_ICONS[level] || '';
53
+ let formatted = `${COLORS.dim}[${time}]${COLORS.reset} `;
54
+ formatted += `${levelColor}${level.toUpperCase().padEnd(5)}${COLORS.reset} `;
55
+ if (category) formatted += `${categoryColor}${icon} ${category}${COLORS.reset} `;
56
+ formatted += message;
57
+ if (data && Object.keys(data).length > 0) {
58
+ const dataStr = JSON.stringify(data, null, 0);
59
+ if (dataStr.length < 100) formatted += ` ${COLORS.dim}${dataStr}${COLORS.reset}`;
60
+ }
61
+ return formatted;
62
+ }
63
+
64
+ class RyzeLogger {
65
+ constructor(options = {}) {
66
+ this.options = {
67
+ level: options.level || 'info',
68
+ prettyPrint: options.prettyPrint !== false,
69
+ category: options.category || 'baileys',
70
+ colors: options.colors !== false,
71
+ timestamps: options.timestamps !== false,
72
+ ...options
73
+ };
74
+ this.category = this.options.category;
75
+ this.filters = new Set(options.filters || []);
76
+ this.history = [];
77
+ this.maxHistory = options.maxHistory || 1000;
78
+ }
79
+
80
+ _log(level, messageOrData, data = {}) {
81
+ let message = '';
82
+ let logData = data;
83
+ if (typeof messageOrData === 'string') {
84
+ message = messageOrData;
85
+ } else if (typeof messageOrData === 'object') {
86
+ logData = messageOrData;
87
+ message = messageOrData.msg || '';
88
+ }
89
+ if (this.filters.size > 0) {
90
+ const shouldFilter = [...this.filters].some(f => message.includes(f) || JSON.stringify(logData).includes(f));
91
+ if (shouldFilter) return;
92
+ }
93
+ this._addToHistory(level, message, logData);
94
+ if (this.options.prettyPrint) console.log(formatConsoleMessage(level, this.category, message, logData));
95
+ }
96
+
97
+ _addToHistory(level, message, data) {
98
+ this.history.push({ timestamp: new Date().toISOString(), level, category: this.category, message, data });
99
+ if (this.history.length > this.maxHistory) this.history.shift();
100
+ }
101
+
102
+ fatal(messageOrData, data) { this._log('fatal', messageOrData, data); }
103
+ error(messageOrData, data) { this._log('error', messageOrData, data); }
104
+ warn(messageOrData, data) { this._log('warn', messageOrData, data); }
105
+ info(messageOrData, data) { this._log('info', messageOrData, data); }
106
+ debug(messageOrData, data) { this._log('debug', messageOrData, data); }
107
+ trace(messageOrData, data) { this._log('trace', messageOrData, data); }
108
+
109
+ success(message, data = {}) {
110
+ const formatted = `${COLORS.reset}${CATEGORY_ICONS.success} ${message}${COLORS.reset}`;
111
+ this._log('info', formatted, data);
112
+ }
113
+
114
+ child(bindings) {
115
+ return new RyzeLogger({ ...this.options, category: bindings.class || bindings.category || this.category });
116
+ }
117
+
118
+ setLevel(level) {
119
+ this.options.level = level;
120
+ }
121
+
122
+ addFilter(pattern) { this.filters.add(pattern); }
123
+ removeFilter(pattern) { this.filters.delete(pattern); }
124
+
125
+ getHistory(options = {}) {
126
+ let history = [...this.history];
127
+ if (options.level) history = history.filter(h => h.level === options.level);
128
+ if (options.category) history = history.filter(h => h.category === options.category);
129
+ if (options.since) {
130
+ const sinceDate = new Date(options.since);
131
+ history = history.filter(h => new Date(h.timestamp) >= sinceDate);
132
+ }
133
+ if (options.limit) history = history.slice(-options.limit);
134
+ return history;
135
+ }
136
+
137
+ clearHistory() { this.history = []; }
138
+
139
+ exportLogs(format = 'json') {
140
+ if (format === 'json') return JSON.stringify(this.history, null, 2);
141
+ return this.history.map(h => `[${h.timestamp}] ${h.level.toUpperCase()} [${h.category}] ${h.message}`).join('\n');
142
+ }
143
+
144
+ time(label) {
145
+ const start = Date.now();
146
+ return { end: (message) => {
147
+ const duration = Date.now() - start;
148
+ this.debug(`${message || label}: ${duration}ms`, { duration, label });
149
+ return duration;
150
+ }};
151
+ }
152
+
153
+ if(condition, level, message, data) {
154
+ if (condition) this[level](message, data);
155
+ }
156
+
157
+ throttle(key, message, data, intervalMs = 5000) {
158
+ if (!this._throttleCache) this._throttleCache = new Map();
159
+ const now = Date.now();
160
+ const lastLog = this._throttleCache.get(key) || 0;
161
+ if (now - lastLog >= intervalMs) {
162
+ this._throttleCache.set(key, now);
163
+ this.info(message, data);
164
+ }
165
+ }
166
+ }
167
+
168
+ function createLogger(options = {}) {
169
+ return new RyzeLogger({
170
+ level: process.env.LOG_LEVEL || 'info',
171
+ prettyPrint: process.env.NODE_ENV !== 'production',
172
+ ...options
173
+ });
174
+ }
175
+
176
+ const defaultLogger = createLogger({ category: 'baileys' });
177
+
178
+ export {
179
+ LOG_LEVELS,
180
+ COLORS,
181
+ CATEGORY_ICONS,
182
+ RyzeLogger,
183
+ createLogger,
184
+ defaultLogger as default
185
+ };
@@ -20,4 +20,18 @@ export * from "./identity-change-handler.js";
20
20
  export * from "./stanza-ack.js";
21
21
  export * from "./rich-messages.js";
22
22
  export * from "./sticker-pack.js";
23
+ export * from "./companion-reg-client-utils.js";
24
+ export * from "./reporting-utils.js";
25
+ // -- Añadido en v7.0.5: portado desde el fork beta --
26
+ export * from "./lid-utils.js";
27
+ export * from "./scheduled-messages.js";
28
+ export * from "./anti-ban.js";
29
+ export * from "./smart-reconnect.js";
30
+ export * from "./message-queue.js";
31
+ export * from "./enhanced-cache.js";
32
+ export * from "./enhanced-logger.js";
33
+ export * from "./bot-utils.js";
34
+ export * from "./banner.js";
35
+ export * from "./rich-message-utils.js";
36
+ export * from "./use-sqlite-auth-state.js";
23
37
  //# sourceMappingURL=index.d.ts.map
@@ -21,4 +21,17 @@ export * from './stanza-ack.js';
21
21
  export * from './companion-reg-client-utils.js';
22
22
  export * from './rich-messages.js';
23
23
  export * from './sticker-pack.js';
24
+ export * from './reporting-utils.js';
25
+ // -- Añadido en v7.0.5: portado desde el fork beta --
26
+ export * from './lid-utils.js';
27
+ export * from './scheduled-messages.js';
28
+ export * from './anti-ban.js';
29
+ export * from './smart-reconnect.js';
30
+ export * from './message-queue.js';
31
+ export * from './enhanced-cache.js';
32
+ export * from './enhanced-logger.js';
33
+ export * from './bot-utils.js';
34
+ export * from './banner.js';
35
+ export * from './rich-message-utils.js';
36
+ export * from './use-sqlite-auth-state.js';
24
37
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,139 @@
1
+ import type { WASocket } from '../Socket/index.js';
2
+
3
+ export interface LidParticipant {
4
+ id?: string;
5
+ jid?: string;
6
+ lid?: string;
7
+ phoneNumber?: string;
8
+ admin?: string | null;
9
+ }
10
+
11
+ export interface LidMessage {
12
+ key: {
13
+ participant?: string;
14
+ remoteJid?: string;
15
+ };
16
+ participantPn?: string;
17
+ }
18
+
19
+ /**
20
+ * Cek apakah JID adalah format LID
21
+ */
22
+ export declare const isLid: (jid: string | undefined) => boolean;
23
+
24
+ /**
25
+ * Cek apakah JID adalah hasil konversi LID yang salah
26
+ */
27
+ export declare const isLidConverted: (jid: string | undefined) => boolean;
28
+
29
+ /**
30
+ * Convert LID ke format JID standard @s.whatsapp.net
31
+ */
32
+ export declare const lidToJid: (jid: string) => string;
33
+
34
+ /**
35
+ * Versi lidToJid yang aman, mengembalikan null jika tidak bisa convert
36
+ */
37
+ export declare const lidToJidSafe: (jid: string) => string | null;
38
+
39
+ /**
40
+ * Extract nomor dari JID apapun (termasuk LID)
41
+ */
42
+ export declare const extractNumber: (jid: string) => Promise<string>;
43
+
44
+ /**
45
+ * Resolve LID atau LID-converted JID ke JID asli menggunakan group metadata
46
+ */
47
+ export declare const resolveLidFromParticipants: (
48
+ jid: string,
49
+ participants?: LidParticipant[]
50
+ ) => string;
51
+
52
+ /**
53
+ * Resolve JID yang mungkin LID-converted ke JID asli
54
+ * Menangani cache, group participants, dan deteksi LID yang salah
55
+ */
56
+ export declare const resolveAnyLidToJid: (
57
+ jid: string,
58
+ participants?: LidParticipant[]
59
+ ) => string;
60
+
61
+ /**
62
+ * Convert array of JIDs, replacing any LIDs or LID-converted JIDs
63
+ */
64
+ export declare const convertLidArray: (
65
+ jids: string[],
66
+ participants?: LidParticipant[]
67
+ ) => string[];
68
+
69
+ /**
70
+ * Decode JID dan kembalikan dalam format standard
71
+ */
72
+ export declare const decodeAndNormalize: (jid: string) => string | null;
73
+
74
+ /**
75
+ * Konversi participant JID dari message
76
+ */
77
+ export declare const resolveParticipant: (
78
+ msg: LidMessage,
79
+ sock?: WASocket
80
+ ) => Promise<string | null>;
81
+
82
+ /**
83
+ * Helper untuk mendapatkan JID asli dari participant
84
+ */
85
+ export declare const getParticipantJid: (participant: LidParticipant) => string;
86
+
87
+ /**
88
+ * Convert semua participant IDs ke format yang bisa di-mention
89
+ */
90
+ export declare const getParticipantJids: (participants?: LidParticipant[]) => string[];
91
+
92
+ /**
93
+ * Cari participant berdasarkan nomor telepon
94
+ */
95
+ export declare const findParticipantByNumber: (
96
+ participants: LidParticipant[],
97
+ targetJid: string
98
+ ) => LidParticipant | null;
99
+
100
+ /**
101
+ * Cache LID to JID mapping dari array participant
102
+ */
103
+ export declare const cacheParticipantLids: (participants?: LidParticipant[]) => void;
104
+
105
+ /**
106
+ * Get cached JID for a LID
107
+ */
108
+ export declare const getCachedJid: (lid: string) => string | null;
109
+
110
+ /**
111
+ * Normalize JID ke nomor telepon (tanpa suffix @s.whatsapp.net atau @lid)
112
+ */
113
+ export declare const normalizeToPhoneNumber: (
114
+ jid: string,
115
+ participants?: LidParticipant[]
116
+ ) => string;
117
+
118
+ /**
119
+ * Simpan mapping LID-JID ke cache
120
+ */
121
+ export declare const cacheLidJid: (lid: string, jid: string) => void;
122
+
123
+ /**
124
+ * Resolve JID menggunakan sock.signalRepository o sock.store
125
+ */
126
+ export declare const resolveFromSock: (
127
+ jid: string,
128
+ sock?: WASocket
129
+ ) => Promise<string>;
130
+
131
+ /**
132
+ * Get jumlah item di LID cache
133
+ */
134
+ export declare const getLidCacheSize: () => number;
135
+
136
+ /**
137
+ * Simpan cache ke disk secara manual
138
+ */
139
+ export declare const savePersistentCache: () => void;