@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
@@ -15,67 +15,15 @@
15
15
  * You should have received a copy of the GNU Lesser General Public License
16
16
  * along with WPPConnect. If not, see <https://www.gnu.org/licenses/>.
17
17
  */
18
- var __extends = (this && this.__extends) || (function () {
19
- var extendStatics = function (d, b) {
20
- extendStatics = Object.setPrototypeOf ||
21
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23
- return extendStatics(d, b);
24
- };
25
- return function (d, b) {
26
- if (typeof b !== "function" && b !== null)
27
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
28
- extendStatics(d, b);
29
- function __() { this.constructor = d; }
30
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31
- };
32
- })();
33
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
34
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
- return new (P || (P = Promise))(function (resolve, reject) {
36
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
37
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
38
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39
- step((generator = generator.apply(thisArg, _arguments || [])).next());
40
- });
41
- };
42
- var __generator = (this && this.__generator) || function (thisArg, body) {
43
- 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);
44
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
45
- function verb(n) { return function (v) { return step([n, v]); }; }
46
- function step(op) {
47
- if (f) throw new TypeError("Generator is already executing.");
48
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
49
- 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;
50
- if (y = 0, t) op = [op[0] & 2, t.value];
51
- switch (op[0]) {
52
- case 0: case 1: t = op; break;
53
- case 4: _.label++; return { value: op[1], done: false };
54
- case 5: _.label++; y = op[1]; op = [0]; continue;
55
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
56
- default:
57
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
58
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
59
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
60
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
61
- if (t[2]) _.ops.pop();
62
- _.trys.pop(); continue;
63
- }
64
- op = body.call(thisArg, _);
65
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
66
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
67
- }
68
- };
69
18
  Object.defineProperty(exports, "__esModule", { value: true });
70
19
  exports.LabelsLayer = void 0;
71
- var helpers_1 = require("../helpers");
72
- var catalog_layer_1 = require("./catalog.layer");
73
- var LabelsLayer = /** @class */ (function (_super) {
74
- __extends(LabelsLayer, _super);
75
- function LabelsLayer(page, session, options) {
76
- var _this = _super.call(this, page, session, options) || this;
77
- _this.page = page;
78
- return _this;
20
+ const helpers_1 = require("../helpers");
21
+ const catalog_layer_1 = require("./catalog.layer");
22
+ class LabelsLayer extends catalog_layer_1.CatalogLayer {
23
+ page;
24
+ constructor(page, session, options) {
25
+ super(page, session, options);
26
+ this.page = page;
79
27
  }
80
28
  /**
81
29
  * Create New Label
@@ -92,19 +40,11 @@ var LabelsLayer = /** @class */ (function (_super) {
92
40
  * @param name Name of label
93
41
  * @param options options of label
94
42
  */
95
- LabelsLayer.prototype.addNewLabel = function (name, options) {
96
- return __awaiter(this, void 0, void 0, function () {
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
100
- var name = _a.name, options = _a.options;
101
- WPP.labels.addNewLabel(name, options);
102
- }, { name: name, options: options })];
103
- case 1: return [2 /*return*/, _a.sent()];
104
- }
105
- });
106
- });
107
- };
43
+ async addNewLabel(name, options) {
44
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ name, options }) => {
45
+ WPP.labels.addNewLabel(name, options);
46
+ }, { name, options });
47
+ }
108
48
  /**
109
49
  * Add or delete label of chatId
110
50
  * @category Labels
@@ -121,19 +61,11 @@ var LabelsLayer = /** @class */ (function (_super) {
121
61
  * @param chatIds ChatIds
122
62
  * @param options options to remove or add
123
63
  */
124
- LabelsLayer.prototype.addOrRemoveLabels = function (chatIds, options) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
129
- var chatIds = _a.chatIds, options = _a.options;
130
- WPP.labels.addOrRemoveLabels(chatIds, options);
131
- }, { chatIds: chatIds, options: options })];
132
- case 1: return [2 /*return*/, _a.sent()];
133
- }
134
- });
135
- });
136
- };
64
+ async addOrRemoveLabels(chatIds, options) {
65
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ chatIds, options }) => {
66
+ WPP.labels.addOrRemoveLabels(chatIds, options);
67
+ }, { chatIds, options });
68
+ }
137
69
  /**
138
70
  * Get all Labels
139
71
  *
@@ -142,13 +74,9 @@ var LabelsLayer = /** @class */ (function (_super) {
142
74
  * client.getAllLabels();
143
75
  * ```
144
76
  */
145
- LabelsLayer.prototype.getAllLabels = function () {
146
- return __awaiter(this, void 0, void 0, function () {
147
- return __generator(this, function (_a) {
148
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function () { return WPP.labels.getAllLabels(); })];
149
- });
150
- });
151
- };
77
+ async getAllLabels() {
78
+ return (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.labels.getAllLabels());
79
+ }
152
80
  /**
153
81
  * Get Label by id
154
82
  * @category Labels
@@ -159,19 +87,11 @@ var LabelsLayer = /** @class */ (function (_super) {
159
87
  * client.getLabelById('1');
160
88
  * ```
161
89
  */
162
- LabelsLayer.prototype.getLabelById = function (id) {
163
- return __awaiter(this, void 0, void 0, function () {
164
- return __generator(this, function (_a) {
165
- switch (_a.label) {
166
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
167
- var id = _a.id;
168
- WPP.labels.getLabelById(id);
169
- }, { id: id })];
170
- case 1: return [2 /*return*/, _a.sent()];
171
- }
172
- });
173
- });
174
- };
90
+ async getLabelById(id) {
91
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ id }) => {
92
+ WPP.labels.getLabelById(id);
93
+ }, { id });
94
+ }
175
95
  /**
176
96
  * Delete all Labels
177
97
  * @category Labels
@@ -181,18 +101,11 @@ var LabelsLayer = /** @class */ (function (_super) {
181
101
  * client.deleteAllLabels();
182
102
  * ```
183
103
  */
184
- LabelsLayer.prototype.deleteAllLabels = function () {
185
- return __awaiter(this, void 0, void 0, function () {
186
- return __generator(this, function (_a) {
187
- switch (_a.label) {
188
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
189
- WPP.labels.deleteAllLabels();
190
- })];
191
- case 1: return [2 /*return*/, _a.sent()];
192
- }
193
- });
104
+ async deleteAllLabels() {
105
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => {
106
+ WPP.labels.deleteAllLabels();
194
107
  });
195
- };
108
+ }
196
109
  /**
197
110
  * Add or delete label of chatId
198
111
  * @category Labels
@@ -203,19 +116,10 @@ var LabelsLayer = /** @class */ (function (_super) {
203
116
  * ```
204
117
  * @param id Id or string to labels to delete
205
118
  */
206
- LabelsLayer.prototype.deleteLabel = function (id) {
207
- return __awaiter(this, void 0, void 0, function () {
208
- return __generator(this, function (_a) {
209
- switch (_a.label) {
210
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
211
- var id = _a.id;
212
- WPP.labels.deleteLabel(id);
213
- }, { id: id })];
214
- case 1: return [2 /*return*/, _a.sent()];
215
- }
216
- });
217
- });
218
- };
219
- return LabelsLayer;
220
- }(catalog_layer_1.CatalogLayer));
119
+ async deleteLabel(id) {
120
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ id }) => {
121
+ WPP.labels.deleteLabel(id);
122
+ }, { id });
123
+ }
124
+ }
221
125
  exports.LabelsLayer = LabelsLayer;
@@ -1,4 +1,4 @@
1
- import { MsgKey } from '@wppconnect/wa-js/dist/whatsapp';
1
+ import { BackendEventName, MsgKey } from '@wppconnect/wa-js/dist/whatsapp';
2
2
  import { StreamInfo, StreamMode } from '@wppconnect/wa-js/dist/whatsapp/enums';
3
3
  import { Page } from 'puppeteer';
4
4
  import { CreateConfig } from '../../config/create-config';
@@ -89,6 +89,14 @@ export declare class ListenerLayer extends ProfileLayer {
89
89
  onStreamInfoChanged(callback: (info: StreamInfo) => void): {
90
90
  dispose: () => void;
91
91
  };
92
+ /**
93
+ * @event Listens to all internal WhatsApp Web BackendEventBus events.
94
+ * The first argument is the event name; additional arguments vary by event.
95
+ * @returns Disposable object to stop the listening
96
+ */
97
+ onBackendEvent(callback: (eventName: BackendEventName, ...args: any[]) => void): {
98
+ dispose: () => void;
99
+ };
92
100
  /**
93
101
  * @event Listens to interface mode change See {@link InterfaceState} and {@link InterfaceMode} for details
94
102
  * @returns Disposable object to stop the listening