@vinzsocket/baileys 2.8.30 → 3.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 (102) hide show
  1. package/WAProto/fix-imports.js +7 -16
  2. package/WAProto/index.js +1 -37306
  3. package/lib/Defaults/index.js +37 -33
  4. package/lib/Signal/Group/ciphertext-message.js +6 -2
  5. package/lib/Signal/Group/group-session-builder.js +12 -7
  6. package/lib/Signal/Group/group_cipher.js +18 -13
  7. package/lib/Signal/Group/index.js +77 -12
  8. package/lib/Signal/Group/keyhelper.js +15 -8
  9. package/lib/Signal/Group/queue-job.js +7 -2
  10. package/lib/Signal/Group/sender-chain-key.js +11 -6
  11. package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
  12. package/lib/Signal/Group/sender-key-message.js +14 -9
  13. package/lib/Signal/Group/sender-key-name.js +6 -2
  14. package/lib/Signal/Group/sender-key-record.js +13 -9
  15. package/lib/Signal/Group/sender-key-state.js +10 -6
  16. package/lib/Signal/Group/sender-message-key.js +9 -4
  17. package/lib/Signal/libsignal.js +34 -28
  18. package/lib/Signal/lid-mapping.js +24 -19
  19. package/lib/Socket/Client/index.js +25 -3
  20. package/lib/Socket/Client/types.js +8 -4
  21. package/lib/Socket/Client/websocket.js +16 -11
  22. package/lib/Socket/business.js +38 -34
  23. package/lib/Socket/chats.js +100 -95
  24. package/lib/Socket/communities.js +55 -49
  25. package/lib/Socket/groups.js +56 -51
  26. package/lib/Socket/index.js +9 -6
  27. package/lib/Socket/messages-recv.js +150 -145
  28. package/lib/Socket/messages-send.js +109 -104
  29. package/lib/Socket/mex.js +12 -8
  30. package/lib/Socket/newsletter.js +27 -23
  31. package/lib/Socket/socket.js +111 -107
  32. package/lib/Store/index.js +47 -4
  33. package/lib/Store/make-cache-manager-store.js +17 -11
  34. package/lib/Store/make-in-memory-store.js +31 -29
  35. package/lib/Store/make-ordered-dictionary.js +7 -2
  36. package/lib/Store/object-repository.js +7 -2
  37. package/lib/Types/Auth.js +3 -2
  38. package/lib/Types/Bussines.js +3 -2
  39. package/lib/Types/Call.js +3 -2
  40. package/lib/Types/Chat.js +5 -2
  41. package/lib/Types/Contact.js +3 -2
  42. package/lib/Types/Events.js +1 -2
  43. package/lib/Types/GroupMetadata.js +3 -2
  44. package/lib/Types/Label.js +6 -3
  45. package/lib/Types/LabelAssociation.js +6 -3
  46. package/lib/Types/Message.js +16 -7
  47. package/lib/Types/Newsletter.js +8 -5
  48. package/lib/Types/Product.js +3 -2
  49. package/lib/Types/Signal.js +1 -2
  50. package/lib/Types/Socket.js +2 -3
  51. package/lib/Types/State.js +7 -4
  52. package/lib/Types/USync.js +1 -2
  53. package/lib/Types/index.js +153 -15
  54. package/lib/Utils/auth-utils.js +32 -25
  55. package/lib/Utils/baileys-event-stream.js +21 -15
  56. package/lib/Utils/business.js +71 -61
  57. package/lib/Utils/chat-utils.js +91 -77
  58. package/lib/Utils/crypto.js +54 -32
  59. package/lib/Utils/decode-wa-message.js +46 -39
  60. package/lib/Utils/event-buffer.js +24 -19
  61. package/lib/Utils/extended-messages.js +14 -9
  62. package/lib/Utils/generics.js +100 -64
  63. package/lib/Utils/history.js +30 -23
  64. package/lib/Utils/index.js +234 -22
  65. package/lib/Utils/lid-resolver.js +12 -5
  66. package/lib/Utils/link-preview.js +11 -7
  67. package/lib/Utils/logger.js +8 -4
  68. package/lib/Utils/lt-hash.js +8 -5
  69. package/lib/Utils/make-mutex.js +8 -3
  70. package/lib/Utils/mention.js +12 -4
  71. package/lib/Utils/message-retry-manager.js +10 -6
  72. package/lib/Utils/messages-media.js +127 -95
  73. package/lib/Utils/messages.js +122 -98
  74. package/lib/Utils/noise-handler.js +25 -21
  75. package/lib/Utils/process-message.js +72 -63
  76. package/lib/Utils/signal.js +45 -33
  77. package/lib/Utils/use-multi-file-auth-state.js +24 -20
  78. package/lib/Utils/validate-connection.js +54 -47
  79. package/lib/WABinary/constants.js +9 -6
  80. package/lib/WABinary/decode.js +17 -10
  81. package/lib/WABinary/encode.js +11 -6
  82. package/lib/WABinary/generic-utils.js +31 -17
  83. package/lib/WABinary/index.js +58 -6
  84. package/lib/WABinary/jid-utils.js +36 -20
  85. package/lib/WABinary/types.js +2 -2
  86. package/lib/WAM/BinaryInfo.js +6 -2
  87. package/lib/WAM/constants.js +1 -1
  88. package/lib/WAM/encode.js +16 -12
  89. package/lib/WAM/index.js +36 -4
  90. package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
  91. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
  92. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
  94. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
  95. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
  96. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
  97. package/lib/WAUSync/Protocols/index.js +58 -6
  98. package/lib/WAUSync/USyncQuery.js +21 -17
  99. package/lib/WAUSync/USyncUser.js +6 -2
  100. package/lib/WAUSync/index.js +36 -4
  101. package/lib/index.js +112 -12
  102. package/package.json +8 -6
@@ -1,17 +1,22 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { Boom } from '@hapi/boom';
3
- import { proto } from '../../WAProto/index.js';
4
- import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
5
- import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
6
- import { SyncState } from '../Types/State.js';
7
- import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
8
- import { makeMutex } from '../Utils/make-mutex.js';
9
- import processMessage from '../Utils/process-message.js';
10
- import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
11
- import { USyncQuery, USyncUser } from '../WAUSync/index.js';
12
- import { makeSocket } from './socket.js';
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.makeChatsSocket = void 0;
5
+ var _nodeCache = _interopRequireDefault(require("@cacheable/node-cache"));
6
+ var _boom = require("@hapi/boom");
7
+ var _index = require("../../WAProto/index.js");
8
+ var _index2 = require("../Defaults/index.js");
9
+ var _index3 = require("../Types/index.js");
10
+ var _State = require("../Types/State.js");
11
+ var _index4 = require("../Utils/index.js");
12
+ var _makeMutex = require("../Utils/make-mutex.js");
13
+ var _processMessage = _interopRequireDefault(require("../Utils/process-message.js"));
14
+ var _index5 = require("../WABinary/index.js");
15
+ var _index6 = require("../WAUSync/index.js");
16
+ var _socket = require("./socket.js");
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
18
  const MAX_SYNC_ATTEMPTS = 2;
14
- export const makeChatsSocket = config => {
19
+ const makeChatsSocket = config => {
15
20
  const {
16
21
  logger,
17
22
  markOnlineOnConnect,
@@ -20,7 +25,7 @@ export const makeChatsSocket = config => {
20
25
  shouldIgnoreJid,
21
26
  shouldSyncHistoryMessage
22
27
  } = config;
23
- const sock = makeSocket(config);
28
+ const sock = (0, _socket.makeSocket)(config);
24
29
  const {
25
30
  ev,
26
31
  ws,
@@ -32,13 +37,13 @@ export const makeChatsSocket = config => {
32
37
  onUnexpectedError
33
38
  } = sock;
34
39
  let privacySettings;
35
- let syncState = SyncState.Connecting;
40
+ let syncState = _State.SyncState.Connecting;
36
41
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
37
- const processingMutex = makeMutex();
42
+ const processingMutex = (0, _makeMutex.makeMutex)();
38
43
  // Timeout for AwaitingInitialSync state
39
44
  let awaitingSyncTimeout;
40
- const placeholderResendCache = config.placeholderResendCache || new NodeCache({
41
- stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
45
+ const placeholderResendCache = config.placeholderResendCache || new _nodeCache.default({
46
+ stdTTL: _index2.DEFAULT_CACHE_TTLS.MSG_RETRY,
42
47
  // 1 hour
43
48
  useClones: false
44
49
  });
@@ -60,7 +65,7 @@ export const makeChatsSocket = config => {
60
65
  tag: 'iq',
61
66
  attrs: {
62
67
  xmlns: 'privacy',
63
- to: S_WHATSAPP_NET,
68
+ to: _index5.S_WHATSAPP_NET,
64
69
  type: 'get'
65
70
  },
66
71
  content: [{
@@ -68,7 +73,7 @@ export const makeChatsSocket = config => {
68
73
  attrs: {}
69
74
  }]
70
75
  });
71
- privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
76
+ privacySettings = (0, _index5.reduceBinaryNodeToDictionary)(content?.[0], 'category');
72
77
  }
73
78
  return privacySettings;
74
79
  };
@@ -78,7 +83,7 @@ export const makeChatsSocket = config => {
78
83
  tag: 'iq',
79
84
  attrs: {
80
85
  xmlns: 'privacy',
81
- to: S_WHATSAPP_NET,
86
+ to: _index5.S_WHATSAPP_NET,
82
87
  type: 'set'
83
88
  },
84
89
  content: [{
@@ -123,7 +128,7 @@ export const makeChatsSocket = config => {
123
128
  tag: 'iq',
124
129
  attrs: {
125
130
  xmlns: 'disappearing_mode',
126
- to: S_WHATSAPP_NET,
131
+ to: _index5.S_WHATSAPP_NET,
127
132
  type: 'set'
128
133
  },
129
134
  content: [{
@@ -139,7 +144,7 @@ export const makeChatsSocket = config => {
139
144
  tag: 'iq',
140
145
  attrs: {
141
146
  xmlns: 'bot',
142
- to: S_WHATSAPP_NET,
147
+ to: _index5.S_WHATSAPP_NET,
143
148
  type: 'get'
144
149
  },
145
150
  content: [{
@@ -149,11 +154,11 @@ export const makeChatsSocket = config => {
149
154
  }
150
155
  }]
151
156
  });
152
- const botNode = getBinaryNodeChild(resp, 'bot');
157
+ const botNode = (0, _index5.getBinaryNodeChild)(resp, 'bot');
153
158
  const botList = [];
154
- for (const section of getBinaryNodeChildren(botNode, 'section')) {
159
+ for (const section of (0, _index5.getBinaryNodeChildren)(botNode, 'section')) {
155
160
  if (section.attrs.type === 'all') {
156
- for (const bot of getBinaryNodeChildren(section, 'bot')) {
161
+ for (const bot of (0, _index5.getBinaryNodeChildren)(section, 'bot')) {
157
162
  botList.push({
158
163
  jid: bot.attrs.jid,
159
164
  personaId: bot.attrs['persona_id']
@@ -164,9 +169,9 @@ export const makeChatsSocket = config => {
164
169
  return botList;
165
170
  };
166
171
  const fetchStatus = async (...jids) => {
167
- const usyncQuery = new USyncQuery().withStatusProtocol();
172
+ const usyncQuery = new _index6.USyncQuery().withStatusProtocol();
168
173
  for (const jid of jids) {
169
- usyncQuery.withUser(new USyncUser().withId(jid));
174
+ usyncQuery.withUser(new _index6.USyncUser().withId(jid));
170
175
  }
171
176
  const result = await sock.executeUSyncQuery(usyncQuery);
172
177
  if (result) {
@@ -174,9 +179,9 @@ export const makeChatsSocket = config => {
174
179
  }
175
180
  };
176
181
  const fetchDisappearingDuration = async (...jids) => {
177
- const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
182
+ const usyncQuery = new _index6.USyncQuery().withDisappearingModeProtocol();
178
183
  for (const jid of jids) {
179
- usyncQuery.withUser(new USyncUser().withId(jid));
184
+ usyncQuery.withUser(new _index6.USyncUser().withId(jid));
180
185
  }
181
186
  const result = await sock.executeUSyncQuery(usyncQuery);
182
187
  if (result) {
@@ -187,20 +192,20 @@ export const makeChatsSocket = config => {
187
192
  const updateProfilePicture = async (jid, content, dimensions) => {
188
193
  let targetJid;
189
194
  if (!jid) {
190
- throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
195
+ throw new _boom.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
191
196
  }
192
- if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
193
- targetJid = jidNormalizedUser(jid); // in case it is someone other than us
197
+ if ((0, _index5.jidNormalizedUser)(jid) !== (0, _index5.jidNormalizedUser)(authState.creds.me.id)) {
198
+ targetJid = (0, _index5.jidNormalizedUser)(jid); // in case it is someone other than us
194
199
  } else {
195
200
  targetJid = undefined;
196
201
  }
197
202
  const {
198
203
  img
199
- } = await generateProfilePicture(content, dimensions);
204
+ } = await (0, _index4.generateProfilePicture)(content, dimensions);
200
205
  await query({
201
206
  tag: 'iq',
202
207
  attrs: {
203
- to: S_WHATSAPP_NET,
208
+ to: _index5.S_WHATSAPP_NET,
204
209
  type: 'set',
205
210
  xmlns: 'w:profile:picture',
206
211
  ...(targetJid ? {
@@ -220,17 +225,17 @@ export const makeChatsSocket = config => {
220
225
  const removeProfilePicture = async jid => {
221
226
  let targetJid;
222
227
  if (!jid) {
223
- throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
228
+ throw new _boom.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
224
229
  }
225
- if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
226
- targetJid = jidNormalizedUser(jid); // in case it is someone other than us
230
+ if ((0, _index5.jidNormalizedUser)(jid) !== (0, _index5.jidNormalizedUser)(authState.creds.me.id)) {
231
+ targetJid = (0, _index5.jidNormalizedUser)(jid); // in case it is someone other than us
227
232
  } else {
228
233
  targetJid = undefined;
229
234
  }
230
235
  await query({
231
236
  tag: 'iq',
232
237
  attrs: {
233
- to: S_WHATSAPP_NET,
238
+ to: _index5.S_WHATSAPP_NET,
234
239
  type: 'set',
235
240
  xmlns: 'w:profile:picture',
236
241
  ...(targetJid ? {
@@ -244,7 +249,7 @@ export const makeChatsSocket = config => {
244
249
  await query({
245
250
  tag: 'iq',
246
251
  attrs: {
247
- to: S_WHATSAPP_NET,
252
+ to: _index5.S_WHATSAPP_NET,
248
253
  type: 'set',
249
254
  xmlns: 'status'
250
255
  },
@@ -265,19 +270,19 @@ export const makeChatsSocket = config => {
265
270
  tag: 'iq',
266
271
  attrs: {
267
272
  xmlns: 'blocklist',
268
- to: S_WHATSAPP_NET,
273
+ to: _index5.S_WHATSAPP_NET,
269
274
  type: 'get'
270
275
  }
271
276
  });
272
- const listNode = getBinaryNodeChild(result, 'list');
273
- return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
277
+ const listNode = (0, _index5.getBinaryNodeChild)(result, 'list');
278
+ return (0, _index5.getBinaryNodeChildren)(listNode, 'item').map(n => n.attrs.jid);
274
279
  };
275
280
  const updateBlockStatus = async (jid, action) => {
276
281
  await query({
277
282
  tag: 'iq',
278
283
  attrs: {
279
284
  xmlns: 'blocklist',
280
- to: S_WHATSAPP_NET,
285
+ to: _index5.S_WHATSAPP_NET,
281
286
  type: 'set'
282
287
  },
283
288
  content: [{
@@ -310,16 +315,16 @@ export const makeChatsSocket = config => {
310
315
  }]
311
316
  }]
312
317
  });
313
- const profileNode = getBinaryNodeChild(results, 'business_profile');
314
- const profiles = getBinaryNodeChild(profileNode, 'profile');
318
+ const profileNode = (0, _index5.getBinaryNodeChild)(results, 'business_profile');
319
+ const profiles = (0, _index5.getBinaryNodeChild)(profileNode, 'profile');
315
320
  if (profiles) {
316
- const address = getBinaryNodeChild(profiles, 'address');
317
- const description = getBinaryNodeChild(profiles, 'description');
318
- const website = getBinaryNodeChild(profiles, 'website');
319
- const email = getBinaryNodeChild(profiles, 'email');
320
- const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
321
- const businessHours = getBinaryNodeChild(profiles, 'business_hours');
322
- const businessHoursConfig = businessHours ? getBinaryNodeChildren(businessHours, 'business_hours_config') : undefined;
321
+ const address = (0, _index5.getBinaryNodeChild)(profiles, 'address');
322
+ const description = (0, _index5.getBinaryNodeChild)(profiles, 'description');
323
+ const website = (0, _index5.getBinaryNodeChild)(profiles, 'website');
324
+ const email = (0, _index5.getBinaryNodeChild)(profiles, 'email');
325
+ const category = (0, _index5.getBinaryNodeChild)((0, _index5.getBinaryNodeChild)(profiles, 'categories'), 'category');
326
+ const businessHours = (0, _index5.getBinaryNodeChild)(profiles, 'business_hours');
327
+ const businessHoursConfig = businessHours ? (0, _index5.getBinaryNodeChildren)(businessHours, 'business_hours_config') : undefined;
323
328
  const websiteStr = website?.content?.toString();
324
329
  return {
325
330
  wid: profiles.attrs?.jid,
@@ -344,7 +349,7 @@ export const makeChatsSocket = config => {
344
349
  await sendNode({
345
350
  tag: 'iq',
346
351
  attrs: {
347
- to: S_WHATSAPP_NET,
352
+ to: _index5.S_WHATSAPP_NET,
348
353
  type: 'set',
349
354
  xmlns: 'urn:xmpp:whatsapp:dirty',
350
355
  id: generateMessageTag()
@@ -363,7 +368,7 @@ export const makeChatsSocket = config => {
363
368
  const newAppStateChunkHandler = isInitialSync => {
364
369
  return {
365
370
  onMutation(mutation) {
366
- processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? {
371
+ (0, _index4.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? {
367
372
  accountSettings: authState.creds.accountSettings
368
373
  } : undefined, logger);
369
374
  }
@@ -392,7 +397,7 @@ export const makeChatsSocket = config => {
392
397
  initialVersionMap[name] = state.version;
393
398
  }
394
399
  } else {
395
- state = newLTHashState();
400
+ state = (0, _index4.newLTHashState)();
396
401
  }
397
402
  states[name] = state;
398
403
  logger.info(`resyncing ${name} from v${state.version}`);
@@ -409,7 +414,7 @@ export const makeChatsSocket = config => {
409
414
  const result = await query({
410
415
  tag: 'iq',
411
416
  attrs: {
412
- to: S_WHATSAPP_NET,
417
+ to: _index5.S_WHATSAPP_NET,
413
418
  xmlns: 'w:sync:app:state',
414
419
  type: 'set'
415
420
  },
@@ -420,7 +425,7 @@ export const makeChatsSocket = config => {
420
425
  }]
421
426
  });
422
427
  // extract from binary node
423
- const decoded = await extractSyncdPatches(result, config?.options);
428
+ const decoded = await (0, _index4.extractSyncdPatches)(result, config?.options);
424
429
  for (const key in decoded) {
425
430
  const name = key;
426
431
  const {
@@ -433,7 +438,7 @@ export const makeChatsSocket = config => {
433
438
  const {
434
439
  state: newState,
435
440
  mutationMap
436
- } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
441
+ } = await (0, _index4.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
437
442
  states[name] = newState;
438
443
  Object.assign(globalMutationMap, mutationMap);
439
444
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
@@ -448,7 +453,7 @@ export const makeChatsSocket = config => {
448
453
  const {
449
454
  state: newState,
450
455
  mutationMap
451
- } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
456
+ } = await (0, _index4.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
452
457
  await authState.keys.set({
453
458
  'app-state-sync-version': {
454
459
  [name]: newState
@@ -500,12 +505,12 @@ export const makeChatsSocket = config => {
500
505
  * type = "image for the high res picture"
501
506
  */
502
507
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
503
- jid = jidNormalizedUser(jid);
508
+ jid = (0, _index5.jidNormalizedUser)(jid);
504
509
  const result = await query({
505
510
  tag: 'iq',
506
511
  attrs: {
507
512
  target: jid,
508
- to: S_WHATSAPP_NET,
513
+ to: _index5.S_WHATSAPP_NET,
509
514
  type: 'get',
510
515
  xmlns: 'w:profile:picture'
511
516
  },
@@ -517,7 +522,7 @@ export const makeChatsSocket = config => {
517
522
  }
518
523
  }]
519
524
  }, timeoutMs);
520
- const child = getBinaryNodeChild(result, 'picture');
525
+ const child = (0, _index5.getBinaryNodeChild)(result, 'picture');
521
526
  return child?.attrs?.url;
522
527
  };
523
528
  const createCallLink = async (type, event, timeoutMs) => {
@@ -540,7 +545,7 @@ export const makeChatsSocket = config => {
540
545
  }] : undefined
541
546
  }]
542
547
  }, timeoutMs);
543
- const child = getBinaryNodeChild(result, 'link_create');
548
+ const child = (0, _index5.getBinaryNodeChild)(result, 'link_create');
544
549
  return child?.attrs?.token;
545
550
  };
546
551
  const sendPresenceUpdate = async (type, toJid) => {
@@ -563,7 +568,7 @@ export const makeChatsSocket = config => {
563
568
  } else {
564
569
  const {
565
570
  server
566
- } = jidDecode(toJid);
571
+ } = (0, _index5.jidDecode)(toJid);
567
572
  const isLid = server === 'lid';
568
573
  await sendNode({
569
574
  tag: 'chatstate',
@@ -645,7 +650,7 @@ export const makeChatsSocket = config => {
645
650
  const name = patchCreate.type;
646
651
  const myAppStateKeyId = authState.creds.myAppStateKeyId;
647
652
  if (!myAppStateKeyId) {
648
- throw new Boom('App state key not present!', {
653
+ throw new _boom.Boom('App state key not present!', {
649
654
  statusCode: 400
650
655
  });
651
656
  }
@@ -660,8 +665,8 @@ export const makeChatsSocket = config => {
660
665
  const {
661
666
  [name]: currentSyncVersion
662
667
  } = await authState.keys.get('app-state-sync-version', [name]);
663
- initial = currentSyncVersion || newLTHashState();
664
- encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
668
+ initial = currentSyncVersion || (0, _index4.newLTHashState)();
669
+ encodeResult = await (0, _index4.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
665
670
  const {
666
671
  patch,
667
672
  state
@@ -669,7 +674,7 @@ export const makeChatsSocket = config => {
669
674
  const node = {
670
675
  tag: 'iq',
671
676
  attrs: {
672
- to: S_WHATSAPP_NET,
677
+ to: _index5.S_WHATSAPP_NET,
673
678
  type: 'set',
674
679
  xmlns: 'w:sync:app:state'
675
680
  },
@@ -686,7 +691,7 @@ export const makeChatsSocket = config => {
686
691
  content: [{
687
692
  tag: 'patch',
688
693
  attrs: {},
689
- content: proto.SyncdPatch.encode(patch).finish()
694
+ content: _index.proto.SyncdPatch.encode(patch).finish()
690
695
  }]
691
696
  }]
692
697
  }]
@@ -705,7 +710,7 @@ export const makeChatsSocket = config => {
705
710
  } = newAppStateChunkHandler(false);
706
711
  const {
707
712
  mutationMap
708
- } = await decodePatches(name, [{
713
+ } = await (0, _index4.decodePatches)(name, [{
709
714
  ...encodeResult.patch,
710
715
  version: {
711
716
  version: encodeResult.state.version
@@ -721,7 +726,7 @@ export const makeChatsSocket = config => {
721
726
  const resultNode = await query({
722
727
  tag: 'iq',
723
728
  attrs: {
724
- to: S_WHATSAPP_NET,
729
+ to: _index5.S_WHATSAPP_NET,
725
730
  xmlns: 'w',
726
731
  type: 'get'
727
732
  },
@@ -733,7 +738,7 @@ export const makeChatsSocket = config => {
733
738
  }
734
739
  }]
735
740
  });
736
- const propsNode = getBinaryNodeChild(resultNode, 'props');
741
+ const propsNode = (0, _index5.getBinaryNodeChild)(resultNode, 'props');
737
742
  let props = {};
738
743
  if (propsNode) {
739
744
  if (propsNode.attrs?.hash) {
@@ -741,7 +746,7 @@ export const makeChatsSocket = config => {
741
746
  authState.creds.lastPropHash = propsNode?.attrs?.hash;
742
747
  ev.emit('creds.update', authState.creds);
743
748
  }
744
- props = reduceBinaryNodeToDictionary(propsNode, 'prop');
749
+ props = (0, _index5.reduceBinaryNodeToDictionary)(propsNode, 'prop');
745
750
  }
746
751
  logger.debug('fetched props');
747
752
  return props;
@@ -752,7 +757,7 @@ export const makeChatsSocket = config => {
752
757
  * requires the last messages till the last message received; required for archive & unread
753
758
  */
754
759
  const chatModify = (mod, jid) => {
755
- const patch = chatModificationToAppPatch(mod, jid);
760
+ const patch = (0, _index4.chatModificationToAppPatch)(mod, jid);
756
761
  return appPatch(patch);
757
762
  };
758
763
  /**
@@ -877,7 +882,7 @@ export const makeChatsSocket = config => {
877
882
  });
878
883
  if (!!msg.pushName) {
879
884
  let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
880
- jid = jidNormalizedUser(jid);
885
+ jid = (0, _index5.jidNormalizedUser)(jid);
881
886
  if (!msg.key.fromMe) {
882
887
  ev.emit('contacts.update', [{
883
888
  id: jid,
@@ -895,30 +900,30 @@ export const makeChatsSocket = config => {
895
900
  });
896
901
  }
897
902
  }
898
- const historyMsg = getHistoryMsg(msg.message);
899
- const shouldProcessHistoryMsg = historyMsg ? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType) : false;
903
+ const historyMsg = (0, _index4.getHistoryMsg)(msg.message);
904
+ const shouldProcessHistoryMsg = historyMsg ? shouldSyncHistoryMessage(historyMsg) && _index2.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType) : false;
900
905
  // State machine: decide on sync and flush
901
- if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
906
+ if (historyMsg && syncState === _State.SyncState.AwaitingInitialSync) {
902
907
  if (awaitingSyncTimeout) {
903
908
  clearTimeout(awaitingSyncTimeout);
904
909
  awaitingSyncTimeout = undefined;
905
910
  }
906
911
  if (shouldProcessHistoryMsg) {
907
- syncState = SyncState.Syncing;
912
+ syncState = _State.SyncState.Syncing;
908
913
  logger.info('Transitioned to Syncing state');
909
914
  // Let doAppStateSync handle the final flush after it's done
910
915
  } else {
911
- syncState = SyncState.Online;
916
+ syncState = _State.SyncState.Online;
912
917
  logger.info('History sync skipped, transitioning to Online state and flushing buffer');
913
918
  ev.flush();
914
919
  }
915
920
  }
916
921
  const doAppStateSync = async () => {
917
- if (syncState === SyncState.Syncing) {
922
+ if (syncState === _State.SyncState.Syncing) {
918
923
  logger.info('Doing app state sync');
919
- await resyncAppState(ALL_WA_PATCH_NAMES, true);
924
+ await resyncAppState(_index3.ALL_WA_PATCH_NAMES, true);
920
925
  // Sync is complete, go online and flush everything
921
- syncState = SyncState.Online;
926
+ syncState = _State.SyncState.Online;
922
927
  logger.info('App state sync complete, transitioning to Online state and flushing buffer');
923
928
  ev.flush();
924
929
  const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
@@ -931,7 +936,7 @@ export const makeChatsSocket = config => {
931
936
  if (shouldProcessHistoryMsg) {
932
937
  await doAppStateSync();
933
938
  }
934
- })(), processMessage(msg, {
939
+ })(), (0, _processMessage.default)(msg, {
935
940
  signalRepository,
936
941
  shouldProcessHistoryMsg,
937
942
  placeholderResendCache,
@@ -942,7 +947,7 @@ export const makeChatsSocket = config => {
942
947
  options: config.options
943
948
  })]);
944
949
  // If the app state key arrives and we are waiting to sync, trigger the sync now.
945
- if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
950
+ if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === _State.SyncState.Syncing) {
946
951
  logger.info('App state sync key arrived, triggering app state sync');
947
952
  await doAppStateSync();
948
953
  }
@@ -952,7 +957,7 @@ export const makeChatsSocket = config => {
952
957
  ws.on('CB:ib,,dirty', async node => {
953
958
  const {
954
959
  attrs
955
- } = getBinaryNodeChild(node, 'dirty');
960
+ } = (0, _index5.getBinaryNodeChild)(node, 'dirty');
956
961
  const type = attrs.type;
957
962
  switch (type) {
958
963
  case 'account_sync':
@@ -989,18 +994,18 @@ export const makeChatsSocket = config => {
989
994
  }
990
995
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
991
996
  }
992
- if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
997
+ if (!receivedPendingNotifications || syncState !== _State.SyncState.Connecting) {
993
998
  return;
994
999
  }
995
- syncState = SyncState.AwaitingInitialSync;
1000
+ syncState = _State.SyncState.AwaitingInitialSync;
996
1001
  logger.info('Connection is now AwaitingInitialSync, buffering events');
997
1002
  ev.buffer();
998
- const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.create({
999
- syncType: proto.HistorySync.HistorySyncType.RECENT
1003
+ const willSyncHistory = shouldSyncHistoryMessage(_index.proto.Message.HistorySyncNotification.create({
1004
+ syncType: _index.proto.HistorySync.HistorySyncType.RECENT
1000
1005
  }));
1001
1006
  if (!willSyncHistory) {
1002
1007
  logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
1003
- syncState = SyncState.Online;
1008
+ syncState = _State.SyncState.Online;
1004
1009
  setTimeout(() => ev.flush(), 0);
1005
1010
  return;
1006
1011
  }
@@ -1009,9 +1014,9 @@ export const makeChatsSocket = config => {
1009
1014
  clearTimeout(awaitingSyncTimeout);
1010
1015
  }
1011
1016
  awaitingSyncTimeout = setTimeout(() => {
1012
- if (syncState === SyncState.AwaitingInitialSync) {
1017
+ if (syncState === _State.SyncState.AwaitingInitialSync) {
1013
1018
  logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
1014
- syncState = SyncState.Online;
1019
+ syncState = _State.SyncState.Online;
1015
1020
  ev.flush();
1016
1021
  }
1017
1022
  }, 20000);
@@ -1061,4 +1066,4 @@ export const makeChatsSocket = config => {
1061
1066
  removeQuickReply
1062
1067
  };
1063
1068
  };
1064
- //# sourceMappingURL=chats.js.map
1069
+ exports.makeChatsSocket = makeChatsSocket;