@wppconnect-team/wppconnect 2.0.0 → 2.0.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/helpers/base64-mimetype.js +2 -2
  3. package/dist/api/helpers/decrypt.js +65 -72
  4. package/dist/api/helpers/download-file.js +31 -81
  5. package/dist/api/helpers/evaluate-and-return.js +98 -93
  6. package/dist/api/helpers/file-to-base64.js +30 -81
  7. package/dist/api/helpers/filename-from-mimetype.js +4 -4
  8. package/dist/api/helpers/scrape-img-qr.js +37 -86
  9. package/dist/api/helpers/scrape-login.js +12 -57
  10. package/dist/api/helpers/select-sticker.js +35 -100
  11. package/dist/api/layers/business.layer.js +29 -134
  12. package/dist/api/layers/catalog.layer.js +59 -210
  13. package/dist/api/layers/community.layer.js +29 -120
  14. package/dist/api/layers/controls.layer.js +62 -262
  15. package/dist/api/layers/group.layer.js +126 -391
  16. package/dist/api/layers/host.layer.js +348 -702
  17. package/dist/api/layers/labels.layer.js +35 -131
  18. package/dist/api/layers/listener.layer.js +386 -504
  19. package/dist/api/layers/newsletter.layer.js +20 -89
  20. package/dist/api/layers/profile.layer.js +73 -184
  21. package/dist/api/layers/retriever.layer.js +161 -468
  22. package/dist/api/layers/sender.layer.js +554 -1094
  23. package/dist/api/layers/status.layer.js +80 -179
  24. package/dist/api/layers/ui.layer.js +32 -129
  25. package/dist/api/model/enum/definitions.js +1 -1
  26. package/dist/api/whatsapp.js +200 -437
  27. package/dist/config/WAuserAgente.js +1 -1
  28. package/dist/config/create-config.js +1 -1
  29. package/dist/config/puppeteer.config.js +1 -1
  30. package/dist/controllers/auth.js +42 -110
  31. package/dist/controllers/browser.js +251 -411
  32. package/dist/controllers/initializer.js +171 -265
  33. package/dist/controllers/websocket.js +29 -28
  34. package/dist/controllers/welcome.js +38 -88
  35. package/dist/token-store/fileTokenStore.js +83 -173
  36. package/dist/token-store/isValidSessionToken.js +2 -2
  37. package/dist/token-store/isValidTokenStore.js +2 -2
  38. package/dist/token-store/memoryTokenStore.js +11 -14
  39. package/dist/utils/ffmpeg.js +75 -131
  40. package/dist/utils/logger.js +5 -5
  41. package/dist/utils/semver.js +6 -6
  42. package/dist/utils/sleep.js +1 -1
  43. package/package.json +8 -8
@@ -32,42 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __generator = (this && this.__generator) || function (thisArg, body) {
45
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
- function verb(n) { return function (v) { return step([n, v]); }; }
48
- function step(op) {
49
- if (f) throw new TypeError("Generator is already executing.");
50
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52
- if (y = 0, t) op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0: case 1: t = op; break;
55
- case 4: _.label++; return { value: op[1], done: false };
56
- case 5: _.label++; y = op[1]; op = [0]; continue;
57
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
- default:
59
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
- if (t[2]) _.ops.pop();
64
- _.trys.pop(); continue;
65
- }
66
- op = body.call(thisArg, _);
67
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
- }
70
- };
71
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
72
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
73
37
  };
@@ -90,15 +54,15 @@ exports.convertToMP4GIF = convertToMP4GIF;
90
54
  * You should have received a copy of the GNU Lesser General Public License
91
55
  * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
92
56
  */
93
- var execa_1 = __importDefault(require("execa"));
94
- var fs = __importStar(require("fs"));
95
- var path = __importStar(require("path"));
96
- var rimraf_1 = __importDefault(require("rimraf"));
97
- var tmp = __importStar(require("tmp"));
98
- var lookpath_1 = require("lookpath");
99
- var tmpDir = tmp.dirSync({});
100
- var i = 0;
101
- process.on('exit', function () {
57
+ const execa_1 = __importDefault(require("execa"));
58
+ const fs = __importStar(require("fs"));
59
+ const path = __importStar(require("path"));
60
+ const rimraf_1 = __importDefault(require("rimraf"));
61
+ const tmp = __importStar(require("tmp"));
62
+ const lookpath_1 = require("lookpath");
63
+ const tmpDir = tmp.dirSync({});
64
+ let i = 0;
65
+ process.on('exit', () => {
102
66
  // Remove only on exit signal
103
67
  try {
104
68
  // Use rimraf because it is synchronous
@@ -106,97 +70,77 @@ process.on('exit', function () {
106
70
  }
107
71
  catch (error) { }
108
72
  });
109
- function getFfmpegPath() {
110
- return __awaiter(this, void 0, void 0, function () {
111
- var ffmpegPath, isExecutable;
112
- return __generator(this, function (_a) {
113
- switch (_a.label) {
114
- case 0:
115
- ffmpegPath = process.env['FFMPEG_PATH'];
116
- if (!ffmpegPath) return [3 /*break*/, 2];
117
- return [4 /*yield*/, fs.promises
118
- .access(ffmpegPath, fs.constants.X_OK)
119
- .then(function () { return true; })
120
- .catch(function () { return false; })];
121
- case 1:
122
- isExecutable = _a.sent();
123
- if (isExecutable) {
124
- return [2 /*return*/, ffmpegPath];
125
- }
126
- _a.label = 2;
127
- case 2: return [4 /*yield*/, (0, lookpath_1.lookpath)('ffmpeg', {
128
- include: [
129
- 'C:\\FFmpeg\\bin',
130
- 'C:\\FFmpeg\\FFmpeg\\bin',
131
- 'C:\\Program Files\\ffmpeg\\bin',
132
- 'C:\\Program Files (x86)\\ffmpeg\\bin',
133
- ],
134
- })];
135
- case 3:
136
- ffmpegPath = _a.sent();
137
- if (!ffmpegPath) {
138
- try {
139
- ffmpegPath = require('ffmpeg-static');
140
- }
141
- catch (error) { }
142
- }
143
- if (!ffmpegPath) {
144
- throw new Error('Error: FFMPEG not found. Please install ffmpeg or define the env FFMPEG_PATH or install ffmpeg-static');
145
- }
146
- return [2 /*return*/, ffmpegPath];
147
- }
148
- });
73
+ async function getFfmpegPath() {
74
+ let ffmpegPath = process.env['FFMPEG_PATH'];
75
+ if (ffmpegPath) {
76
+ const isExecutable = await fs.promises
77
+ .access(ffmpegPath, fs.constants.X_OK)
78
+ .then(() => true)
79
+ .catch(() => false);
80
+ if (isExecutable) {
81
+ return ffmpegPath;
82
+ }
83
+ }
84
+ ffmpegPath = await (0, lookpath_1.lookpath)('ffmpeg', {
85
+ include: [
86
+ 'C:\\FFmpeg\\bin',
87
+ 'C:\\FFmpeg\\FFmpeg\\bin',
88
+ 'C:\\Program Files\\ffmpeg\\bin',
89
+ 'C:\\Program Files (x86)\\ffmpeg\\bin',
90
+ ],
149
91
  });
92
+ if (!ffmpegPath) {
93
+ try {
94
+ ffmpegPath = require('ffmpeg-static');
95
+ }
96
+ catch (error) { }
97
+ }
98
+ if (!ffmpegPath) {
99
+ throw new Error('Error: FFMPEG not found. Please install ffmpeg or define the env FFMPEG_PATH or install ffmpeg-static');
100
+ }
101
+ return ffmpegPath;
150
102
  }
151
103
  /**
152
104
  * Convert a file to a compatible MP4-GIF for WhatsApp
153
105
  * @param inputBase64 Gif in base64 format
154
106
  * @returns base64 of a MP4-GIF for WhatsApp
155
107
  */
156
- function convertToMP4GIF(inputBase64) {
157
- return __awaiter(this, void 0, void 0, function () {
158
- var inputPath, outputPath, ffmpegPath, out, outputBase64;
159
- return __generator(this, function (_a) {
160
- switch (_a.label) {
161
- case 0:
162
- inputPath = path.join(tmpDir.name, "".concat(i++));
163
- outputPath = path.join(tmpDir.name, "".concat(i++, ".mp4"));
164
- if (inputBase64.includes(',')) {
165
- inputBase64 = inputBase64.split(',')[1];
166
- }
167
- fs.writeFileSync(inputPath, Buffer.from(inputBase64, 'base64'));
168
- return [4 /*yield*/, getFfmpegPath()];
169
- case 1:
170
- ffmpegPath = _a.sent();
171
- _a.label = 2;
172
- case 2:
173
- _a.trys.push([2, , 4, 5]);
174
- return [4 /*yield*/, (0, execa_1.default)(ffmpegPath, [
175
- '-i',
176
- inputPath,
177
- '-movflags',
178
- 'faststart',
179
- '-pix_fmt',
180
- 'yuv420p',
181
- '-vf',
182
- 'scale=trunc(iw/2)*2:trunc(ih/2)*2',
183
- '-f',
184
- 'mp4',
185
- outputPath,
186
- ])];
187
- case 3:
188
- out = _a.sent();
189
- if (out.exitCode === 0) {
190
- outputBase64 = fs.readFileSync(outputPath);
191
- return [2 /*return*/, 'data:video/mp4;base64,' + outputBase64.toString('base64')];
192
- }
193
- throw out.stderr;
194
- case 4:
195
- (0, rimraf_1.default)(inputPath, function () { return null; });
196
- (0, rimraf_1.default)(outputPath, function () { return null; });
197
- return [7 /*endfinally*/];
198
- case 5: return [2 /*return*/, ''];
199
- }
200
- });
201
- });
108
+ async function convertToMP4GIF(inputBase64) {
109
+ const inputPath = path.join(tmpDir.name, `${i++}`);
110
+ const outputPath = path.join(tmpDir.name, `${i++}.mp4`);
111
+ if (inputBase64.includes(',')) {
112
+ inputBase64 = inputBase64.split(',')[1];
113
+ }
114
+ fs.writeFileSync(inputPath, Buffer.from(inputBase64, 'base64'));
115
+ /**
116
+ * fluent-ffmpeg is a good alternative,
117
+ * but to work with MP4 you must use fisical file or ffmpeg will not work
118
+ * Because of that, I made the choice to use temporary file
119
+ */
120
+ const ffmpegPath = await getFfmpegPath();
121
+ try {
122
+ const out = await (0, execa_1.default)(ffmpegPath, [
123
+ '-i',
124
+ inputPath,
125
+ '-movflags',
126
+ 'faststart',
127
+ '-pix_fmt',
128
+ 'yuv420p',
129
+ '-vf',
130
+ 'scale=trunc(iw/2)*2:trunc(ih/2)*2',
131
+ '-f',
132
+ 'mp4',
133
+ outputPath,
134
+ ]);
135
+ if (out.exitCode === 0) {
136
+ const outputBase64 = fs.readFileSync(outputPath);
137
+ return 'data:video/mp4;base64,' + outputBase64.toString('base64');
138
+ }
139
+ throw out.stderr;
140
+ }
141
+ finally {
142
+ (0, rimraf_1.default)(inputPath, () => null);
143
+ (0, rimraf_1.default)(outputPath, () => null);
144
+ }
145
+ return '';
202
146
  }
@@ -17,9 +17,9 @@ exports.defaultLogger = exports.formatLabelSession = void 0;
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- var winston_1 = require("winston");
21
- exports.formatLabelSession = (0, winston_1.format)(function (info, opts) {
22
- var parts = [];
20
+ const winston_1 = require("winston");
21
+ exports.formatLabelSession = (0, winston_1.format)((info, opts) => {
22
+ const parts = [];
23
23
  if (info.session) {
24
24
  parts.push(info.session);
25
25
  delete info.session;
@@ -29,8 +29,8 @@ exports.formatLabelSession = (0, winston_1.format)(function (info, opts) {
29
29
  delete info.type;
30
30
  }
31
31
  if (parts.length) {
32
- var prefix = parts.join(':');
33
- info.message = "[".concat(prefix, "] ").concat(info.message);
32
+ let prefix = parts.join(':');
33
+ info.message = `[${prefix}] ${info.message}`;
34
34
  }
35
35
  return info;
36
36
  });
@@ -17,7 +17,7 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.upToDate = upToDate;
20
- var VPAT = /^\d+(\.\d+){0,2}$/;
20
+ const VPAT = /^\d+(\.\d+){0,2}$/;
21
21
  /**
22
22
  * Compares two versions
23
23
  * @return true if local is up to date, false otherwise
@@ -30,15 +30,15 @@ function upToDate(local, remote) {
30
30
  if (local == remote)
31
31
  return true;
32
32
  if (VPAT.test(local) && VPAT.test(remote)) {
33
- var lparts = local.split('.');
33
+ const lparts = local.split('.');
34
34
  while (lparts.length < 3)
35
35
  lparts.push('0');
36
- var rparts = remote.split('.');
36
+ const rparts = remote.split('.');
37
37
  while (rparts.length < 3)
38
38
  rparts.push('0');
39
- for (var i = 0; i < 3; i++) {
40
- var l = parseInt(lparts[i], 10);
41
- var r = parseInt(rparts[i], 10);
39
+ for (let i = 0; i < 3; i++) {
40
+ const l = parseInt(lparts[i], 10);
41
+ const r = parseInt(rparts[i], 10);
42
42
  if (l === r)
43
43
  continue;
44
44
  return l > r;
@@ -18,5 +18,5 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.sleep = sleep;
20
20
  function sleep(time) {
21
- return new Promise(function (resolve) { return setTimeout(resolve, time); });
21
+ return new Promise((resolve) => setTimeout(resolve, time));
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wppconnect-team/wppconnect",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "WPPConnect is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination... 😀🤔💭",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -58,10 +58,10 @@
58
58
  "@babel/core": "^7.29.0",
59
59
  "@babel/eslint-parser": "^7.28.6",
60
60
  "@babel/eslint-plugin": "^7.27.1",
61
- "@babel/preset-env": "^7.29.2",
62
- "@commitlint/cli": "^20.5.0",
63
- "@commitlint/config-conventional": "^20.5.0",
64
- "@commitlint/cz-commitlint": "^20.5.1",
61
+ "@babel/preset-env": "^7.29.3",
62
+ "@commitlint/cli": "^20.5.3",
63
+ "@commitlint/config-conventional": "^20.5.3",
64
+ "@commitlint/cz-commitlint": "^20.5.3",
65
65
  "@eslint/js": "^10.0.1",
66
66
  "@types/atob": "^2.1.4",
67
67
  "@types/mime-types": "^3.0.1",
@@ -76,7 +76,7 @@
76
76
  "conventional-changelog-cli": "^5.0.0",
77
77
  "eslint": "10.2.1",
78
78
  "eslint-config-prettier": "^10.1.8",
79
- "@tony.ganchev/eslint-plugin-header": "^3.4.3",
79
+ "@tony.ganchev/eslint-plugin-header": "^3.4.4",
80
80
  "eslint-plugin-prettier": "^5.5.5",
81
81
  "globals": "^17.5.0",
82
82
  "husky": "^9.1.7",
@@ -94,10 +94,10 @@
94
94
  "webpack-cli": "^6.0.1"
95
95
  },
96
96
  "dependencies": {
97
- "@wppconnect/wa-js": "^4.0.0",
97
+ "@wppconnect/wa-js": "^4.1.0",
98
98
  "@wppconnect/wa-version": "^1.5.3829",
99
99
  "atob": "^2.1.2",
100
- "axios": "^1.15.0",
100
+ "axios": "^1.16.0",
101
101
  "boxen": "^5.1.2",
102
102
  "catch-exit": "^2.0.0",
103
103
  "chalk": "~4.1.2",