whatsapp-web.js 1.21.1-alpha.0 → 2.0.0-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.21.1-alpha.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
package/src/Client.js CHANGED
@@ -275,6 +275,50 @@ class Client extends EventEmitter {
275
275
 
276
276
  }
277
277
 
278
+ await page.evaluate(() => {
279
+ /**
280
+ * Helper function that compares between two WWeb versions. Its purpose is to help the developer to choose the correct code implementation depending on the comparison value and the WWeb version.
281
+ * @param {string} lOperand The left operand for the WWeb version string to compare with
282
+ * @param {string} operator The comparison operator
283
+ * @param {string} rOperand The right operand for the WWeb version string to compare with
284
+ * @returns {boolean} Boolean value that indicates the result of the comparison
285
+ */
286
+ window.compareWwebVersions = (lOperand, operator, rOperand) => {
287
+ if (!['>', '>=', '<', '<=', '='].includes(operator)) {
288
+ throw class _ extends Error {
289
+ constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
290
+ }('Invalid comparison operator is provided');
291
+
292
+ }
293
+ if (typeof lOperand !== 'string' || typeof rOperand !== 'string') {
294
+ throw class _ extends Error {
295
+ constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
296
+ }('A non-string WWeb version type is provided');
297
+ }
298
+
299
+ lOperand = lOperand.replace(/-beta$/, '');
300
+ rOperand = rOperand.replace(/-beta$/, '');
301
+
302
+ while (lOperand.length !== rOperand.length) {
303
+ lOperand.length > rOperand.length
304
+ ? rOperand = rOperand.concat('0')
305
+ : lOperand = lOperand.concat('0');
306
+ }
307
+
308
+ lOperand = Number(lOperand.replace(/\./g, ''));
309
+ rOperand = Number(rOperand.replace(/\./g, ''));
310
+
311
+ return (
312
+ operator === '>' ? lOperand > rOperand :
313
+ operator === '>=' ? lOperand >= rOperand :
314
+ operator === '<' ? lOperand < rOperand :
315
+ operator === '<=' ? lOperand <= rOperand :
316
+ operator === '=' ? lOperand === rOperand :
317
+ false
318
+ );
319
+ };
320
+ });
321
+
278
322
  await page.evaluate(ExposeStore, moduleRaid.toString());
279
323
  const authEventPayload = await this.authStrategy.getAuthEventPayload();
280
324
 
@@ -702,7 +746,14 @@ class Client extends EventEmitter {
702
746
  await this.pupPage.evaluate(() => {
703
747
  return window.Store.AppState.logout();
704
748
  });
705
-
749
+ await this.pupBrowser.close();
750
+
751
+ let maxDelay = 0;
752
+ while (this.pupBrowser.isConnected() && (maxDelay < 10)) { // waits a maximum of 1 second before calling the AuthStrategy
753
+ await new Promise(resolve => setTimeout(resolve, 100));
754
+ maxDelay++;
755
+ }
756
+
706
757
  await this.authStrategy.logout();
707
758
  }
708
759
 
@@ -44,10 +44,10 @@ class LocalAuth extends BaseAuthStrategy {
44
44
 
45
45
  async logout() {
46
46
  if (this.userDataDir) {
47
- return (fs.rmSync ? fs.rmSync : fs.rmdirSync).call(this, this.userDataDir, { recursive: true });
47
+ return (fs.rmSync ? fs.rmSync : fs.rmdirSync).call(this, this.userDataDir, { recursive: true, force: true });
48
48
  }
49
49
  }
50
50
 
51
51
  }
52
52
 
53
- module.exports = LocalAuth;
53
+ module.exports = LocalAuth;
@@ -187,7 +187,7 @@ class Chat extends Base {
187
187
  if (m.isNotification) {
188
188
  return false; // dont include notification messages
189
189
  }
190
- if (searchOptions && searchOptions.fromMe && m.id.fromMe !== searchOptions.fromMe) {
190
+ if (searchOptions && searchOptions.fromMe !== undefined && m.id.fromMe !== searchOptions.fromMe) {
191
191
  return false;
192
192
  }
193
193
  return true;
@@ -153,8 +153,9 @@ class GroupChat extends Chat {
153
153
  const success = await this.client.pupPage.evaluate(async (chatId, description) => {
154
154
  const chatWid = window.Store.WidFactory.createWid(chatId);
155
155
  let descId = window.Store.GroupMetadata.get(chatWid).descId;
156
+ let newId = await window.Store.MsgKey.newId();
156
157
  try {
157
- await window.Store.GroupUtils.setGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
158
+ await window.Store.GroupUtils.setGroupDescription(chatWid, description, newId, descId);
158
159
  return true;
159
160
  } catch (err) {
160
161
  if(err.name === 'ServerStatusCodeError') return false;
@@ -278,4 +279,4 @@ class GroupChat extends Chat {
278
279
 
279
280
  }
280
281
 
281
- module.exports = GroupChat;
282
+ module.exports = GroupChat;
@@ -9,7 +9,7 @@ exports.ExposeStore = (moduleRaidStr) => {
9
9
  window.Store.AppState = window.mR.findModule('Socket')[0].Socket;
10
10
  window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
11
11
  window.Store.BlockContact = window.mR.findModule('blockContact')[0];
12
- window.Store.Call = window.mR.findModule('CallCollection')[0].CallCollection;
12
+ window.Store.Call = window.mR.findModule((module) => module.default && module.default.Call)[0].default.Call;
13
13
  window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
14
14
  window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
15
15
  window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
@@ -80,6 +80,12 @@ exports.ExposeStore = (moduleRaidStr) => {
80
80
  };
81
81
  }
82
82
 
83
+ if (window.mR.findModule('ChatCollection')[0] && window.mR.findModule('ChatCollection')[0].ChatCollection) {
84
+ if (typeof window.mR.findModule('ChatCollection')[0].ChatCollection.findImpl === 'undefined' && typeof window.mR.findModule('ChatCollection')[0].ChatCollection._find != 'undefined') {
85
+ window.mR.findModule('ChatCollection')[0].ChatCollection.findImpl = window.mR.findModule('ChatCollection')[0].ChatCollection._find;
86
+ }
87
+ }
88
+
83
89
  // TODO remove these once everybody has been updated to WWebJS with legacy sessions removed
84
90
  const _linkPreview = window.mR.findModule('queryLinkPreview');
85
91
  if (_linkPreview && _linkPreview[0] && _linkPreview[0].default) {
@@ -511,7 +517,7 @@ exports.LoadUtils = () => {
511
517
 
512
518
  // TODO: remove useOldImplementation and its checks once all clients are updated to >= v2.2327.4
513
519
  const useOldImplementation
514
- = window.WWebJS.compareWwebVersions(window.Debug.VERSION, '<', '2.2327.4');
520
+ = window.compareWwebVersions(window.Debug.VERSION, '<', '2.2327.4');
515
521
 
516
522
  res.isMe = useOldImplementation
517
523
  ? contact.isMe
@@ -787,46 +793,4 @@ exports.LoadUtils = () => {
787
793
  throw err;
788
794
  }
789
795
  };
790
-
791
- /**
792
- * Inner function that compares between two WWeb versions. Its purpose is to help the developer to choose the correct code implementation depending on the comparison value and the WWeb version.
793
- * @param {string} lOperand The left operand for the WWeb version string to compare with
794
- * @param {string} operator The comparison operator
795
- * @param {string} rOperand The right operand for the WWeb version string to compare with
796
- * @returns {boolean} Boolean value that indicates the result of the comparison
797
- */
798
- window.WWebJS.compareWwebVersions = (lOperand, operator, rOperand) => {
799
- if (!['>', '>=', '<', '<=', '='].includes(operator)) {
800
- throw class _ extends Error {
801
- constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
802
- }('Invalid comparison operator is provided');
803
-
804
- }
805
- if (typeof lOperand !== 'string' || typeof rOperand !== 'string') {
806
- throw class _ extends Error {
807
- constructor(m) { super(m); this.name = 'CompareWwebVersionsError'; }
808
- }('A non-string WWeb version type is provided');
809
- }
810
-
811
- lOperand = lOperand.replace(/-beta$/, '');
812
- rOperand = rOperand.replace(/-beta$/, '');
813
-
814
- while (lOperand.length !== rOperand.length) {
815
- lOperand.length > rOperand.length
816
- ? rOperand = rOperand.concat('0')
817
- : lOperand = lOperand.concat('0');
818
- }
819
-
820
- lOperand = Number(lOperand.replace(/\./g, ''));
821
- rOperand = Number(rOperand.replace(/\./g, ''));
822
-
823
- return (
824
- operator === '>' ? lOperand > rOperand :
825
- operator === '>=' ? lOperand >= rOperand :
826
- operator === '<' ? lOperand < rOperand :
827
- operator === '<=' ? lOperand <= rOperand :
828
- operator === '=' ? lOperand === rOperand :
829
- false
830
- );
831
- };
832
796
  };