chore(v1.34.7): bump version and generate docs

This commit is contained in:
WWebJS Bot 2026-04-24 20:10:36 +00:00
commit f935b50011
77 changed files with 5207 additions and 2669 deletions

View file

@ -4,7 +4,7 @@
<head>
<meta name="generator" content="JSDoc 3.6.11">
<meta charset="utf-8">
<title>whatsapp-web.js 1.34.6 &raquo; Source: authStrategies/RemoteAuth.js</title>
<title>whatsapp-web.js 1.34.7 &raquo; Source: authStrategies/RemoteAuth.js</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
@ -15,7 +15,7 @@
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>34.<wbr>6</a>
<a href="index.html" class="jsdoc-navbar-package-name">whatsapp-web.<wbr>js 1.<wbr>34.<wbr>7</a>
</div>
</div>
</nav>
@ -51,40 +51,64 @@ const BaseAuthStrategy &#x3D; require(&#x27;./BaseAuthStrategy&#x27;);
* @param {object} options - options
* @param {object} options.store - Remote database store instance
* @param {string} options.clientId - Client id to distinguish instances if you are using multiple, otherwise keep null if you are using only one instance
* @param {string} options.dataPath - Change the default path for saving session files, default is: &quot;./.wwebjs_auth/&quot;
* @param {string} options.dataPath - Change the default path for saving session files, default is: &quot;./.wwebjs_auth/&quot;
* @param {number} options.backupSyncIntervalMs - Sets the time interval for periodic session backups. Accepts values starting from 60000ms {1 minute}
* @param {number} options.rmMaxRetries - Sets the maximum number of retries for removing the session directory
*/
class RemoteAuth extends BaseAuthStrategy {
constructor({ clientId, dataPath, store, backupSyncIntervalMs, rmMaxRetries } &#x3D; {}) {
if (!fs &amp;amp;&amp;amp; !unzipper &amp;amp;&amp;amp; !archiver) throw new Error(&#x27;Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag&#x27;);
constructor({
clientId,
dataPath,
store,
backupSyncIntervalMs,
rmMaxRetries,
} &#x3D; {}) {
if (!fs &amp;amp;&amp;amp; !unzipper &amp;amp;&amp;amp; !archiver)
throw new Error(
&#x27;Optional Dependencies [fs-extra, unzipper, archiver] are required to use RemoteAuth. Make sure to run npm install correctly and remove the --no-optional flag&#x27;,
);
super();
const idRegex &#x3D; /^[-_\w]+$/i;
if (clientId &amp;amp;&amp;amp; !idRegex.test(clientId)) {
throw new Error(&#x27;Invalid clientId. Only alphanumeric characters, underscores and hyphens are allowed.&#x27;);
throw new Error(
&#x27;Invalid clientId. Only alphanumeric characters, underscores and hyphens are allowed.&#x27;,
);
}
if (!backupSyncIntervalMs || backupSyncIntervalMs &amp;lt; 60000) {
throw new Error(&#x27;Invalid backupSyncIntervalMs. Accepts values starting from 60000ms {1 minute}.&#x27;);
throw new Error(
&#x27;Invalid backupSyncIntervalMs. Accepts values starting from 60000ms {1 minute}.&#x27;,
);
}
if(!store) throw new Error(&#x27;Remote database store is required.&#x27;);
if (!store) throw new Error(&#x27;Remote database store is required.&#x27;);
this.store &#x3D; store;
this.clientId &#x3D; clientId;
this.backupSyncIntervalMs &#x3D; backupSyncIntervalMs;
this.dataPath &#x3D; path.resolve(dataPath || &#x27;./.wwebjs_auth/&#x27;);
this.tempDir &#x3D; &#x60;${this.dataPath}/wwebjs_temp_session_${this.clientId}&#x60;;
this.requiredDirs &#x3D; [&#x27;Default&#x27;, &#x27;IndexedDB&#x27;, &#x27;Local Storage&#x27;]; /* &#x3D;&gt; Required Files &amp;amp; Dirs in WWebJS to restore session */
this.requiredDirs &#x3D; [
&#x27;Default&#x27;,
&#x27;IndexedDB&#x27;,
&#x27;Local Storage&#x27;,
]; /* &#x3D;&gt; Required Files &amp;amp; Dirs in WWebJS to restore session */
this.rmMaxRetries &#x3D; rmMaxRetries ?? 4;
}
async beforeBrowserInitialized() {
const puppeteerOpts &#x3D; this.client.options.puppeteer;
const sessionDirName &#x3D; this.clientId ? &#x60;RemoteAuth-${this.clientId}&#x60; : &#x27;RemoteAuth&#x27;;
const sessionDirName &#x3D; this.clientId
? &#x60;RemoteAuth-${this.clientId}&#x60;
: &#x27;RemoteAuth&#x27;;
const dirPath &#x3D; path.join(this.dataPath, sessionDirName);
if (puppeteerOpts.userDataDir &amp;amp;&amp;amp; puppeteerOpts.userDataDir !&#x3D;&#x3D; dirPath) {
throw new Error(&#x27;RemoteAuth is not compatible with a user-supplied userDataDir.&#x27;);
if (
puppeteerOpts.userDataDir &amp;amp;&amp;amp;
puppeteerOpts.userDataDir !&#x3D;&#x3D; dirPath
) {
throw new Error(
&#x27;RemoteAuth is not compatible with a user-supplied userDataDir.&#x27;,
);
}
this.userDataDir &#x3D; dirPath;
@ -94,7 +118,7 @@ class RemoteAuth extends BaseAuthStrategy {
this.client.options.puppeteer &#x3D; {
...puppeteerOpts,
userDataDir: dirPath
userDataDir: dirPath,
};
}
@ -111,20 +135,26 @@ class RemoteAuth extends BaseAuthStrategy {
let pathExists &#x3D; await this.isValidPath(this.userDataDir);
if (pathExists) {
await fs.promises.rm(this.userDataDir, {
recursive: true,
force: true,
maxRetries: this.rmMaxRetries,
}).catch(() &#x3D;&gt; {});
await fs.promises
.rm(this.userDataDir, {
recursive: true,
force: true,
maxRetries: this.rmMaxRetries,
})
.catch(() &#x3D;&gt; {});
}
clearInterval(this.backupSync);
}
async afterAuthReady() {
const sessionExists &#x3D; await this.store.sessionExists({session: this.sessionName});
if(!sessionExists) {
await this.delay(60000); /* Initial delay sync required for session to be stable enough to recover */
await this.storeRemoteSession({emit: true});
const sessionExists &#x3D; await this.store.sessionExists({
session: this.sessionName,
});
if (!sessionExists) {
await this.delay(
60000,
); /* Initial delay sync required for session to be stable enough to recover */
await this.storeRemoteSession({ emit: true });
}
var self &#x3D; this;
this.backupSync &#x3D; setInterval(async function () {
@ -133,34 +163,57 @@ class RemoteAuth extends BaseAuthStrategy {
}
async storeRemoteSession(options) {
/* Compress &amp;amp; Store Session */
const pathExists &#x3D; await this.isValidPath(this.userDataDir);
if (pathExists) {
await this.compressSession();
await this.store.save({session: path.join(this.dataPath, this.sessionName)});
await fs.promises.unlink(path.join(this.dataPath, &#x60;${this.sessionName}.zip&#x60;));
await fs.promises.rm(&#x60;${this.tempDir}&#x60;, {
recursive: true,
force: true,
maxRetries: this.rmMaxRetries,
}).catch(() &#x3D;&gt; {});
if(options &amp;amp;&amp;amp; options.emit) this.client.emit(Events.REMOTE_SESSION_SAVED);
if (!pathExists) return;
let compressedSessionPath;
try {
compressedSessionPath &#x3D; await this.compressSession();
await this.store.save({
session: this.sessionName,
});
if (options &amp;amp;&amp;amp; options.emit)
this.client.emit(Events.REMOTE_SESSION_SAVED);
} finally {
const paths &#x3D; [
this.tempDir,
...(compressedSessionPath ? [compressedSessionPath] : []),
];
await Promise.allSettled(
paths.map((p) &#x3D;&gt;
fs.promises.rm(p, {
recursive: true,
force: true,
maxRetries: this.rmMaxRetries,
}),
),
);
}
}
async extractRemoteSession() {
const pathExists &#x3D; await this.isValidPath(this.userDataDir);
const compressedSessionPath &#x3D; path.join(this.dataPath, &#x60;${this.sessionName}.zip&#x60;);
const sessionExists &#x3D; await this.store.sessionExists({session: this.sessionName});
const compressedSessionPath &#x3D; path.join(
this.dataPath,
&#x60;${this.sessionName}.zip&#x60;,
);
const sessionExists &#x3D; await this.store.sessionExists({
session: this.sessionName,
});
if (pathExists) {
await fs.promises.rm(this.userDataDir, {
recursive: true,
force: true,
maxRetries: this.rmMaxRetries,
}).catch(() &#x3D;&gt; {});
await fs.promises
.rm(this.userDataDir, {
recursive: true,
force: true,
maxRetries: this.rmMaxRetries,
})
.catch(() &#x3D;&gt; {});
}
if (sessionExists) {
await this.store.extract({session: this.sessionName, path: compressedSessionPath});
await this.store.extract({
session: this.sessionName,
path: compressedSessionPath,
});
await this.unCompressSession(compressedSessionPath);
} else {
fs.mkdirSync(this.userDataDir, { recursive: true });
@ -168,59 +221,62 @@ class RemoteAuth extends BaseAuthStrategy {
}
async deleteRemoteSession() {
const sessionExists &#x3D; await this.store.sessionExists({session: this.sessionName});
if (sessionExists) await this.store.delete({session: this.sessionName});
const sessionExists &#x3D; await this.store.sessionExists({
session: this.sessionName,
});
if (sessionExists)
await this.store.delete({ session: this.sessionName });
}
async compressSession() {
const stageDefaultPath &#x3D; path.join(this.tempDir, &#x27;Default&#x27;);
const userDataDefaultPath &#x3D; path.join(this.userDataDir, &#x27;Default&#x27;);
await fs.emptyDir(stageDefaultPath);
await this.copyByRequiredDirs(userDataDefaultPath, stageDefaultPath);
const archive &#x3D; archiver(&#x27;zip&#x27;);
const stream &#x3D; fs.createWriteStream(path.join(this.dataPath, &#x60;${this.sessionName}.zip&#x60;));
const outPath &#x3D; path.join(this.dataPath, &#x60;${this.sessionName}.zip&#x60;);
const out &#x3D; fs.createWriteStream(outPath);
await fs.copy(this.userDataDir, this.tempDir).catch(() &#x3D;&gt; {});
await this.deleteMetadata();
return new Promise((resolve, reject) &#x3D;&gt; {
archive
.directory(this.tempDir, false)
.on(&#x27;error&#x27;, err &#x3D;&gt; reject(err))
.pipe(stream);
await new Promise((resolve, reject) &#x3D;&gt; {
out.once(&#x27;close&#x27;, resolve);
out.once(&#x27;error&#x27;, reject);
archive.once(&#x27;error&#x27;, reject);
stream.on(&#x27;close&#x27;, () &#x3D;&gt; resolve());
archive.pipe(out);
archive.directory(this.tempDir, false);
archive.finalize();
});
return outPath;
}
async unCompressSession(compressedSessionPath) {
var stream &#x3D; fs.createReadStream(compressedSessionPath);
await new Promise((resolve, reject) &#x3D;&gt; {
stream.pipe(unzipper.Extract({
path: this.userDataDir,
concurrency: 10
}))
.on(&#x27;error&#x27;, err &#x3D;&gt; reject(err))
stream
.pipe(
unzipper.Extract({
path: this.userDataDir,
concurrency: 10,
}),
)
.on(&#x27;error&#x27;, (err) &#x3D;&gt; reject(err))
.on(&#x27;finish&#x27;, () &#x3D;&gt; resolve());
});
await fs.promises.unlink(compressedSessionPath);
}
async deleteMetadata() {
const sessionDirs &#x3D; [this.tempDir, path.join(this.tempDir, &#x27;Default&#x27;)];
for (const dir of sessionDirs) {
const sessionFiles &#x3D; await fs.promises.readdir(dir);
for (const element of sessionFiles) {
if (!this.requiredDirs.includes(element)) {
const dirElement &#x3D; path.join(dir, element);
const stats &#x3D; await fs.promises.lstat(dirElement);
if (stats.isDirectory()) {
await fs.promises.rm(dirElement, {
recursive: true,
force: true,
maxRetries: this.rmMaxRetries,
}).catch(() &#x3D;&gt; {});
} else {
await fs.promises.unlink(dirElement).catch(() &#x3D;&gt; {});
}
}
async copyByRequiredDirs(from, to) {
for (const d of this.requiredDirs) {
const src &#x3D; path.join(from, d);
if (await this.isValidPath(src)) {
const dest &#x3D; path.join(to, path.basename(src));
await fs.promises.cp(src, dest, {
recursive: true,
force: true,
errorOnExist: false,
});
}
}
}
@ -235,7 +291,7 @@ class RemoteAuth extends BaseAuthStrategy {
}
async delay(ms) {
return new Promise(resolve &#x3D;&gt; setTimeout(resolve, ms));
return new Promise((resolve) &#x3D;&gt; setTimeout(resolve, ms));
}
}
@ -250,7 +306,7 @@ module.exports &#x3D; RemoteAuth;
<footer id="jsdoc-footer" class="jsdoc-footer">
<div id="jsdoc-footer-container">
<p>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.11 on January 30, 2026.
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc</a> 3.6.11 on April 24, 2026.
</p>
</div>
</footer>