@wppconnect-team/wppconnect 1.41.3 → 2.0.1

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 (47) 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/exposed.enum.d.ts +2 -1
  7. package/dist/api/helpers/exposed.enum.js +1 -0
  8. package/dist/api/helpers/file-to-base64.js +30 -81
  9. package/dist/api/helpers/filename-from-mimetype.js +4 -4
  10. package/dist/api/helpers/scrape-img-qr.js +37 -86
  11. package/dist/api/helpers/scrape-login.js +12 -57
  12. package/dist/api/helpers/select-sticker.js +35 -100
  13. package/dist/api/layers/business.layer.js +29 -134
  14. package/dist/api/layers/catalog.layer.js +59 -210
  15. package/dist/api/layers/community.layer.js +29 -120
  16. package/dist/api/layers/controls.layer.js +62 -262
  17. package/dist/api/layers/group.layer.js +126 -391
  18. package/dist/api/layers/host.layer.js +348 -702
  19. package/dist/api/layers/labels.layer.js +35 -131
  20. package/dist/api/layers/listener.layer.d.ts +9 -1
  21. package/dist/api/layers/listener.layer.js +392 -491
  22. package/dist/api/layers/newsletter.layer.js +20 -89
  23. package/dist/api/layers/profile.layer.js +73 -184
  24. package/dist/api/layers/retriever.layer.js +163 -468
  25. package/dist/api/layers/sender.layer.js +554 -1094
  26. package/dist/api/layers/status.layer.js +80 -179
  27. package/dist/api/layers/ui.layer.js +32 -129
  28. package/dist/api/model/enum/definitions.js +1 -1
  29. package/dist/api/whatsapp.js +200 -426
  30. package/dist/config/WAuserAgente.js +1 -1
  31. package/dist/config/create-config.js +1 -1
  32. package/dist/config/puppeteer.config.js +1 -1
  33. package/dist/controllers/auth.js +42 -110
  34. package/dist/controllers/browser.js +251 -411
  35. package/dist/controllers/initializer.js +171 -265
  36. package/dist/controllers/websocket.js +29 -28
  37. package/dist/controllers/welcome.js +38 -88
  38. package/dist/lib/wapi/wapi.js +1 -1
  39. package/dist/token-store/fileTokenStore.js +83 -173
  40. package/dist/token-store/isValidSessionToken.js +2 -2
  41. package/dist/token-store/isValidTokenStore.js +2 -2
  42. package/dist/token-store/memoryTokenStore.js +11 -14
  43. package/dist/utils/ffmpeg.js +75 -131
  44. package/dist/utils/logger.js +5 -5
  45. package/dist/utils/semver.js +6 -6
  46. package/dist/utils/sleep.js +1 -1
  47. package/package.json +8 -8
@@ -17,5 +17,5 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.useragentOverride = void 0;
20
- var useragentOverride = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36';
20
+ const useragentOverride = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36';
21
21
  exports.useragentOverride = useragentOverride;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultOptions = void 0;
4
- var logger_1 = require("../utils/logger");
4
+ const logger_1 = require("../utils/logger");
5
5
  exports.defaultOptions = {
6
6
  folderNameToken: './tokens',
7
7
  headless: true,
@@ -17,7 +17,7 @@
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.puppeteerConfig = void 0;
20
- var puppeteerConfig = {
20
+ const puppeteerConfig = {
21
21
  whatsappUrl: 'https://web.whatsapp.com',
22
22
  chromiumArgs: [
23
23
  // `--app=${WAUrl}`,
@@ -48,131 +48,63 @@ var __importStar = (this && this.__importStar) || (function () {
48
48
  return result;
49
49
  };
50
50
  })();
51
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
52
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
- return new (P || (P = Promise))(function (resolve, reject) {
54
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
55
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
56
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
57
- step((generator = generator.apply(thisArg, _arguments || [])).next());
58
- });
59
- };
60
- var __generator = (this && this.__generator) || function (thisArg, body) {
61
- 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);
62
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
- function verb(n) { return function (v) { return step([n, v]); }; }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
67
- 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;
68
- if (y = 0, t) op = [op[0] & 2, t.value];
69
- switch (op[0]) {
70
- case 0: case 1: t = op; break;
71
- case 4: _.label++; return { value: op[1], done: false };
72
- case 5: _.label++; y = op[1]; op = [0]; continue;
73
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
74
- default:
75
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
76
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
77
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
78
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
79
- if (t[2]) _.ops.pop();
80
- _.trys.pop(); continue;
81
- }
82
- op = body.call(thisArg, _);
83
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
84
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
- }
86
- };
87
51
  Object.defineProperty(exports, "__esModule", { value: true });
88
52
  exports.isConnectingToPhone = exports.isInsideChat = exports.needsToScan = exports.isAuthenticated = exports.getInterfaceStatus = void 0;
89
53
  exports.asciiQr = asciiQr;
90
- var qrcode = __importStar(require("qrcode-terminal"));
91
- var getInterfaceStatus = function (waPage) { return __awaiter(void 0, void 0, void 0, function () {
92
- return __generator(this, function (_a) {
93
- switch (_a.label) {
94
- case 0: return [4 /*yield*/, waPage
95
- .waitForFunction(function () {
96
- var _a, _b;
97
- var elLoginWrapper = document.querySelector('body > div > div > .landing-wrapper');
98
- var elQRCodeCanvas = document.querySelector('canvas');
99
- if (elLoginWrapper && elQRCodeCanvas) {
100
- return 'UNPAIRED';
101
- }
102
- var streamStatus = (_b = (_a = WPP === null || WPP === void 0 ? void 0 : WPP.whatsapp) === null || _a === void 0 ? void 0 : _a.Stream) === null || _b === void 0 ? void 0 : _b.displayInfo;
103
- if (['PAIRING', 'RESUMING', 'SYNCING'].includes(streamStatus)) {
104
- return 'PAIRING';
105
- }
106
- var elChat = document.querySelector('.app,.two');
107
- if (elChat && elChat.attributes && elChat.tabIndex) {
108
- return 'CONNECTED';
109
- }
110
- return false;
111
- }, {
112
- timeout: 0,
113
- polling: 100,
114
- })
115
- .then(function (element) { return __awaiter(void 0, void 0, void 0, function () {
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0: return [4 /*yield*/, element.evaluate(function (a) { return a; })];
119
- case 1: return [2 /*return*/, (_a.sent())];
120
- }
121
- });
122
- }); })
123
- .catch(function () { return null; })];
124
- case 1: return [2 /*return*/, _a.sent()];
54
+ const qrcode = __importStar(require("qrcode-terminal"));
55
+ const getInterfaceStatus = async (waPage) => {
56
+ return await waPage
57
+ .waitForFunction(() => {
58
+ const elLoginWrapper = document.querySelector('body > div > div > .landing-wrapper');
59
+ const elQRCodeCanvas = document.querySelector('canvas');
60
+ if (elLoginWrapper && elQRCodeCanvas) {
61
+ return 'UNPAIRED';
125
62
  }
126
- });
127
- }); };
63
+ const streamStatus = WPP?.whatsapp?.Stream?.displayInfo;
64
+ if (['PAIRING', 'RESUMING', 'SYNCING'].includes(streamStatus)) {
65
+ return 'PAIRING';
66
+ }
67
+ const elChat = document.querySelector('.app,.two');
68
+ if (elChat && elChat.attributes && elChat.tabIndex) {
69
+ return 'CONNECTED';
70
+ }
71
+ return false;
72
+ }, {
73
+ timeout: 0,
74
+ polling: 100,
75
+ })
76
+ .then(async (element) => {
77
+ return (await element.evaluate((a) => a));
78
+ })
79
+ .catch(() => null);
80
+ };
128
81
  exports.getInterfaceStatus = getInterfaceStatus;
129
82
  /**
130
83
  * Validates if client is authenticated
131
84
  * @returns true if is authenticated, false otherwise
132
85
  * @param waPage
133
86
  */
134
- var isAuthenticated = function (waPage) {
135
- return waPage.evaluate(function () { return WPP.conn.isRegistered(); });
87
+ const isAuthenticated = (waPage) => {
88
+ return waPage.evaluate(() => WPP.conn.isRegistered());
136
89
  };
137
90
  exports.isAuthenticated = isAuthenticated;
138
- var needsToScan = function (waPage) { return __awaiter(void 0, void 0, void 0, function () {
139
- var connected;
140
- return __generator(this, function (_a) {
141
- switch (_a.label) {
142
- case 0: return [4 /*yield*/, (0, exports.isAuthenticated)(waPage)];
143
- case 1:
144
- connected = _a.sent();
145
- return [2 /*return*/, !connected];
146
- }
147
- });
148
- }); };
91
+ const needsToScan = async (waPage) => {
92
+ const connected = await (0, exports.isAuthenticated)(waPage);
93
+ return !connected;
94
+ };
149
95
  exports.needsToScan = needsToScan;
150
- var isInsideChat = function (waPage) { return __awaiter(void 0, void 0, void 0, function () {
151
- return __generator(this, function (_a) {
152
- switch (_a.label) {
153
- case 0: return [4 /*yield*/, waPage.evaluate(function () { return WPP.conn.isMainReady(); })];
154
- case 1: return [2 /*return*/, _a.sent()];
155
- }
156
- });
157
- }); };
96
+ const isInsideChat = async (waPage) => {
97
+ return await waPage.evaluate(() => WPP.conn.isMainReady());
98
+ };
158
99
  exports.isInsideChat = isInsideChat;
159
- var isConnectingToPhone = function (waPage) { return __awaiter(void 0, void 0, void 0, function () {
160
- return __generator(this, function (_a) {
161
- switch (_a.label) {
162
- case 0: return [4 /*yield*/, waPage.evaluate(function () { return WPP.conn.isMainLoaded() && !WPP.conn.isMainReady(); })];
163
- case 1: return [2 /*return*/, _a.sent()];
164
- }
165
- });
166
- }); };
100
+ const isConnectingToPhone = async (waPage) => {
101
+ return await waPage.evaluate(() => WPP.conn.isMainLoaded() && !WPP.conn.isMainReady());
102
+ };
167
103
  exports.isConnectingToPhone = isConnectingToPhone;
168
- function asciiQr(code) {
169
- return __awaiter(this, void 0, void 0, function () {
170
- return __generator(this, function (_a) {
171
- return [2 /*return*/, new Promise(function (resolve) {
172
- qrcode.generate(code, { small: true }, function (qrcode) {
173
- resolve(qrcode);
174
- });
175
- })];
104
+ async function asciiQr(code) {
105
+ return new Promise((resolve) => {
106
+ qrcode.generate(code, { small: true }, (qrcode) => {
107
+ resolve(qrcode);
176
108
  });
177
109
  });
178
110
  }