@queenanya/baileys 7.4.0 → 7.4.3

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 (63) hide show
  1. package/README.md +0 -10
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.d.ts +0 -231
  4. package/lib/Defaults/index.js +3 -18
  5. package/lib/Socket/Client/index.d.ts +2 -3
  6. package/lib/Socket/Client/index.js +2 -3
  7. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  8. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  9. package/lib/Socket/business.d.ts +1 -1
  10. package/lib/Socket/chats.d.ts +2 -2
  11. package/lib/Socket/chats.js +5 -6
  12. package/lib/Socket/groups.d.ts +1 -7
  13. package/lib/Socket/index.d.ts +10 -12
  14. package/lib/Socket/index.js +2 -2
  15. package/lib/Socket/messages-recv.d.ts +2 -2
  16. package/lib/Socket/messages-recv.js +3 -6
  17. package/lib/Socket/messages-send.d.ts +1 -1
  18. package/lib/Socket/messages-send.js +23 -8
  19. package/lib/Socket/newsletter.d.ts +1 -1
  20. package/lib/Socket/socket.d.ts +2 -1
  21. package/lib/Socket/socket.js +9 -14
  22. package/lib/Store/make-in-memory-store.js +8 -10
  23. package/lib/Store/make-ordered-dictionary.js +2 -2
  24. package/lib/Types/Auth.d.ts +0 -6
  25. package/lib/Types/Chat.d.ts +7 -7
  26. package/lib/Types/Contact.d.ts +1 -1
  27. package/lib/Types/Message.d.ts +4 -2
  28. package/lib/Types/Socket.d.ts +3 -3
  29. package/lib/Utils/auth-utils.js +1 -7
  30. package/lib/Utils/chat-utils.d.ts +4 -4
  31. package/lib/Utils/chat-utils.js +25 -20
  32. package/lib/Utils/decode-wa-message.js +14 -3
  33. package/lib/Utils/event-buffer.js +7 -7
  34. package/lib/Utils/generics.d.ts +8 -4
  35. package/lib/Utils/generics.js +33 -6
  36. package/lib/Utils/history.d.ts +2 -2
  37. package/lib/Utils/link-preview.js +24 -1
  38. package/lib/Utils/make-mutex.js +1 -0
  39. package/lib/Utils/messages-media.d.ts +1 -1
  40. package/lib/Utils/messages-media.js +9 -16
  41. package/lib/Utils/messages.js +7 -11
  42. package/lib/Utils/noise-handler.d.ts +1 -2
  43. package/lib/Utils/noise-handler.js +5 -10
  44. package/lib/Utils/process-message.js +1 -0
  45. package/lib/Utils/signal.js +2 -0
  46. package/lib/Utils/use-multi-file-auth-state.js +1 -0
  47. package/lib/Utils/validate-connection.d.ts +0 -1
  48. package/lib/Utils/validate-connection.js +10 -44
  49. package/lib/WABinary/constants.js +5 -5
  50. package/lib/WABinary/encode.js +7 -5
  51. package/lib/WABinary/jid-utils.d.ts +1 -1
  52. package/lib/WABinary/jid-utils.js +1 -1
  53. package/lib/WAM/BinaryInfo.d.ts +2 -2
  54. package/lib/WAM/constants.d.ts +3 -2
  55. package/lib/WAM/encode.js +2 -2
  56. package/package.json +18 -21
  57. package/lib/Defaults/phonenumber-mcc.json +0 -223
  58. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  59. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  60. package/lib/Socket/registration.d.ts +0 -271
  61. package/lib/Socket/registration.js +0 -166
  62. /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
  63. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -3,6 +3,7 @@
3
3
  import { Boom } from '@hapi/boom';
4
4
  import { SocketConfig } from '../Types';
5
5
  import { BinaryNode } from '../WABinary';
6
+ import { WebSocketClient } from './Client';
6
7
  /**
7
8
  * Connects to WA servers and performs:
8
9
  * - simple queries (no retry mechanism, wait for connection establishment)
@@ -11,7 +12,7 @@ import { BinaryNode } from '../WABinary';
11
12
  */
12
13
  export declare const makeSocket: (config: SocketConfig) => {
13
14
  type: "md";
14
- ws: any;
15
+ ws: WebSocketClient;
15
16
  ev: import("../Types").BaileysEventEmitter & {
16
17
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
17
18
  buffer(): void;
@@ -20,15 +20,14 @@ 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', { statusCode: Types_1.DisconnectReason.loggedOut });
27
26
  }
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)) {
27
+ if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
29
28
  url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
30
29
  }
31
- const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
30
+ const ws = new Client_1.WebSocketClient(url, config);
32
31
  ws.connect();
33
32
  const ev = (0, Utils_1.makeEventBuffer)(logger);
34
33
  /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
@@ -36,8 +35,7 @@ const makeSocket = (config) => {
36
35
  /** WA noise protocol wrapper */
37
36
  const noise = (0, Utils_1.makeNoiseHandler)({
38
37
  keyPair: ephemeralKeyPair,
39
- NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
40
- mobile: config.mobile,
38
+ NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
41
39
  logger,
42
40
  routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
43
41
  });
@@ -160,10 +158,7 @@ const makeSocket = (config) => {
160
158
  logger.trace({ handshake }, 'handshake recv from WA');
161
159
  const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
162
160
  let node;
163
- if (config.mobile) {
164
- node = (0, Utils_1.generateMobileNode)(config);
165
- }
166
- else if (!creds.me) {
161
+ if (!creds.me) {
167
162
  node = (0, Utils_1.generateRegistrationNode)(creds, config);
168
163
  logger.info({ node }, 'not logged in, attempting registration...');
169
164
  }
@@ -233,11 +228,11 @@ const makeSocket = (config) => {
233
228
  const l0 = frame.tag;
234
229
  const l1 = frame.attrs || {};
235
230
  const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
236
- Object.keys(l1).forEach(key => {
231
+ for (const key of Object.keys(l1)) {
237
232
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
238
233
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
239
234
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
240
- });
235
+ }
241
236
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
242
237
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
243
238
  if (!anyTriggered && logger.level === 'debug') {
@@ -182,16 +182,14 @@ exports.default = (config) => {
182
182
  const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
183
183
  const list = assertMessageList(jid);
184
184
  list.upsert(msg, 'append');
185
- if (type === 'notify') {
186
- if (!chats.get(jid)) {
187
- ev.emit('chats.upsert', [
188
- {
189
- id: jid,
190
- conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
191
- unreadCount: 1
192
- }
193
- ]);
194
- }
185
+ if (type === 'notify' && !chats.get(jid)) {
186
+ ev.emit('chats.upsert', [
187
+ {
188
+ id: jid,
189
+ conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
190
+ unreadCount: 1
191
+ }
192
+ ]);
195
193
  }
196
194
  }
197
195
  break;
@@ -56,9 +56,9 @@ function makeOrderedDictionary(idGetter) {
56
56
  },
57
57
  clear: () => {
58
58
  array.splice(0, array.length);
59
- Object.keys(dict).forEach(key => {
59
+ for (const key of Object.keys(dict)) {
60
60
  delete dict[key];
61
- });
61
+ }
62
62
  },
63
63
  filter: (contain) => {
64
64
  let i = 0;
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import type { proto } from '../../WAProto';
4
- import { RegistrationOptions } from '../Socket/registration';
5
4
  import type { Contact } from './Contact';
6
5
  import type { MinimalMessage } from './Message';
7
6
  export type KeyPair = {
@@ -58,12 +57,7 @@ export type AuthenticationCreds = SignalCreds & {
58
57
  /** number of times history & app state has been synced */
59
58
  accountSyncCounter: number;
60
59
  accountSettings: AccountSettings;
61
- deviceId: string;
62
- phoneId: string;
63
- identityId: Buffer;
64
60
  registered: boolean;
65
- backupToken: Buffer;
66
- registration: RegistrationOptions;
67
61
  pairingCode: string | undefined;
68
62
  lastPropHash: string | undefined;
69
63
  routingInfo: Buffer | undefined;
@@ -3,7 +3,7 @@ import type { AccountSettings } from './Auth';
3
3
  import type { BufferedEventData } from './Events';
4
4
  import type { ChatLabelAssociationActionBody } from './LabelAssociation';
5
5
  import type { MessageLabelAssociationActionBody } from './LabelAssociation';
6
- import type { MinimalMessage } from './Message';
6
+ import type { MinimalMessage, WAMessageKey } from './Message';
7
7
  import type { LabelActionBody } from './Label';
8
8
  /** privacy settings in WhatsApp Web */
9
9
  export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
@@ -62,12 +62,12 @@ export type ChatModification = {
62
62
  /** mute for duration, or provide timestamp of mute to remove*/
63
63
  mute: number | null;
64
64
  } | {
65
- clear: 'all' | {
66
- messages: {
67
- id: string;
68
- fromMe?: boolean;
69
- timestamp: number;
70
- }[];
65
+ clear: boolean;
66
+ } | {
67
+ deleteForMe: {
68
+ deleteMedia: boolean;
69
+ key: WAMessageKey;
70
+ timestamp: number;
71
71
  };
72
72
  } | {
73
73
  star: {
@@ -14,6 +14,6 @@ export interface Contact {
14
14
  * null => if the profile picture has not been set (default profile picture)
15
15
  * any other string => url of the profile picture
16
16
  */
17
- imgUrl?: string | null | 'changed';
17
+ imgUrl?: string | null;
18
18
  status?: string;
19
19
  }
@@ -25,11 +25,13 @@ export type WALocationMessage = proto.Message.ILocationMessage;
25
25
  export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
26
26
  export import WAMessageStubType = proto.WebMessageInfo.StubType;
27
27
  export import WAMessageStatus = proto.WebMessageInfo.Status;
28
- export type WAMediaUpload = Buffer | {
28
+ export type WAMediaPayloadURL = {
29
29
  url: URL | string;
30
- } | {
30
+ };
31
+ export type WAMediaPayloadStream = {
31
32
  stream: Readable;
32
33
  };
34
+ export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL;
33
35
  /** Set of message types that are supported by the library */
34
36
  export type MessageType = keyof proto.Message;
35
37
  export type DownloadableMessage = {
@@ -30,7 +30,9 @@ export type SocketConfig = {
30
30
  defaultQueryTimeoutMs: number | undefined;
31
31
  /** ping-pong interval for WS connection */
32
32
  keepAliveIntervalMs: number;
33
- /** should baileys use the mobile api instead of the multi device api */
33
+ /** should baileys use the mobile api instead of the multi device api
34
+ * @deprecated This feature has been removed
35
+ */
34
36
  mobile?: boolean;
35
37
  /** proxy agent */
36
38
  agent?: Agent;
@@ -113,6 +115,4 @@ export type SocketConfig = {
113
115
  /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
114
116
  cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
115
117
  makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
116
- /** Socket passthrough */
117
- socket?: any;
118
118
  };
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
7
7
  const crypto_1 = require("crypto");
8
8
  const node_cache_1 = __importDefault(require("node-cache"));
9
- const uuid_1 = require("uuid");
10
9
  const Defaults_1 = require("../Defaults");
11
10
  const crypto_2 = require("./crypto");
12
11
  const generics_1 = require("./generics");
@@ -143,6 +142,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
143
142
  let tries = maxCommitRetries;
144
143
  while (tries) {
145
144
  tries -= 1;
145
+ //eslint-disable-next-line max-depth
146
146
  try {
147
147
  await state.set(mutations);
148
148
  logger.trace({ dbQueriesInTransaction }, 'committed transaction');
@@ -191,13 +191,7 @@ const initAuthCreds = () => {
191
191
  accountSettings: {
192
192
  unarchiveChats: false
193
193
  },
194
- // mobile creds
195
- deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
196
- phoneId: (0, uuid_1.v4)(),
197
- identityId: (0, crypto_1.randomBytes)(20),
198
194
  registered: false,
199
- backupToken: (0, crypto_1.randomBytes)(20),
200
- registration: {},
201
195
  pairingCode: undefined,
202
196
  lastPropHash: undefined,
203
197
  routingInfo: undefined,
@@ -30,7 +30,7 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
30
30
  };
31
31
  };
32
32
  }>;
33
- export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
33
+ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
34
34
  critical_block: {
35
35
  patches: proto.ISyncdPatch[];
36
36
  hasMorePatches: boolean;
@@ -57,13 +57,13 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
57
57
  snapshot?: proto.ISyncdSnapshot | undefined;
58
58
  };
59
59
  }>;
60
- export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer>;
61
- export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
60
+ export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>;
61
+ export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
62
62
  export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
63
63
  state: LTHashState;
64
64
  mutationMap: ChatMutationMap;
65
65
  }>;
66
- export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
66
+ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
67
67
  state: LTHashState;
68
68
  mutationMap: ChatMutationMap;
69
69
  }>;
@@ -305,8 +305,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
305
305
  indexValueMap: { ...initial.indexValueMap }
306
306
  };
307
307
  const mutationMap = {};
308
- for (let i = 0; i < syncds.length; i++) {
309
- const syncd = syncds[i];
308
+ for (const syncd of syncds) {
310
309
  const { version, keyId, snapshotMac } = syncd;
311
310
  if (syncd.externalMutations) {
312
311
  logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
@@ -418,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
418
417
  operation: OP.SET
419
418
  };
420
419
  }
420
+ else if ('deleteForMe' in mod) {
421
+ const { timestamp, key, deleteMedia } = mod.deleteForMe;
422
+ patch = {
423
+ syncAction: {
424
+ deleteMessageForMeAction: {
425
+ deleteMedia,
426
+ messageTimestamp: timestamp
427
+ }
428
+ },
429
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
430
+ type: 'regular_high',
431
+ apiVersion: 3,
432
+ operation: OP.SET
433
+ };
434
+ }
421
435
  else if ('clear' in mod) {
422
- if (mod.clear === 'all') {
423
- throw new boom_1.Boom('not supported');
424
- }
425
- else {
426
- const key = mod.clear.messages[0];
427
- patch = {
428
- syncAction: {
429
- deleteMessageForMeAction: {
430
- deleteMedia: false,
431
- messageTimestamp: key.timestamp
432
- }
433
- },
434
- index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
435
- type: 'regular_high',
436
- apiVersion: 3,
437
- operation: OP.SET
438
- };
439
- }
436
+ patch = {
437
+ syncAction: {
438
+ clearChatAction: {} // add message range later
439
+ },
440
+ index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
441
+ type: 'regular_high',
442
+ apiVersion: 6,
443
+ operation: OP.SET
444
+ };
440
445
  }
441
446
  else if ('pin' in mod) {
442
447
  patch = {
@@ -179,9 +179,20 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
179
179
  default:
180
180
  throw new Error(`Unknown e2e type: ${e2eType}`);
181
181
  }
182
- let msg = WAProto_1.proto.Message.decode(tag === 'plaintext' ? msgBuffer : (0, generics_1.unpadRandomMax16)(msgBuffer));
183
- msg = ((_a = msg === null || msg === void 0 ? void 0 : msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
184
- await processSenderKeyDistribution(msg);
182
+ let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer);
183
+ msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
184
+ if (msg.senderKeyDistributionMessage) {
185
+ //eslint-disable-next-line max-depth
186
+ try {
187
+ await repository.processSenderKeyDistributionMessage({
188
+ authorJid: author,
189
+ item: msg.senderKeyDistributionMessage
190
+ });
191
+ }
192
+ catch (err) {
193
+ logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
194
+ }
195
+ }
185
196
  if (fullMessage.message) {
186
197
  Object.assign(fullMessage.message, msg);
187
198
  }
@@ -138,7 +138,9 @@ const makeBufferData = () => {
138
138
  groupUpdates: {}
139
139
  };
140
140
  };
141
- function append(data, historyCache, event, eventData, logger) {
141
+ function append(data, historyCache, event,
142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+ eventData, logger) {
142
144
  var _a, _b, _c;
143
145
  switch (event) {
144
146
  case 'messaging-history.set':
@@ -502,12 +504,10 @@ function consolidateEvents(data) {
502
504
  return map;
503
505
  }
504
506
  function concatChats(a, b) {
505
- if (b.unreadCount === null) {
506
- // neutralize unread counter
507
- if (a.unreadCount < 0) {
508
- a.unreadCount = undefined;
509
- b.unreadCount = undefined;
510
- }
507
+ if (b.unreadCount === null && // neutralize unread counter
508
+ a.unreadCount < 0) {
509
+ a.unreadCount = undefined;
510
+ b.unreadCount = undefined;
511
511
  }
512
512
  if (typeof a.unreadCount === 'number' && typeof b.unreadCount === 'number') {
513
513
  b = { ...b };
@@ -3,7 +3,7 @@
3
3
  import { AxiosRequestConfig } from 'axios';
4
4
  import { Logger } from 'pino';
5
5
  import { proto } from '../../WAProto';
6
- import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, WACallUpdateType, WAVersion } from '../Types';
6
+ import { BaileysEventEmitter, BaileysEventMap, BrowsersMap, ConnectionState, WACallUpdateType, WAVersion } from '../Types';
7
7
  import { BinaryNode } from '../WABinary';
8
8
  /**
9
9
  const COMPANION_PLATFORM_MAP = {
@@ -48,7 +48,7 @@ export declare const generateMessageIDV2: (userId?: string) => string;
48
48
  export declare const generateMessageIDV3: (userId?: string) => string;
49
49
  export declare const generateMessageID: () => string;
50
50
  export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
51
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
51
+ export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
52
52
  export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
53
53
  /**
54
54
  * utility that fetches latest baileys version from the main branch.
@@ -80,7 +80,7 @@ export declare const fetchLatestBaileysVersion2: (options?: AxiosRequestConfig<a
80
80
  * A utility that fetches the latest web version of whatsapp.
81
81
  * Use to ensure your WA connection is always on the latest version
82
82
  */
83
- export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
83
+ export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<{}>) => Promise<{
84
84
  version: WAVersion;
85
85
  isLatest: boolean;
86
86
  error?: undefined;
@@ -111,5 +111,9 @@ export declare const getCodeFromWSError: (error: Error) => number;
111
111
  * @param platform AuthenticationCreds.platform
112
112
  */
113
113
  export declare const isWABusinessPlatform: (platform: string) => boolean;
114
- export declare function trimUndefined(obj: any): any;
114
+ export declare function trimUndefined(obj: {
115
+ [_: string]: any;
116
+ }): {
117
+ [_: string]: any;
118
+ };
115
119
  export declare function bytesToCrockford(buffer: Buffer): string;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -46,12 +69,14 @@ const getPlatformId = (browser) => {
46
69
  };
47
70
  exports.getPlatformId = getPlatformId;
48
71
  exports.BufferJSON = {
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
73
  replacer: (k, value) => {
50
74
  if (Buffer.isBuffer(value) || value instanceof Uint8Array || (value === null || value === void 0 ? void 0 : value.type) === 'Buffer') {
51
75
  return { type: 'Buffer', data: Buffer.from((value === null || value === void 0 ? void 0 : value.data) || value).toString('base64') };
52
76
  }
53
77
  return value;
54
78
  },
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
80
  reviver: (_, value) => {
56
81
  if (typeof value === 'object' && !!value && (value.buffer === true || value.type === 'Buffer')) {
57
82
  const val = value.data || value.value;
@@ -101,7 +126,7 @@ const encodeBigEndian = (e, t = 4) => {
101
126
  return a;
102
127
  };
103
128
  exports.encodeBigEndian = encodeBigEndian;
104
- const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t);
129
+ const toNumber = (t) => ((typeof t === 'object' && t) ? ('toNumber' in t ? t.toNumber() : t.low) : t || 0);
105
130
  exports.toNumber = toNumber;
106
131
  /** unix timestamp of a date in seconds */
107
132
  const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000);
@@ -227,8 +252,7 @@ exports.bindWaitForConnectionUpdate = bindWaitForConnectionUpdate;
227
252
  const printQRIfNecessaryListener = (ev, logger) => {
228
253
  ev.on('connection.update', async ({ qr }) => {
229
254
  if (qr) {
230
- const QR = await import('qrcode-terminal')
231
- .then(m => m.default || m)
255
+ const QR = await Promise.resolve().then(() => __importStar(require('qrcode-terminal'))).then(m => m.default || m)
232
256
  .catch(() => {
233
257
  logger.error('QR code terminal not added as dependency');
234
258
  });
@@ -395,7 +419,9 @@ const getCodeFromWSError = (error) => {
395
419
  statusCode = code;
396
420
  }
397
421
  }
398
- else if (((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
422
+ else if (
423
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
424
+ ((_b = error === null || error === void 0 ? void 0 : error.code) === null || _b === void 0 ? void 0 : _b.startsWith('E'))
399
425
  || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('timed out'))) { // handle ETIMEOUT, ENOTFOUND etc
400
426
  statusCode = 408;
401
427
  }
@@ -410,6 +436,7 @@ const isWABusinessPlatform = (platform) => {
410
436
  return platform === 'smbi' || platform === 'smba';
411
437
  };
412
438
  exports.isWABusinessPlatform = isWABusinessPlatform;
439
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
413
440
  function trimUndefined(obj) {
414
441
  for (const key in obj) {
415
442
  if (typeof obj[key] === 'undefined') {
@@ -424,8 +451,8 @@ function bytesToCrockford(buffer) {
424
451
  let value = 0;
425
452
  let bitCount = 0;
426
453
  const crockford = [];
427
- for (let i = 0; i < buffer.length; i++) {
428
- value = (value << 8) | (buffer[i] & 0xff);
454
+ for (const element of buffer) {
455
+ value = (value << 8) | (element & 0xff);
429
456
  bitCount += 8;
430
457
  while (bitCount >= 5) {
431
458
  crockford.push(CROCKFORD_CHARACTERS.charAt((value >>> (bitCount - 5)) & 31));
@@ -1,7 +1,7 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { proto } from '../../WAProto';
3
3
  import { Chat, Contact } from '../Types';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
4
+ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<proto.HistorySync>;
5
5
  export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
6
  chats: Chat[];
7
7
  contacts: Contact[];
@@ -9,7 +9,7 @@ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
9
9
  syncType: proto.HistorySync.HistorySyncType;
10
10
  progress: number | null | undefined;
11
11
  };
12
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
12
+ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<{}>) => Promise<{
13
13
  chats: Chat[];
14
14
  contacts: Contact[];
15
15
  messages: proto.IWebMessageInfo[];
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.getUrlInfo = void 0;
4
27
  const messages_1 = require("./messages");
@@ -25,7 +48,7 @@ const getUrlInfo = async (text, opts = {
25
48
  // retries
26
49
  const retries = 0;
27
50
  const maxRetry = 5;
28
- const { getLinkPreview } = await import('link-preview-js');
51
+ const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')));
29
52
  let previewLink = text;
30
53
  if (!text.startsWith('https://') && !text.startsWith('http://')) {
31
54
  previewLink = 'https://' + previewLink;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeKeyedMutex = exports.makeMutex = void 0;
4
4
  const makeMutex = () => {
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
6
  let task = Promise.resolve();
6
7
  let taskTimeout;
7
8
  return {
@@ -100,7 +100,7 @@ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaTyp
100
100
  export type MediaDownloadOptions = {
101
101
  startByte?: number;
102
102
  endByte?: number;
103
- options?: AxiosRequestConfig<any>;
103
+ options?: AxiosRequestConfig<{}>;
104
104
  };
105
105
  export declare const getUrlFromDirectPath: (directPath: string) => string;
106
106
  export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;