@queenanya/baileys 6.9.2 → 7.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.
Files changed (59) hide show
  1. package/README.md +56 -13
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.js +5 -2
  4. package/lib/Socket/business.d.ts +46 -8
  5. package/lib/Socket/business.js +1 -0
  6. package/lib/Socket/chats.d.ts +10 -2
  7. package/lib/Socket/chats.js +42 -3
  8. package/lib/Socket/groups.d.ts +17 -3
  9. package/lib/Socket/groups.js +12 -1
  10. package/lib/Socket/index.d.ts +46 -8
  11. package/lib/Socket/messages-recv.d.ts +45 -9
  12. package/lib/Socket/messages-recv.js +184 -22
  13. package/lib/Socket/messages-send.d.ts +40 -6
  14. package/lib/Socket/messages-send.js +153 -37
  15. package/lib/Socket/newsletter.d.ts +140 -0
  16. package/lib/Socket/newsletter.js +249 -0
  17. package/lib/Socket/registration.d.ts +46 -11
  18. package/lib/Socket/socket.js +18 -4
  19. package/lib/Store/make-in-memory-store.d.ts +2 -2
  20. package/lib/Store/make-in-memory-store.js +11 -44
  21. package/lib/Types/Auth.d.ts +1 -0
  22. package/lib/Types/Chat.d.ts +5 -0
  23. package/lib/Types/Events.d.ts +40 -2
  24. package/lib/Types/GroupMetadata.d.ts +3 -1
  25. package/lib/Types/Label.d.ts +11 -0
  26. package/lib/Types/Message.d.ts +39 -27
  27. package/lib/Types/Newsletter.d.ts +79 -0
  28. package/lib/Types/Newsletter.js +18 -0
  29. package/lib/Types/Socket.d.ts +7 -0
  30. package/lib/Types/index.d.ts +9 -0
  31. package/lib/Types/index.js +1 -0
  32. package/lib/Utils/auth-utils.js +1 -0
  33. package/lib/Utils/chat-utils.js +16 -0
  34. package/lib/Utils/crypto.d.ts +1 -1
  35. package/lib/Utils/crypto.js +4 -2
  36. package/lib/Utils/decode-wa-message.d.ts +1 -0
  37. package/lib/Utils/decode-wa-message.js +50 -22
  38. package/lib/Utils/generics.d.ts +30 -10
  39. package/lib/Utils/generics.js +82 -10
  40. package/lib/Utils/history.d.ts +4 -0
  41. package/lib/Utils/history.js +3 -0
  42. package/lib/Utils/logger.d.ts +1 -3
  43. package/lib/Utils/messages-media.d.ts +10 -1
  44. package/lib/Utils/messages-media.js +61 -18
  45. package/lib/Utils/messages.d.ts +2 -1
  46. package/lib/Utils/messages.js +77 -76
  47. package/lib/Utils/noise-handler.d.ts +3 -2
  48. package/lib/Utils/noise-handler.js +18 -5
  49. package/lib/Utils/process-message.d.ts +3 -2
  50. package/lib/Utils/process-message.js +53 -21
  51. package/lib/Utils/signal.js +21 -16
  52. package/lib/Utils/use-multi-file-auth-state.js +16 -3
  53. package/lib/WABinary/decode.d.ts +2 -2
  54. package/lib/WABinary/decode.js +6 -4
  55. package/lib/WABinary/encode.d.ts +1 -2
  56. package/lib/WABinary/encode.js +1 -1
  57. package/lib/WABinary/jid-utils.d.ts +3 -1
  58. package/lib/WABinary/jid-utils.js +4 -1
  59. package/package.json +32 -27
@@ -11,7 +11,7 @@ const generateIV = (counter) => {
11
11
  new DataView(iv).setUint32(8, counter);
12
12
  return new Uint8Array(iv);
13
13
  };
14
- const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, }) => {
14
+ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }) => {
15
15
  logger = logger.child({ class: 'ns' });
16
16
  const authenticate = (data) => {
17
17
  if (!isFinished) {
@@ -101,10 +101,23 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
101
101
  if (isFinished) {
102
102
  data = encrypt(data);
103
103
  }
104
- const introSize = sentIntro ? 0 : NOISE_HEADER.length;
104
+ let header;
105
+ if (routingInfo) {
106
+ header = Buffer.alloc(7);
107
+ header.write('ED', 0, 'utf8');
108
+ header.writeUint8(0, 2);
109
+ header.writeUint8(1, 3);
110
+ header.writeUint8(routingInfo.byteLength >> 16, 4);
111
+ header.writeUint16BE(routingInfo.byteLength & 65535, 5);
112
+ header = Buffer.concat([header, routingInfo, NOISE_HEADER]);
113
+ }
114
+ else {
115
+ header = Buffer.from(NOISE_HEADER);
116
+ }
117
+ const introSize = sentIntro ? 0 : header.length;
105
118
  const frame = Buffer.alloc(introSize + 3 + data.byteLength);
106
119
  if (!sentIntro) {
107
- frame.set(NOISE_HEADER);
120
+ frame.set(header);
108
121
  sentIntro = true;
109
122
  }
110
123
  frame.writeUInt8(data.byteLength >> 16, introSize);
@@ -112,7 +125,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
112
125
  frame.set(data, introSize + 3);
113
126
  return frame;
114
127
  },
115
- decodeFrame: (newData, onFrame) => {
128
+ decodeFrame: async (newData, onFrame) => {
116
129
  var _a;
117
130
  // the binary protocol uses its own framing mechanism
118
131
  // on top of the WS frames
@@ -130,7 +143,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
130
143
  inBytes = inBytes.slice(size + 3);
131
144
  if (isFinished) {
132
145
  const result = decrypt(frame);
133
- frame = (0, WABinary_1.decodeBinaryNode)(result);
146
+ frame = await (0, WABinary_1.decodeBinaryNode)(result);
134
147
  }
135
148
  logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
136
149
  onFrame(frame);
@@ -1,9 +1,10 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import type { Logger } from 'pino';
3
3
  import { proto } from '../../WAProto';
4
- import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
4
+ import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
5
5
  type ProcessMessageContext = {
6
6
  shouldProcessHistoryMsg: boolean;
7
+ placeholderResendCache?: CacheStore;
7
8
  creds: AuthenticationCreds;
8
9
  keyStore: SignalKeyStoreWithTransaction;
9
10
  ev: BaileysEventEmitter;
@@ -37,5 +38,5 @@ type PollContext = {
37
38
  * @returns list of SHA256 options
38
39
  */
39
40
  export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
40
- declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
41
+ declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
41
42
  export default processMessage;
@@ -102,8 +102,8 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
102
102
  }
103
103
  }
104
104
  exports.decryptPollVote = decryptPollVote;
105
- const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
106
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
105
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
106
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
107
107
  const meId = creds.me.id;
108
108
  const { accountSettings } = creds;
109
109
  const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
@@ -137,14 +137,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
137
137
  isLatest,
138
138
  }, 'got history notification');
139
139
  if (process) {
140
- ev.emit('creds.update', {
141
- processedHistoryMessages: [
142
- ...(creds.processedHistoryMessages || []),
143
- { key: message.key, messageTimestamp: message.messageTimestamp }
144
- ]
145
- });
140
+ if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
141
+ ev.emit('creds.update', {
142
+ processedHistoryMessages: [
143
+ ...(creds.processedHistoryMessages || []),
144
+ { key: message.key, messageTimestamp: message.messageTimestamp }
145
+ ]
146
+ });
147
+ }
146
148
  const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
147
- ev.emit('messaging-history.set', { ...data, isLatest });
149
+ ev.emit('messaging-history.set', {
150
+ ...data,
151
+ isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
152
+ ? isLatest
153
+ : undefined
154
+ });
148
155
  }
149
156
  break;
150
157
  case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
@@ -187,14 +194,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
187
194
  case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
188
195
  const response = protocolMsg.peerDataOperationRequestResponseMessage;
189
196
  if (response) {
197
+ placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
198
+ // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
190
199
  const { peerDataOperationResult } = response;
191
200
  for (const result of peerDataOperationResult) {
192
201
  const { placeholderMessageResendResponse: retryResponse } = result;
193
202
  if (retryResponse) {
194
203
  const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
195
- ev.emit('messages.update', [
196
- { key: webMessageInfo.key, update: { message: webMessageInfo.message } }
197
- ]);
204
+ // wait till another upsert event is available, don't want it to be part of the PDO response message
205
+ setTimeout(() => {
206
+ ev.emit('messages.upsert', {
207
+ messages: [webMessageInfo],
208
+ type: 'notify',
209
+ requestId: response.stanzaId
210
+ });
211
+ }, 500);
198
212
  }
199
213
  }
200
214
  }
@@ -208,11 +222,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
208
222
  };
209
223
  ev.emit('messages.reaction', [{
210
224
  reaction,
211
- key: content.reactionMessage.key,
225
+ key: (_d = content.reactionMessage) === null || _d === void 0 ? void 0 : _d.key,
212
226
  }]);
213
227
  }
214
228
  else if (message.messageStubType) {
215
- const jid = message.key.remoteJid;
229
+ const jid = (_e = message.key) === null || _e === void 0 ? void 0 : _e.remoteJid;
216
230
  //let actor = whatsappID (message.participant)
217
231
  let participants;
218
232
  const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
@@ -220,8 +234,15 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
220
234
  var _a;
221
235
  ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
222
236
  };
237
+ const emitGroupRequestJoin = (participant, action, method) => {
238
+ ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
239
+ };
223
240
  const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
224
241
  switch (message.messageStubType) {
242
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
243
+ participants = message.messageStubParameters || [];
244
+ emitParticipantsUpdate('modify');
245
+ break;
225
246
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
226
247
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
227
248
  participants = message.messageStubParameters || [];
@@ -249,30 +270,41 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
249
270
  emitParticipantsUpdate('promote');
250
271
  break;
251
272
  case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
252
- const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
273
+ const announceValue = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
253
274
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
254
275
  break;
255
276
  case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
256
- const restrictValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
277
+ const restrictValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
257
278
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
258
279
  break;
259
280
  case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
260
- const name = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
281
+ const name = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
261
282
  chat.name = name;
262
283
  emitGroupUpdate({ subject: name });
263
284
  break;
285
+ case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
286
+ const description = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
287
+ chat.description = description;
288
+ emitGroupUpdate({ desc: description });
289
+ break;
264
290
  case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
265
- const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
291
+ const code = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
266
292
  emitGroupUpdate({ inviteCode: code });
267
293
  break;
268
294
  case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
269
- const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
295
+ const memberAddValue = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
270
296
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
271
297
  break;
272
298
  case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
273
- const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
299
+ const approvalMode = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
274
300
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
275
301
  break;
302
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
303
+ const participant = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
304
+ const action = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[1];
305
+ const method = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[2];
306
+ emitGroupRequestJoin(participant, action, method);
307
+ break;
276
308
  }
277
309
  }
278
310
  else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
@@ -283,7 +315,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
283
315
  const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
284
316
  const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
285
317
  const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
286
- const pollEncKey = (_k = pollMsg.messageContextInfo) === null || _k === void 0 ? void 0 : _k.messageSecret;
318
+ const pollEncKey = (_r = pollMsg.messageContextInfo) === null || _r === void 0 ? void 0 : _r.messageSecret;
287
319
  try {
288
320
  const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
289
321
  pollEncKey,
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  const Defaults_1 = require("../Defaults");
5
6
  const WABinary_1 = require("../WABinary");
6
7
  const crypto_1 = require("./crypto");
@@ -66,22 +67,26 @@ const parseAndInjectE2ESessions = async (node, repository) => {
66
67
  for (const node of nodes) {
67
68
  (0, WABinary_1.assertNodeErrorFree)(node);
68
69
  }
69
- await Promise.all(nodes.map(async (node) => {
70
- const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
71
- const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
72
- const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
73
- const jid = node.attrs.jid;
74
- const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
75
- await repository.injectE2ESession({
76
- jid,
77
- session: {
78
- registrationId: registrationId,
79
- identityKey: (0, crypto_1.generateSignalPubKey)(identity),
80
- signedPreKey: extractKey(signedKey),
81
- preKey: extractKey(key)
82
- }
83
- });
84
- }));
70
+ const chunkSize = 100;
71
+ const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
72
+ for (const nodesChunk of chunks) {
73
+ await Promise.all(nodesChunk.map(async (node) => {
74
+ const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
75
+ const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
76
+ const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
77
+ const jid = node.attrs.jid;
78
+ const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
79
+ await repository.injectE2ESession({
80
+ jid,
81
+ session: {
82
+ registrationId: registrationId,
83
+ identityKey: (0, crypto_1.generateSignalPubKey)(identity),
84
+ signedPreKey: extractKey(signedKey),
85
+ preKey: extractKey(key)
86
+ }
87
+ });
88
+ }));
89
+ }
85
90
  };
86
91
  exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
87
92
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.useMultiFileAuthState = void 0;
7
+ const async_lock_1 = __importDefault(require("async-lock"));
4
8
  const promises_1 = require("fs/promises");
5
9
  const path_1 = require("path");
6
10
  const WAProto_1 = require("../../WAProto");
7
11
  const auth_utils_1 = require("./auth-utils");
8
12
  const generics_1 = require("./generics");
13
+ // We need to lock files due to the fact that we are using async functions to read and write files
14
+ // https://github.com/WhiskeySockets/Baileys/issues/794
15
+ // https://github.com/nodejs/node/issues/26338
16
+ // Default pending is 1000, set it to infinity
17
+ // https://github.com/rogierschouten/async-lock/issues/63
18
+ const fileLock = new async_lock_1.default({ maxPending: Infinity });
9
19
  /**
10
20
  * stores the full authentication state in a single folder.
11
21
  * Far more efficient than singlefileauthstate
@@ -15,11 +25,13 @@ const generics_1 = require("./generics");
15
25
  * */
16
26
  const useMultiFileAuthState = async (folder) => {
17
27
  const writeData = (data, file) => {
18
- return (0, promises_1.writeFile)((0, path_1.join)(folder, fixFileName(file)), JSON.stringify(data, generics_1.BufferJSON.replacer));
28
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
29
+ return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
19
30
  };
20
31
  const readData = async (file) => {
21
32
  try {
22
- const data = await (0, promises_1.readFile)((0, path_1.join)(folder, fixFileName(file)), { encoding: 'utf-8' });
33
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
34
+ const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
23
35
  return JSON.parse(data, generics_1.BufferJSON.reviver);
24
36
  }
25
37
  catch (error) {
@@ -28,7 +40,8 @@ const useMultiFileAuthState = async (folder) => {
28
40
  };
29
41
  const removeData = async (file) => {
30
42
  try {
31
- await (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
43
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
44
+ await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
32
45
  }
33
46
  catch (_a) {
34
47
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- export declare const decompressingIfRequired: (buffer: Buffer) => Buffer;
3
+ export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer>;
4
4
  export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
5
5
  index: number;
6
6
  }) => BinaryNode;
7
- export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
7
+ export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
@@ -24,12 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
27
+ const util_1 = require("util");
27
28
  const zlib_1 = require("zlib");
28
29
  const constants = __importStar(require("./constants"));
29
30
  const jid_utils_1 = require("./jid-utils");
30
- const decompressingIfRequired = (buffer) => {
31
+ const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
32
+ const decompressingIfRequired = async (buffer) => {
31
33
  if (2 & buffer.readUInt8()) {
32
- buffer = (0, zlib_1.inflateSync)(buffer.slice(1));
34
+ buffer = await inflatePromise(buffer.slice(1));
33
35
  }
34
36
  else { // nodes with no compression have a 0x00 prefix, we remove that
35
37
  buffer = buffer.slice(1);
@@ -245,8 +247,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
245
247
  };
246
248
  };
247
249
  exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
248
- const decodeBinaryNode = (buff) => {
249
- const decompBuff = (0, exports.decompressingIfRequired)(buff);
250
+ const decodeBinaryNode = async (buff) => {
251
+ const decompBuff = await (0, exports.decompressingIfRequired)(buff);
250
252
  return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
251
253
  };
252
254
  exports.decodeBinaryNode = decodeBinaryNode;
@@ -1,3 +1,2 @@
1
- /// <reference types="node" />
2
1
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
2
+ export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => number[];
@@ -223,6 +223,6 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
223
223
  else {
224
224
  throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
225
225
  }
226
- return Buffer.from(buffer);
226
+ return buffer;
227
227
  };
228
228
  exports.encodeBinaryNode = encodeBinaryNode;
@@ -3,7 +3,7 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
3
  export declare const SERVER_JID = "server@c.us";
4
4
  export declare const PSA_WID = "0@c.us";
5
5
  export declare const STORIES_JID = "status@broadcast";
6
- export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid';
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
7
7
  export type JidWithDevice = {
8
8
  user: string;
9
9
  device?: number;
@@ -26,4 +26,6 @@ export declare const isJidBroadcast: (jid: string | undefined) => boolean | unde
26
26
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
27
  /** is the jid the status broadcast */
28
28
  export declare const isJidStatusBroadcast: (jid: string) => boolean;
29
+ /** is the jid a newsletter */
30
+ export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
29
31
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
@@ -48,6 +48,9 @@ exports.isJidGroup = isJidGroup;
48
48
  /** is the jid the status broadcast */
49
49
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
50
50
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
51
+ /** is the jid a newsletter */
52
+ const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
53
+ exports.isJidNewsletter = isJidNewsletter;
51
54
  const jidNormalizedUser = (jid) => {
52
55
  const result = (0, exports.jidDecode)(jid);
53
56
  if (!result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "6.9.2",
3
+ "version": "7.0.0",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -43,41 +43,46 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@adiwajshing/keyed-db": "^0.2.4",
46
- "@hapi/boom": "^9.1.3",
47
- "@queenanya/pkg": "latest",
48
- "audio-decode": "^2.1.3",
49
- "axios": "^1.3.3",
46
+ "@hapi/boom": "^10.0.1",
47
+ "@queenanya/invite": "latest",
48
+ "async-lock": "^1.4.1",
49
+ "audio-decode": "^2.2.0",
50
+ "axios": "^1.7.2",
50
51
  "cache-manager": "4.0.1",
51
- "futoin-hkdf": "^1.5.1",
52
+ "futoin-hkdf": "^1.5.3",
52
53
  "json": "^11.0.0",
53
- "libphonenumber-js": "^1.10.20",
54
+ "libphonenumber-js": "^1.11.4",
54
55
  "libsignal": "npm:@queenanya/libsignal@latest",
56
+ "lodash": "^4.17.21",
57
+ "megajs": "1.1.7",
55
58
  "music-metadata": "^7.12.3",
56
59
  "node-cache": "^5.1.2",
57
- "pino": "^7.0.0",
58
- "protobufjs": "^7.2.4",
59
- "uuid": "^9.0.0",
60
- "ws": "^8.13.0"
60
+ "pino": "^9.3.0",
61
+ "protobufjs": "^7.3.2",
62
+ "release-it": "^17.6.0",
63
+ "uuid": "^10.0.0",
64
+ "ws": "^8.18.0"
61
65
  },
62
66
  "devDependencies": {
63
67
  "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
64
- "@types/got": "^9.6.11",
65
- "@types/jest": "^27.5.1",
66
- "@types/node": "^16.0.0",
67
- "@types/sharp": "^0.29.4",
68
- "@types/ws": "^8.0.0",
69
- "conventional-changelog-cli": "^2.2.2",
70
- "eslint": "^8.0.0",
71
- "jest": "^27.0.6",
72
- "jimp": "^0.16.1",
68
+ "@types/got": "^9.6.12",
69
+ "@types/jest": "^29.5.12",
70
+ "@types/node": "^20.14.10",
71
+ "@types/sharp": "^0.31.1",
72
+ "@types/ws": "^8.5.11",
73
+ "conventional-changelog-cli": "^5.0.0",
74
+ "eslint": "^9.7.0",
75
+ "jest": "^29.7.0",
76
+ "jimp": "^0.22.12",
73
77
  "json": "^11.0.0",
74
- "link-preview-js": "^3.0.0",
75
- "open": "^8.4.2",
78
+ "link-preview-js": "^3.0.5",
79
+ "megajs": "1.1.7",
80
+ "open": "^10.1.0",
76
81
  "qrcode-terminal": "^0.12.0",
77
- "release-it": "^15.10.3",
78
- "sharp": "^0.30.5",
79
- "ts-jest": "^27.0.3",
80
- "ts-node": "^10.8.1",
82
+ "release-it": "^17.6.0",
83
+ "sharp": "^0.33.4",
84
+ "ts-jest": "^29.2.2",
85
+ "ts-node": "^10.9.2",
81
86
  "typedoc": "^0.24.7",
82
87
  "typescript": "^4.6.4"
83
88
  },
@@ -85,7 +90,7 @@
85
90
  "jimp": "^0.16.1",
86
91
  "link-preview-js": "^3.0.0",
87
92
  "qrcode-terminal": "^0.12.0",
88
- "sharp": "^0.32.2"
93
+ "sharp": "^0.32.6"
89
94
  },
90
95
  "peerDependenciesMeta": {
91
96
  "jimp": {