whatsapp-web.js 1.26.1-alpha.2 → 1.27.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/index.d.ts CHANGED
@@ -538,7 +538,8 @@ declare namespace WAWebJS {
538
538
  public dataPath?: string;
539
539
  constructor(options?: {
540
540
  clientId?: string,
541
- dataPath?: string
541
+ dataPath?: string,
542
+ rmMaxRetries?: number
542
543
  })
543
544
  }
544
545
 
@@ -552,7 +553,8 @@ declare namespace WAWebJS {
552
553
  store: Store,
553
554
  clientId?: string,
554
555
  dataPath?: string,
555
- backupSyncIntervalMs: number
556
+ backupSyncIntervalMs: number,
557
+ rmMaxRetries?: number
556
558
  })
557
559
  }
558
560
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatsapp-web.js",
3
- "version": "1.26.1-alpha.2",
3
+ "version": "1.27.0",
4
4
  "description": "Library for interacting with the WhatsApp Web API ",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
@@ -9,9 +9,10 @@ const BaseAuthStrategy = require('./BaseAuthStrategy');
9
9
  * @param {object} options - options
10
10
  * @param {string} options.clientId - Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance
11
11
  * @param {string} options.dataPath - Change the default path for saving session files, default is: "./.wwebjs_auth/"
12
+ * @param {number} options.rmMaxRetries - Sets the maximum number of retries for removing the session directory
12
13
  */
13
14
  class LocalAuth extends BaseAuthStrategy {
14
- constructor({ clientId, dataPath }={}) {
15
+ constructor({ clientId, dataPath, rmMaxRetries }={}) {
15
16
  super();
16
17
 
17
18
  const idRegex = /^[-_\w]+$/i;
@@ -21,6 +22,7 @@ class LocalAuth extends BaseAuthStrategy {
21
22
 
22
23
  this.dataPath = path.resolve(dataPath || './.wwebjs_auth/');
23
24
  this.clientId = clientId;
25
+ this.rmMaxRetries = rmMaxRetries ?? 4;
24
26
  }
25
27
 
26
28
  async beforeBrowserInitialized() {
@@ -44,7 +46,7 @@ class LocalAuth extends BaseAuthStrategy {
44
46
 
45
47
  async logout() {
46
48
  if (this.userDataDir) {
47
- await fs.promises.rm(this.userDataDir, { recursive: true, force: true })
49
+ await fs.promises.rm(this.userDataDir, { recursive: true, force: true, maxRetries: this.rmMaxRetries })
48
50
  .catch((e) => {
49
51
  throw new Error(e);
50
52
  });
@@ -22,9 +22,10 @@ const BaseAuthStrategy = require('./BaseAuthStrategy');
22
22
  * @param {string} options.clientId - Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance
23
23
  * @param {string} options.dataPath - Change the default path for saving session files, default is: "./.wwebjs_auth/"
24
24
  * @param {number} options.backupSyncIntervalMs - Sets the time interval for periodic session backups. Accepts values starting from 60000ms {1 minute}
25
+ * @param {number} options.rmMaxRetries - Sets the maximum number of retries for removing the session directory
25
26
  */
26
27
  class RemoteAuth extends BaseAuthStrategy {
27
- constructor({ clientId, dataPath, store, backupSyncIntervalMs } = {}) {
28
+ constructor({ clientId, dataPath, store, backupSyncIntervalMs, rmMaxRetries } = {}) {
28
29
  if (!fs && !unzipper && !archiver) throw new Error('Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag');
29
30
  super();
30
31
 
@@ -43,6 +44,7 @@ class RemoteAuth extends BaseAuthStrategy {
43
44
  this.dataPath = path.resolve(dataPath || './.wwebjs_auth/');
44
45
  this.tempDir = `${this.dataPath}/wwebjs_temp_session_${this.clientId}`;
45
46
  this.requiredDirs = ['Default', 'IndexedDB', 'Local Storage']; /* => Required Files & Dirs in WWebJS to restore session */
47
+ this.rmMaxRetries = rmMaxRetries ?? 4;
46
48
  }
47
49
 
48
50
  async beforeBrowserInitialized() {
@@ -80,7 +82,8 @@ class RemoteAuth extends BaseAuthStrategy {
80
82
  if (pathExists) {
81
83
  await fs.promises.rm(this.userDataDir, {
82
84
  recursive: true,
83
- force: true
85
+ force: true,
86
+ maxRetries: this.rmMaxRetries,
84
87
  }).catch(() => {});
85
88
  }
86
89
  clearInterval(this.backupSync);
@@ -107,7 +110,8 @@ class RemoteAuth extends BaseAuthStrategy {
107
110
  await fs.promises.unlink(`${this.sessionName}.zip`);
108
111
  await fs.promises.rm(`${this.tempDir}`, {
109
112
  recursive: true,
110
- force: true
113
+ force: true,
114
+ maxRetries: this.rmMaxRetries,
111
115
  }).catch(() => {});
112
116
  if(options && options.emit) this.client.emit(Events.REMOTE_SESSION_SAVED);
113
117
  }
@@ -120,7 +124,8 @@ class RemoteAuth extends BaseAuthStrategy {
120
124
  if (pathExists) {
121
125
  await fs.promises.rm(this.userDataDir, {
122
126
  recursive: true,
123
- force: true
127
+ force: true,
128
+ maxRetries: this.rmMaxRetries,
124
129
  }).catch(() => {});
125
130
  }
126
131
  if (sessionExists) {
@@ -177,7 +182,8 @@ class RemoteAuth extends BaseAuthStrategy {
177
182
  if (stats.isDirectory()) {
178
183
  await fs.promises.rm(dirElement, {
179
184
  recursive: true,
180
- force: true
185
+ force: true,
186
+ maxRetries: this.rmMaxRetries,
181
187
  }).catch(() => {});
182
188
  } else {
183
189
  await fs.promises.unlink(dirElement).catch(() => {});
@@ -381,9 +381,9 @@ class GroupChat extends Chat {
381
381
  const codeRes = await this.client.pupPage.evaluate(async chatId => {
382
382
  const chatWid = window.Store.WidFactory.createWid(chatId);
383
383
  try {
384
- return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')
385
- ? await window.Store.GroupInvite.queryGroupInviteCode(chatWid, true)
386
- : await window.Store.GroupInvite.queryGroupInviteCode(chatWid);
384
+ return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1020730154')
385
+ ? await window.Store.GroupInvite.fetchMexGroupInviteCode(chatId)
386
+ : await window.Store.GroupInvite.queryGroupInviteCode(chatWid, true);
387
387
  }
388
388
  catch (err) {
389
389
  if(err.name === 'ServerStatusCodeError') return undefined;
@@ -391,7 +391,9 @@ class GroupChat extends Chat {
391
391
  }
392
392
  }, this.id._serialized);
393
393
 
394
- return codeRes?.code;
394
+ return codeRes?.code
395
+ ? codeRes?.code
396
+ : codeRes;
395
397
  }
396
398
 
397
399
  /**
@@ -122,7 +122,8 @@ exports.ExposeStore = () => {
122
122
  };
123
123
  window.Store.GroupInvite = {
124
124
  ...window.require('WAWebGroupInviteJob'),
125
- ...window.require('WAWebGroupQueryJob')
125
+ ...window.require('WAWebGroupQueryJob'),
126
+ ...window.require('WAWebMexFetchGroupInviteCodeJob')
126
127
  };
127
128
  window.Store.GroupInviteV4 = {
128
129
  ...window.require('WAWebGroupInviteV4Job'),
@@ -451,11 +451,12 @@ exports.LoadUtils = () => {
451
451
  window.WWebJS.getChatModel = async chat => {
452
452
 
453
453
  let res = chat.serialize();
454
- res.isGroup = chat.isGroup;
454
+ res.isGroup = false;
455
455
  res.formattedTitle = chat.formattedTitle;
456
- res.isMuted = chat.mute && chat.mute.isMuted;
456
+ res.isMuted = chat.muteExpiration == 0 ? false : true;
457
457
 
458
458
  if (chat.groupMetadata) {
459
+ res.isGroup = true;
459
460
  const chatWid = window.Store.WidFactory.createWid((chat.id._serialized));
460
461
  await window.Store.GroupMetadata.update(chatWid);
461
462
  res.groupMetadata = chat.groupMetadata.serialize();