cuki-bailx 1.2.5 → 2.0.7

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 (154) hide show
  1. package/WAProto/AICommon.js +27981 -0
  2. package/WAProto/AICommon.proto +713 -0
  3. package/WAProto/Ephemeral.js +295 -0
  4. package/WAProto/Ephemeral.proto +7 -0
  5. package/WAProto/GenerateStatics.sh +4 -0
  6. package/WAProto/WAProto.proto +4775 -0
  7. package/WAProto/cuki.js +7 -0
  8. package/WAProto/index.js +56886 -17506
  9. package/lib/Defaults/baileys-version.json +2 -2
  10. package/lib/Defaults/index.js +117 -102
  11. package/lib/Socket/Client/index.js +2 -3
  12. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
  13. package/lib/Socket/chats.js +97 -90
  14. package/lib/Socket/groups.js +20 -5
  15. package/lib/Socket/index.js +2 -2
  16. package/lib/Socket/messages-recv.js +9 -65
  17. package/lib/Socket/messages-send.js +612 -286
  18. package/lib/Socket/newsletter.js +68 -41
  19. package/lib/Socket/{dugong.js → setup.js} +5 -13
  20. package/lib/Socket/socket.js +58 -32
  21. package/lib/Store/index.js +1 -3
  22. package/lib/Store/make-in-memory-store.js +26 -14
  23. package/lib/Store/make-ordered-dictionary.js +2 -2
  24. package/lib/Types/Label.js +1 -1
  25. package/lib/Types/LabelAssociation.js +1 -1
  26. package/lib/Types/Message.js +0 -2
  27. package/lib/Types/Newsletter.js +3 -17
  28. package/lib/Types/index.js +2 -2
  29. package/lib/Utils/auth-utils.js +6 -13
  30. package/lib/Utils/business.js +2 -2
  31. package/lib/Utils/chat-utils.js +36 -35
  32. package/lib/Utils/crypto.js +71 -29
  33. package/lib/Utils/decode-wa-message.js +65 -56
  34. package/lib/Utils/event-buffer.js +11 -7
  35. package/lib/Utils/generics.js +73 -23
  36. package/lib/Utils/history.js +4 -6
  37. package/lib/Utils/link-preview.js +34 -1
  38. package/lib/Utils/lt-hash.js +6 -6
  39. package/lib/Utils/messages-media.js +479 -161
  40. package/lib/Utils/messages.js +391 -77
  41. package/lib/Utils/noise-handler.js +19 -23
  42. package/lib/Utils/signal.js +47 -36
  43. package/lib/Utils/use-multi-file-auth-state.js +51 -6
  44. package/lib/Utils/validate-connection.js +94 -66
  45. package/lib/WABinary/constants.js +1276 -13
  46. package/lib/WABinary/decode.js +26 -13
  47. package/lib/WABinary/encode.js +39 -17
  48. package/lib/WABinary/generic-utils.js +2 -85
  49. package/lib/WABinary/jid-utils.js +12 -5
  50. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  51. package/lib/index.js +18 -5
  52. package/package.json +100 -105
  53. package/engine-requirements.js +0 -10
  54. package/lib/Defaults/index.d.ts +0 -53
  55. package/lib/Defaults/phonenumber-mcc.json +0 -223
  56. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  57. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  58. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  59. package/lib/Signal/Group/index.d.ts +0 -11
  60. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  61. package/lib/Signal/Group/queue-job.d.ts +0 -1
  62. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  63. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  64. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  65. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  66. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  67. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  68. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  69. package/lib/Signal/libsignal.d.ts +0 -3
  70. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  71. package/lib/Socket/Client/index.d.ts +0 -3
  72. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  73. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  74. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  75. package/lib/Socket/business.d.ts +0 -171
  76. package/lib/Socket/chats.d.ts +0 -80
  77. package/lib/Socket/dugong.d.ts +0 -219
  78. package/lib/Socket/groups.d.ts +0 -115
  79. package/lib/Socket/index.d.ts +0 -173
  80. package/lib/Socket/messages-recv.d.ts +0 -161
  81. package/lib/Socket/messages-send.d.ts +0 -149
  82. package/lib/Socket/newsletter.d.ts +0 -134
  83. package/lib/Socket/registration.d.ts +0 -267
  84. package/lib/Socket/registration.js +0 -166
  85. package/lib/Socket/socket.d.ts +0 -43
  86. package/lib/Socket/socket.js.bak +0 -630
  87. package/lib/Socket/usync.d.ts +0 -36
  88. package/lib/Store/index.d.ts +0 -3
  89. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  90. package/lib/Store/make-cache-manager-store.js +0 -83
  91. package/lib/Store/make-in-memory-store.d.ts +0 -118
  92. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  93. package/lib/Store/object-repository.d.ts +0 -10
  94. package/lib/Types/Auth.d.ts +0 -110
  95. package/lib/Types/Call.d.ts +0 -13
  96. package/lib/Types/Chat.d.ts +0 -102
  97. package/lib/Types/Contact.d.ts +0 -19
  98. package/lib/Types/Events.d.ts +0 -157
  99. package/lib/Types/GroupMetadata.d.ts +0 -55
  100. package/lib/Types/Label.d.ts +0 -35
  101. package/lib/Types/LabelAssociation.d.ts +0 -29
  102. package/lib/Types/Message.d.ts +0 -273
  103. package/lib/Types/Newsletter.d.ts +0 -92
  104. package/lib/Types/Product.d.ts +0 -78
  105. package/lib/Types/Signal.d.ts +0 -57
  106. package/lib/Types/Socket.d.ts +0 -111
  107. package/lib/Types/State.d.ts +0 -27
  108. package/lib/Types/USync.d.ts +0 -25
  109. package/lib/Types/index.d.ts +0 -57
  110. package/lib/Utils/auth-utils.d.ts +0 -18
  111. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  112. package/lib/Utils/business.d.ts +0 -22
  113. package/lib/Utils/chat-utils.d.ts +0 -71
  114. package/lib/Utils/crypto.d.ts +0 -41
  115. package/lib/Utils/decode-wa-message.d.ts +0 -19
  116. package/lib/Utils/event-buffer.d.ts +0 -35
  117. package/lib/Utils/generics.d.ts +0 -92
  118. package/lib/Utils/history.d.ts +0 -15
  119. package/lib/Utils/index.d.ts +0 -17
  120. package/lib/Utils/link-preview.d.ts +0 -21
  121. package/lib/Utils/logger.d.ts +0 -4
  122. package/lib/Utils/lt-hash.d.ts +0 -12
  123. package/lib/Utils/make-mutex.d.ts +0 -7
  124. package/lib/Utils/messages-media.d.ts +0 -116
  125. package/lib/Utils/messages.d.ts +0 -77
  126. package/lib/Utils/noise-handler.d.ts +0 -21
  127. package/lib/Utils/process-message.d.ts +0 -41
  128. package/lib/Utils/signal.d.ts +0 -32
  129. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  130. package/lib/Utils/validate-connection.d.ts +0 -11
  131. package/lib/WABinary/constants.d.ts +0 -27
  132. package/lib/WABinary/decode.d.ts +0 -7
  133. package/lib/WABinary/encode.d.ts +0 -3
  134. package/lib/WABinary/generic-utils.d.ts +0 -16
  135. package/lib/WABinary/index.d.ts +0 -5
  136. package/lib/WABinary/jid-utils.d.ts +0 -31
  137. package/lib/WABinary/types.d.ts +0 -18
  138. package/lib/WAM/BinaryInfo.d.ts +0 -17
  139. package/lib/WAM/constants.d.ts +0 -38
  140. package/lib/WAM/encode.d.ts +0 -3
  141. package/lib/WAM/index.d.ts +0 -3
  142. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  143. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  144. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  145. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  146. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  147. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  148. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  149. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  150. package/lib/WAUSync/USyncUser.d.ts +0 -12
  151. package/lib/WAUSync/index.d.ts +0 -3
  152. package/lib/index.d.ts +0 -12
  153. package/lib/index.js.bak +0 -48
  154. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeChatsSocket = void 0;
7
7
  const boom_1 = require("@hapi/boom");
8
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
9
  const WAProto_1 = require("../../WAProto");
9
10
  const Defaults_1 = require("../Defaults");
10
11
  const Types_1 = require("../Types");
@@ -12,7 +13,6 @@ const Utils_1 = require("../Utils");
12
13
  const make_mutex_1 = require("../Utils/make-mutex");
13
14
  const process_message_1 = __importDefault(require("../Utils/process-message"));
14
15
  const WABinary_1 = require("../WABinary");
15
- const socket_1 = require("./socket");
16
16
  const WAUSync_1 = require("../WAUSync");
17
17
  const usync_1 = require("./usync");
18
18
  const MAX_SYNC_ATTEMPTS = 2;
@@ -25,6 +25,13 @@ const makeChatsSocket = (config) => {
25
25
  let pendingAppStateSync = false;
26
26
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
27
27
  const processingMutex = (0, make_mutex_1.makeMutex)();
28
+ const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
30
+ useClones: false
31
+ });
32
+ if (!config.placeholderResendCache) {
33
+ config.placeholderResendCache = placeholderResendCache;
34
+ }
28
35
  /** helper function to fetch the given app state sync key */
29
36
  const getAppStateSyncKey = async (keyId) => {
30
37
  const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
@@ -68,6 +75,12 @@ const makeChatsSocket = (config) => {
68
75
  }]
69
76
  });
70
77
  };
78
+ const updateMessagesPrivacy = async (value) => {
79
+ await privacyQuery('messages', value);
80
+ };
81
+ const updateCallPrivacy = async (value) => {
82
+ await privacyQuery('calladd', value);
83
+ };
71
84
  const updateLastSeenPrivacy = async (value) => {
72
85
  await privacyQuery('last', value);
73
86
  };
@@ -102,44 +115,34 @@ const makeChatsSocket = (config) => {
102
115
  }]
103
116
  });
104
117
  };
105
- /** helper function to run a generic IQ query */
106
- const interactiveQuery = async (userNodes, queryNode) => {
107
- const result = await query({
118
+ const getBotListV2 = async () => {
119
+ const resp = await query({
108
120
  tag: 'iq',
109
121
  attrs: {
122
+ xmlns: 'bot',
110
123
  to: WABinary_1.S_WHATSAPP_NET,
111
- type: 'get',
112
- xmlns: 'usync',
124
+ type: 'get'
113
125
  },
114
- content: [
115
- {
116
- tag: 'usync',
126
+ content: [{
127
+ tag: 'bot',
117
128
  attrs: {
118
- sid: generateMessageTag(),
119
- mode: 'query',
120
- last: 'true',
121
- index: '0',
122
- context: 'interactive',
123
- },
124
- content: [
125
- {
126
- tag: 'query',
127
- attrs: {},
128
- content: [queryNode]
129
- },
130
- {
131
- tag: 'list',
132
- attrs: {},
133
- content: userNodes
134
- }
135
- ]
136
- }
137
- ],
129
+ v: '2'
130
+ }
131
+ }]
138
132
  });
139
- const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
140
- const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
141
- const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
142
- return users;
133
+ const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
134
+ const botList = [];
135
+ for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
136
+ if (section.attrs.type === 'all') {
137
+ for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
138
+ botList.push({
139
+ jid: bot.attrs.jid,
140
+ personaId: bot.attrs['persona_id']
141
+ });
142
+ }
143
+ }
144
+ }
145
+ return botList;
143
146
  };
144
147
  const onWhatsApp = async (...jids) => {
145
148
  const usyncQuery = new WAUSync_1.USyncQuery()
@@ -154,14 +157,26 @@ const makeChatsSocket = (config) => {
154
157
  return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
155
158
  }
156
159
  };
157
- const fetchStatus = async (jid) => {
158
- const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
160
+ const fetchStatus = async (...jids) => {
161
+ const usyncQuery = new WAUSync_1.USyncQuery()
162
+ .withStatusProtocol();
163
+ for (const jid of jids) {
164
+ usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
165
+ }
166
+ const result = await sock.executeUSyncQuery(usyncQuery);
159
167
  if (result) {
160
- const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
161
- return {
162
- status: status === null || status === void 0 ? void 0 : status.content.toString(),
163
- setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
164
- };
168
+ return result.list;
169
+ }
170
+ };
171
+ const fetchDisappearingDuration = async (...jids) => {
172
+ const usyncQuery = new WAUSync_1.USyncQuery()
173
+ .withDisappearingModeProtocol();
174
+ for (const jid of jids) {
175
+ usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
176
+ }
177
+ const result = await sock.executeUSyncQuery(usyncQuery);
178
+ if (result) {
179
+ return result.list;
165
180
  }
166
181
  };
167
182
  /** update the profile picture for yourself or a group */
@@ -290,9 +305,9 @@ const makeChatsSocket = (config) => {
290
305
  const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
291
306
  const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
292
307
  const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
293
- const businessHoursConfig = businessHours ?
294
- (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
295
- undefined;
308
+ const businessHoursConfig = businessHours
309
+ ? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
310
+ : undefined;
296
311
  const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
297
312
  return {
298
313
  wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
@@ -401,16 +416,12 @@ const makeChatsSocket = (config) => {
401
416
  states[name] = newState;
402
417
  Object.assign(globalMutationMap, mutationMap);
403
418
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
404
- await authState.keys.set({ 'app-state-sync-version': {
405
- [name]: newState
406
- } });
419
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
407
420
  }
408
421
  // only process if there are syncd patches
409
422
  if (patches.length) {
410
423
  const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
411
- await authState.keys.set({ 'app-state-sync-version': {
412
- [name]: newState
413
- } });
424
+ await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
414
425
  logger.info(`synced ${name} to v${newState.version}`);
415
426
  initialVersionMap[name] = newState.version;
416
427
  Object.assign(globalMutationMap, mutationMap);
@@ -425,13 +436,11 @@ const makeChatsSocket = (config) => {
425
436
  catch (error) {
426
437
  // if retry attempts overshoot
427
438
  // or key not found
428
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
429
- ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
430
- error.name === 'TypeError';
439
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
440
+ || ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
441
+ || error.name === 'TypeError';
431
442
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
432
- await authState.keys.set({ 'app-state-sync-version': {
433
- [name]: null
434
- } });
443
+ await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
435
444
  // increment number of retries
436
445
  attemptsMap[name] = (attemptsMap[name] || 0) + 1;
437
446
  if (isIrrecoverableError) {
@@ -481,7 +490,7 @@ const makeChatsSocket = (config) => {
481
490
  await sendNode({
482
491
  tag: 'presence',
483
492
  attrs: {
484
- name: me.name,
493
+ name: me.name.replace(/@/g, ''),
485
494
  type
486
495
  }
487
496
  });
@@ -515,22 +524,22 @@ const makeChatsSocket = (config) => {
515
524
  id: generateMessageTag(),
516
525
  type: 'subscribe'
517
526
  },
518
- content: tcToken ?
519
- [
527
+ content: tcToken
528
+ ? [
520
529
  {
521
530
  tag: 'tctoken',
522
531
  attrs: {},
523
532
  content: tcToken
524
533
  }
525
- ] :
526
- undefined
534
+ ]
535
+ : undefined
527
536
  }));
528
537
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
529
538
  var _a;
530
539
  let presence;
531
540
  const jid = attrs.from;
532
541
  const participant = attrs.participant || attrs.from;
533
- if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
542
+ if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
534
543
  return;
535
544
  }
536
545
  if (tag === 'presence') {
@@ -554,9 +563,7 @@ const makeChatsSocket = (config) => {
554
563
  logger.error({ tag, attrs, content }, 'recv invalid presence node');
555
564
  }
556
565
  if (presence) {
557
- ev.emit('presence.update', { id: jid, presences: {
558
- [participant]: presence
559
- } });
566
+ ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
560
567
  }
561
568
  };
562
569
  const appPatch = async (patchCreate) => {
@@ -607,9 +614,7 @@ const makeChatsSocket = (config) => {
607
614
  ]
608
615
  };
609
616
  await query(node);
610
- await authState.keys.set({ 'app-state-sync-version': {
611
- [name]: state
612
- } });
617
+ await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
613
618
  });
614
619
  });
615
620
  if (config.emitOwnEvents) {
@@ -622,7 +627,7 @@ const makeChatsSocket = (config) => {
622
627
  };
623
628
  /** sending non-abt props may fix QR scan fail if server expects */
624
629
  const fetchProps = async () => {
625
- var _a, _b;
630
+ var _a, _b, _c;
626
631
  const resultNode = await query({
627
632
  tag: 'iq',
628
633
  attrs: {
@@ -631,20 +636,19 @@ const makeChatsSocket = (config) => {
631
636
  type: 'get',
632
637
  },
633
638
  content: [
634
- {
635
- tag: 'props',
636
- attrs: {
639
+ { tag: 'props', attrs: {
637
640
  protocol: '2',
638
641
  hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
639
- }
640
- }
642
+ } }
641
643
  ]
642
644
  });
643
645
  const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
644
646
  let props = {};
645
647
  if (propsNode) {
646
- authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
647
- ev.emit('creds.update', authState.creds);
648
+ if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
649
+ authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
650
+ ev.emit('creds.update', authState.creds);
651
+ }
648
652
  props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
649
653
  }
650
654
  logger.debug('fetched props');
@@ -654,7 +658,7 @@ const makeChatsSocket = (config) => {
654
658
  * modify a chat -- mark unread, read etc.
655
659
  * lastMessages must be sorted in reverse chronologically
656
660
  * requires the last messages till the last message received; required for archive & unread
657
- */
661
+ */
658
662
  const chatModify = (mod, jid) => {
659
663
  const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
660
664
  return appPatch(patch);
@@ -738,24 +742,25 @@ const makeChatsSocket = (config) => {
738
742
  }
739
743
  }
740
744
  const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
741
- const shouldProcessHistoryMsg = historyMsg ?
742
- (shouldSyncHistoryMessage(historyMsg) &&
743
- Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
744
- false;
745
+ const shouldProcessHistoryMsg = historyMsg
746
+ ? (shouldSyncHistoryMessage(historyMsg)
747
+ && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
748
+ : false;
745
749
  if (historyMsg && !authState.creds.myAppStateKeyId) {
746
750
  logger.warn('skipping app state sync, as myAppStateKeyId is not set');
747
751
  pendingAppStateSync = true;
748
752
  }
749
753
  await Promise.all([
750
754
  (async () => {
751
- if (historyMsg &&
752
- authState.creds.myAppStateKeyId) {
755
+ if (historyMsg
756
+ && authState.creds.myAppStateKeyId) {
753
757
  pendingAppStateSync = false;
754
758
  await doAppStateSync();
755
759
  }
756
760
  })(),
757
761
  (0, process_message_1.default)(msg, {
758
762
  shouldProcessHistoryMsg,
763
+ placeholderResendCache,
759
764
  ev,
760
765
  creds: authState.creds,
761
766
  keyStore: authState.keys,
@@ -764,8 +769,8 @@ const makeChatsSocket = (config) => {
764
769
  getMessage: config.getMessage,
765
770
  })
766
771
  ]);
767
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
768
- pendingAppStateSync) {
772
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
773
+ && pendingAppStateSync) {
769
774
  await doAppStateSync();
770
775
  pendingAppStateSync = false;
771
776
  }
@@ -816,18 +821,17 @@ const makeChatsSocket = (config) => {
816
821
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
817
822
  .catch(error => onUnexpectedError(error, 'presence update requests'));
818
823
  }
819
- if (receivedPendingNotifications) {
820
- // if we don't have the app state key
824
+ if (receivedPendingNotifications && // if we don't have the app state key
821
825
  // we keep buffering events until we finally have
822
826
  // the key and can sync the messages
823
- if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
824
- ev.buffer();
825
- needToFlushWithAppStateSync = true;
826
- }
827
+ !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
828
+ ev.buffer();
829
+ needToFlushWithAppStateSync = true;
827
830
  }
828
831
  });
829
832
  return {
830
833
  ...sock,
834
+ getBotListV2,
831
835
  processingMutex,
832
836
  fetchPrivacySettings,
833
837
  upsertMessage,
@@ -837,12 +841,15 @@ const makeChatsSocket = (config) => {
837
841
  profilePictureUrl,
838
842
  onWhatsApp,
839
843
  fetchBlocklist,
844
+ fetchDisappearingDuration,
840
845
  fetchStatus,
841
846
  updateProfilePicture,
842
847
  removeProfilePicture,
843
848
  updateProfileStatus,
844
849
  updateProfileName,
845
850
  updateBlockStatus,
851
+ updateCallPrivacy,
852
+ updateMessagesPrivacy,
846
853
  updateLastSeenPrivacy,
847
854
  updateOnlinePrivacy,
848
855
  updateProfilePicturePrivacy,
@@ -6,7 +6,6 @@ const Types_1 = require("../Types");
6
6
  const Utils_1 = require("../Utils");
7
7
  const WABinary_1 = require("../WABinary");
8
8
  const chats_1 = require("./chats");
9
- const WAUSync_1 = require("../WAUSync");
10
9
  const makeGroupsSocket = (config) => {
11
10
  const sock = (0, chats_1.makeChatsSocket)(config);
12
11
  const { authState, ev, query, upsertMessage } = sock;
@@ -68,9 +67,10 @@ const makeGroupsSocket = (config) => {
68
67
  });
69
68
  return {
70
69
  ...sock,
70
+ groupQuery,
71
71
  groupMetadata,
72
72
  groupCreate: async (subject, participants) => {
73
- const key = (0, Utils_1.generateMessageID)();
73
+ const key = (0, Utils_1.generateMessageIDV2)();
74
74
  const result = await groupQuery('@g.us', 'set', [
75
75
  {
76
76
  tag: 'create',
@@ -164,7 +164,7 @@ const makeGroupsSocket = (config) => {
164
164
  {
165
165
  tag: 'description',
166
166
  attrs: {
167
- ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
167
+ ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
168
168
  ...(prev ? { prev } : {})
169
169
  },
170
170
  content: description ? [
@@ -188,12 +188,23 @@ const makeGroupsSocket = (config) => {
188
188
  const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group');
189
189
  return result === null || result === void 0 ? void 0 : result.attrs.jid;
190
190
  },
191
+ /**
192
+ * revoke a v4 invite for someone
193
+ * @param groupJid group jid
194
+ * @param invitedJid jid of person you invited
195
+ * @returns true if successful
196
+ */
197
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
198
+ const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }]);
199
+ return !!result;
200
+ },
191
201
  /**
192
202
  * accept a GroupInviteMessage
193
203
  * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
194
204
  * @param inviteMessage the message to accept
195
205
  */
196
206
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
207
+ var _a;
197
208
  key = typeof key === 'string' ? { remoteJid: key } : key;
198
209
  const results = await groupQuery(inviteMessage.groupJid, 'set', [{
199
210
  tag: 'accept',
@@ -225,7 +236,7 @@ const makeGroupsSocket = (config) => {
225
236
  await upsertMessage({
226
237
  key: {
227
238
  remoteJid: inviteMessage.groupJid,
228
- id: (0, Utils_1.generateMessageID)(),
239
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
229
240
  fromMe: false,
230
241
  participant: key.remoteJid,
231
242
  },
@@ -294,8 +305,12 @@ const extractGroupMetadata = (result) => {
294
305
  creation: group.attrs.creation ? +group.attrs.creation : undefined,
295
306
  owner: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn || group.attrs.creator),
296
307
  ...(group.attrs.addressing_mode === 'lid' ? { ownerLid: (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) } : {}),
308
+ desc,
309
+ descId,
297
310
  descOwner,
298
311
  descOwnerLid,
312
+ descTime,
313
+ linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
299
314
  restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
300
315
  announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
301
316
  isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
@@ -306,6 +321,7 @@ const extractGroupMetadata = (result) => {
306
321
  return {
307
322
  id: attrs.jid,
308
323
  jid: attrs.phone_number || attrs.jid,
324
+ lid: attrs.lid || attrs.jid,
309
325
  admin: (attrs.type || null),
310
326
  };
311
327
  }),
@@ -314,4 +330,3 @@ const extractGroupMetadata = (result) => {
314
330
  return metadata;
315
331
  };
316
332
  exports.extractGroupMetadata = extractGroupMetadata;
317
-
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Defaults_1 = require("../Defaults");
4
- const registration_1 = require("./registration");
4
+ const business_1 = require("./business");
5
5
  // export the last socket layer
6
- const makeWASocket = (config) => ((0, registration_1.makeRegistrationSocket)({
6
+ const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
7
7
  ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
8
  ...config
9
9
  }));
@@ -16,34 +16,9 @@ const WABinary_1 = require("../WABinary");
16
16
  const groups_1 = require("./groups");
17
17
  const messages_send_1 = require("./messages-send");
18
18
  const makeMessagesRecvSocket = (config) => {
19
- const {
20
- logger,
21
- retryRequestDelayMs,
22
- maxMsgRetryCount,
23
- getMessage,
24
- shouldIgnoreJid
25
- } = config;
19
+ const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
26
20
  const sock = (0, messages_send_1.makeMessagesSocket)(config);
27
- const {
28
- ev,
29
- authState,
30
- ws,
31
- processingMutex,
32
- signalRepository,
33
- query,
34
- upsertMessage,
35
- resyncAppState,
36
- groupMetadata,
37
- onUnexpectedError,
38
- assertSessions,
39
- sendNode,
40
- relayMessage,
41
- sendReceipt,
42
- uploadPreKeys,
43
- createParticipantNodes,
44
- getUSyncDevices,
45
- sendPeerDataOperationMessage
46
- } = sock;
21
+ const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, groupMetadata, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, } = sock;
47
22
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
48
23
  const retryMutex = (0, make_mutex_1.makeMutex)();
49
24
  const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
@@ -67,7 +42,7 @@ const makeMessagesRecvSocket = (config) => {
67
42
  to: attrs.from,
68
43
  class: tag
69
44
  }
70
- }
45
+ };
71
46
  if (!!errorCode) {
72
47
  stanza.attrs.error = errorCode.toString();
73
48
  }
@@ -83,31 +58,14 @@ const makeMessagesRecvSocket = (config) => {
83
58
  if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
84
59
  stanza.attrs.from = authState.creds.me.id;
85
60
  }
86
- logger.debug({
87
- recv: {
88
- tag,
89
- attrs
90
- },
91
- sent: stanza.attrs }, 'sent ack');
61
+ logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
92
62
  await sendNode(stanza);
93
63
  };
94
64
  const offerCall = async (toJid, isVideo = false) => {
95
65
  const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
96
66
  const offerContent = [];
97
- offerContent.push({
98
- tag: 'audio',
99
- attrs: {
100
- enc: 'opus',
101
- rate: '16000'
102
- }, content: undefined
103
- });
104
- offerContent.push({
105
- tag: 'audio',
106
- attrs: {
107
- enc: 'opus',
108
- rate: '8000'
109
- }, content: undefined
110
- });
67
+ offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '16000' }, content: undefined });
68
+ offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '8000' }, content: undefined });
111
69
  if (isVideo) {
112
70
  offerContent.push({
113
71
  tag: 'video',
@@ -121,23 +79,9 @@ const makeMessagesRecvSocket = (config) => {
121
79
  }
122
80
  });
123
81
  }
124
- offerContent.push({
125
- tag: 'net',
126
- attrs: {
127
- medium: '3'
128
- }, content: undefined
129
- });
130
- offerContent.push({
131
- tag: 'capability',
132
- attrs: {
133
- ver: '1'
134
- }, content: new Uint8Array([1, 4, 255, 131, 207, 4]) });
135
- offerContent.push({
136
- tag: 'encopt',
137
- attrs: {
138
- keygen: '2'
139
- }, content: undefined
140
- })
82
+ offerContent.push({ tag: 'net', attrs: { medium: '3' }, content: undefined });
83
+ offerContent.push({ tag: 'capability', attrs: { ver: '1' }, content: new Uint8Array([1, 4, 255, 131, 207, 4]) });
84
+ offerContent.push({ tag: 'encopt', attrs: { keygen: '2' }, content: undefined });
141
85
  const encKey = (0, crypto_1.randomBytes)(32);
142
86
  const devices = (await getUSyncDevices([toJid], true, false)).map(({ user, device }) => (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device));
143
87
  await assertSessions(devices, true);