@another-trial/whatsapp-web.js 1.34.1 → 1.35.0-alpha.2
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/.env.example +2 -2
- package/CODE_OF_CONDUCT.md +133 -133
- package/LICENSE +201 -201
- package/README.md +155 -185
- package/example.js +699 -690
- package/index.d.ts +2248 -2202
- package/index.js +35 -35
- package/package.json +59 -59
- package/shell.js +36 -36
- package/src/Client.js +2447 -2361
- package/src/authStrategies/BaseAuthStrategy.js +26 -26
- package/src/authStrategies/LocalAuth.js +58 -58
- package/src/authStrategies/NoAuth.js +11 -11
- package/src/authStrategies/RemoteAuth.js +210 -210
- package/src/factories/ChatFactory.js +21 -21
- package/src/factories/ContactFactory.js +15 -15
- package/src/structures/Base.js +21 -21
- package/src/structures/Broadcast.js +69 -69
- package/src/structures/BusinessContact.js +20 -20
- package/src/structures/Buttons.js +81 -81
- package/src/structures/Call.js +75 -75
- package/src/structures/Channel.js +382 -382
- package/src/structures/Chat.js +329 -299
- package/src/structures/ClientInfo.js +70 -70
- package/src/structures/Contact.js +208 -208
- package/src/structures/GroupChat.js +485 -485
- package/src/structures/GroupNotification.js +104 -104
- package/src/structures/Label.js +49 -49
- package/src/structures/List.js +79 -79
- package/src/structures/Location.js +61 -61
- package/src/structures/Message.js +780 -747
- package/src/structures/MessageMedia.js +111 -111
- package/src/structures/Order.js +51 -51
- package/src/structures/Payment.js +79 -79
- package/src/structures/Poll.js +44 -44
- package/src/structures/PollVote.js +75 -75
- package/src/structures/PrivateChat.js +12 -12
- package/src/structures/PrivateContact.js +12 -12
- package/src/structures/Product.js +67 -67
- package/src/structures/ProductMetadata.js +24 -24
- package/src/structures/Reaction.js +68 -68
- package/src/structures/ScheduledEvent.js +71 -71
- package/src/structures/index.js +27 -27
- package/src/util/Constants.js +186 -183
- package/src/util/Injected/AuthStore/AuthStore.js +16 -16
- package/src/util/Injected/AuthStore/LegacyAuthStore.js +21 -21
- package/src/util/Injected/LegacyStore.js +145 -145
- package/src/util/Injected/Store.js +257 -233
- package/src/util/Injected/Utils.js +1168 -1169
- package/src/util/InterfaceController.js +126 -126
- package/src/util/Puppeteer.js +23 -23
- package/src/util/Util.js +186 -186
- package/src/webCache/LocalWebCache.js +40 -40
- package/src/webCache/RemoteWebCache.js +39 -39
- package/src/webCache/WebCache.js +13 -13
- package/src/webCache/WebCacheFactory.js +19 -19
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
|
|
4
|
-
const { WebCache, VersionResolveError } = require('./WebCache');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* LocalWebCache - Fetches a WhatsApp Web version from a local file store
|
|
8
|
-
* @param {object} options - options
|
|
9
|
-
* @param {string} options.path - Path to the directory where cached versions are saved, default is: "./.wwebjs_cache/"
|
|
10
|
-
* @param {boolean} options.strict - If true, will throw an error if the requested version can't be fetched. If false, will resolve to the latest version.
|
|
11
|
-
*/
|
|
12
|
-
class LocalWebCache extends WebCache {
|
|
13
|
-
constructor(options = {}) {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
this.path = options.path || './.wwebjs_cache/';
|
|
17
|
-
this.strict = options.strict || false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async resolve(version) {
|
|
21
|
-
const filePath = path.join(this.path, `${version}.html`);
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
return fs.readFileSync(filePath, 'utf-8');
|
|
25
|
-
}
|
|
26
|
-
catch (err) {
|
|
27
|
-
if (this.strict) throw new VersionResolveError(`Couldn't load version ${version} from the cache`);
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async persist(indexHtml, version) {
|
|
33
|
-
// version = (version+'').replace(/[^0-9.]/g,'');
|
|
34
|
-
const filePath = path.join(this.path, `${version}.html`);
|
|
35
|
-
fs.mkdirSync(this.path, { recursive: true });
|
|
36
|
-
fs.writeFileSync(filePath, indexHtml);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = LocalWebCache;
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const { WebCache, VersionResolveError } = require('./WebCache');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* LocalWebCache - Fetches a WhatsApp Web version from a local file store
|
|
8
|
+
* @param {object} options - options
|
|
9
|
+
* @param {string} options.path - Path to the directory where cached versions are saved, default is: "./.wwebjs_cache/"
|
|
10
|
+
* @param {boolean} options.strict - If true, will throw an error if the requested version can't be fetched. If false, will resolve to the latest version.
|
|
11
|
+
*/
|
|
12
|
+
class LocalWebCache extends WebCache {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this.path = options.path || './.wwebjs_cache/';
|
|
17
|
+
this.strict = options.strict || false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async resolve(version) {
|
|
21
|
+
const filePath = path.join(this.path, `${version}.html`);
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (this.strict) throw new VersionResolveError(`Couldn't load version ${version} from the cache`);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async persist(indexHtml, version) {
|
|
33
|
+
// version = (version+'').replace(/[^0-9.]/g,'');
|
|
34
|
+
const filePath = path.join(this.path, `${version}.html`);
|
|
35
|
+
fs.mkdirSync(this.path, { recursive: true });
|
|
36
|
+
fs.writeFileSync(filePath, indexHtml);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = LocalWebCache;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
const fetch = require('node-fetch');
|
|
2
|
-
const { WebCache, VersionResolveError } = require('./WebCache');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* RemoteWebCache - Fetches a WhatsApp Web version index from a remote server
|
|
6
|
-
* @param {object} options - options
|
|
7
|
-
* @param {string} options.remotePath - Endpoint that should be used to fetch the version index. Use {version} as a placeholder for the version number.
|
|
8
|
-
* @param {boolean} options.strict - If true, will throw an error if the requested version can't be fetched. If false, will resolve to the latest version. Defaults to false.
|
|
9
|
-
*/
|
|
10
|
-
class RemoteWebCache extends WebCache {
|
|
11
|
-
constructor(options = {}) {
|
|
12
|
-
super();
|
|
13
|
-
|
|
14
|
-
if (!options.remotePath) throw new Error('webVersionCache.remotePath is required when using the remote cache');
|
|
15
|
-
this.remotePath = options.remotePath;
|
|
16
|
-
this.strict = options.strict || false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async resolve(version) {
|
|
20
|
-
const remotePath = this.remotePath.replace('{version}', version);
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const cachedRes = await fetch(remotePath);
|
|
24
|
-
if (cachedRes.ok) {
|
|
25
|
-
return cachedRes.text();
|
|
26
|
-
}
|
|
27
|
-
} catch (err) {
|
|
28
|
-
console.error(`Error fetching version ${version} from remote`, err);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (this.strict) throw new VersionResolveError(`Couldn't load version ${version} from the archive`);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async persist() {
|
|
36
|
-
// Nothing to do here
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
1
|
+
const fetch = require('node-fetch');
|
|
2
|
+
const { WebCache, VersionResolveError } = require('./WebCache');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* RemoteWebCache - Fetches a WhatsApp Web version index from a remote server
|
|
6
|
+
* @param {object} options - options
|
|
7
|
+
* @param {string} options.remotePath - Endpoint that should be used to fetch the version index. Use {version} as a placeholder for the version number.
|
|
8
|
+
* @param {boolean} options.strict - If true, will throw an error if the requested version can't be fetched. If false, will resolve to the latest version. Defaults to false.
|
|
9
|
+
*/
|
|
10
|
+
class RemoteWebCache extends WebCache {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
if (!options.remotePath) throw new Error('webVersionCache.remotePath is required when using the remote cache');
|
|
15
|
+
this.remotePath = options.remotePath;
|
|
16
|
+
this.strict = options.strict || false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async resolve(version) {
|
|
20
|
+
const remotePath = this.remotePath.replace('{version}', version);
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const cachedRes = await fetch(remotePath);
|
|
24
|
+
if (cachedRes.ok) {
|
|
25
|
+
return cachedRes.text();
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error(`Error fetching version ${version} from remote`, err);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.strict) throw new VersionResolveError(`Couldn't load version ${version} from the archive`);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async persist() {
|
|
36
|
+
// Nothing to do here
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
40
|
module.exports = RemoteWebCache;
|
package/src/webCache/WebCache.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default implementation of a web version cache that does nothing.
|
|
3
|
-
*/
|
|
4
|
-
class WebCache {
|
|
5
|
-
async resolve() { return null; }
|
|
6
|
-
async persist() { }
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class VersionResolveError extends Error { }
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
WebCache,
|
|
13
|
-
VersionResolveError
|
|
1
|
+
/**
|
|
2
|
+
* Default implementation of a web version cache that does nothing.
|
|
3
|
+
*/
|
|
4
|
+
class WebCache {
|
|
5
|
+
async resolve() { return null; }
|
|
6
|
+
async persist() { }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class VersionResolveError extends Error { }
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
WebCache,
|
|
13
|
+
VersionResolveError
|
|
14
14
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const RemoteWebCache = require('./RemoteWebCache');
|
|
2
|
-
const LocalWebCache = require('./LocalWebCache');
|
|
3
|
-
const { WebCache } = require('./WebCache');
|
|
4
|
-
|
|
5
|
-
const createWebCache = (type, options) => {
|
|
6
|
-
switch (type) {
|
|
7
|
-
case 'remote':
|
|
8
|
-
return new RemoteWebCache(options);
|
|
9
|
-
case 'local':
|
|
10
|
-
return new LocalWebCache(options);
|
|
11
|
-
case 'none':
|
|
12
|
-
return new WebCache();
|
|
13
|
-
default:
|
|
14
|
-
throw new Error(`Invalid WebCache type ${type}`);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
module.exports = {
|
|
19
|
-
createWebCache,
|
|
1
|
+
const RemoteWebCache = require('./RemoteWebCache');
|
|
2
|
+
const LocalWebCache = require('./LocalWebCache');
|
|
3
|
+
const { WebCache } = require('./WebCache');
|
|
4
|
+
|
|
5
|
+
const createWebCache = (type, options) => {
|
|
6
|
+
switch (type) {
|
|
7
|
+
case 'remote':
|
|
8
|
+
return new RemoteWebCache(options);
|
|
9
|
+
case 'local':
|
|
10
|
+
return new LocalWebCache(options);
|
|
11
|
+
case 'none':
|
|
12
|
+
return new WebCache();
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Invalid WebCache type ${type}`);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
createWebCache,
|
|
20
20
|
};
|