@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,155 +15,65 @@
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.GroupLayer = void 0;
71
- var helpers_1 = require("../helpers");
72
- var retriever_layer_1 = require("./retriever.layer");
73
- var GroupLayer = /** @class */ (function (_super) {
74
- __extends(GroupLayer, _super);
75
- function GroupLayer(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 retriever_layer_1 = require("./retriever.layer");
22
+ class GroupLayer extends retriever_layer_1.RetrieverLayer {
23
+ page;
24
+ constructor(page, session, options) {
25
+ super(page, session, options);
26
+ this.page = page;
79
27
  }
80
28
  /**
81
29
  * Removes the host device from the group
82
30
  * @category Group
83
31
  * @param groupId group id
84
32
  */
85
- GroupLayer.prototype.leaveGroup = function (groupId) {
86
- return __awaiter(this, void 0, void 0, function () {
87
- return __generator(this, function (_a) {
88
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (groupId) { return WPP.group.leave(groupId); }, groupId)];
89
- });
90
- });
91
- };
33
+ async leaveGroup(groupId) {
34
+ return (0, helpers_1.evaluateAndReturn)(this.page, (groupId) => WPP.group.leave(groupId), groupId);
35
+ }
92
36
  /**
93
37
  * Retrieves group members as [Id] objects
94
38
  * @category Group
95
39
  * @param groupId group id
96
40
  */
97
- GroupLayer.prototype.getGroupMembersIds = function (groupId) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- return __generator(this, function (_a) {
100
- return [2 /*return*/, (0, helpers_1.evaluateAndReturn)(this.page, function (groupId) {
101
- return Promise.resolve(WPP.group.getParticipants(groupId)).then(function (participants) { return participants.map(function (p) { return p.id; }); });
102
- }, groupId)];
103
- });
104
- });
105
- };
41
+ async getGroupMembersIds(groupId) {
42
+ return (0, helpers_1.evaluateAndReturn)(this.page, (groupId) => Promise.resolve(WPP.group.getParticipants(groupId)).then((participants) => participants.map((p) => p.id)), groupId);
43
+ }
106
44
  /**
107
45
  * Returns current group members as [Contact] objects
108
46
  * For previous members, see `groupMetadata.pastParticipants`.
109
47
  * @category Group
110
48
  * @param groupId
111
49
  */
112
- GroupLayer.prototype.getGroupMembers = function (groupId) {
113
- return __awaiter(this, void 0, void 0, function () {
114
- var membersIds, actions;
115
- var _this = this;
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0: return [4 /*yield*/, this.getGroupMembersIds(groupId)];
119
- case 1:
120
- membersIds = _a.sent();
121
- actions = membersIds.map(function (memberId) {
122
- return _this.getContact(memberId._serialized);
123
- });
124
- return [2 /*return*/, Promise.all(actions)];
125
- }
126
- });
50
+ async getGroupMembers(groupId) {
51
+ const membersIds = await this.getGroupMembersIds(groupId);
52
+ const actions = membersIds.map((memberId) => {
53
+ return this.getContact(memberId._serialized);
127
54
  });
128
- };
55
+ return Promise.all(actions);
56
+ }
129
57
  /**
130
58
  * Generates group-invite link
131
59
  * @category Group
132
60
  * @param chatId
133
61
  * @returns Invitation link
134
62
  */
135
- GroupLayer.prototype.getGroupInviteLink = function (chatId) {
136
- return __awaiter(this, void 0, void 0, function () {
137
- var code;
138
- return __generator(this, function (_a) {
139
- switch (_a.label) {
140
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WPP.group.getInviteCode(chatId); }, chatId)];
141
- case 1:
142
- code = _a.sent();
143
- return [2 /*return*/, "https://chat.whatsapp.com/".concat(code)];
144
- }
145
- });
146
- });
147
- };
63
+ async getGroupInviteLink(chatId) {
64
+ const code = await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WPP.group.getInviteCode(chatId), chatId);
65
+ return `https://chat.whatsapp.com/${code}`;
66
+ }
148
67
  /**
149
68
  * Revokes group-invite link and generates a new one.
150
69
  * @category Group
151
70
  * @param chatId
152
71
  * @returns Invitation link
153
72
  */
154
- GroupLayer.prototype.revokeGroupInviteLink = function (chatId) {
155
- return __awaiter(this, void 0, void 0, function () {
156
- var code;
157
- return __generator(this, function (_a) {
158
- switch (_a.label) {
159
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) { return WPP.group.revokeInviteCode(chatId); }, chatId)];
160
- case 1:
161
- code = _a.sent();
162
- return [2 /*return*/, "https://chat.whatsapp.com/".concat(code)];
163
- }
164
- });
165
- });
166
- };
73
+ async revokeGroupInviteLink(chatId) {
74
+ const code = await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => WPP.group.revokeInviteCode(chatId), chatId);
75
+ return `https://chat.whatsapp.com/${code}`;
76
+ }
167
77
  /**
168
78
  * Displays group info from an invitation link (or invitation ID)
169
79
  * @category Group
@@ -172,138 +82,69 @@ var GroupLayer = /** @class */ (function (_super) {
172
82
  * @example getGroupInfoFromInviteLink('https://chat.whatsapp.com/invite/CMJYfPFqRyE2GxrnkldYED')
173
83
  * @example getGroupInfoFromInviteLink('CMJYfPFqRyE2GxrnkldYED')
174
84
  */
175
- GroupLayer.prototype.getGroupInfoFromInviteLink = function (inviteCode) {
176
- return __awaiter(this, void 0, void 0, function () {
177
- return __generator(this, function (_a) {
178
- switch (_a.label) {
179
- case 0:
180
- inviteCode = inviteCode.replace('chat.whatsapp.com/', '');
181
- inviteCode = inviteCode.replace('invite/', '');
182
- inviteCode = inviteCode.replace('https://', '');
183
- inviteCode = inviteCode.replace('http://', '');
184
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (inviteCode) { return WPP.group.getGroupInfoFromInviteCode(inviteCode); }, inviteCode)];
185
- case 1: return [2 /*return*/, _a.sent()];
186
- }
187
- });
188
- });
189
- };
85
+ async getGroupInfoFromInviteLink(inviteCode) {
86
+ inviteCode = inviteCode.replace('chat.whatsapp.com/', '');
87
+ inviteCode = inviteCode.replace('invite/', '');
88
+ inviteCode = inviteCode.replace('https://', '');
89
+ inviteCode = inviteCode.replace('http://', '');
90
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (inviteCode) => WPP.group.getGroupInfoFromInviteCode(inviteCode), inviteCode);
91
+ }
190
92
  /**
191
93
  * Creates a new chat group
192
94
  * @category Group
193
95
  * @param groupName Group name
194
96
  * @param contacts Contacts that should be added.
195
97
  */
196
- GroupLayer.prototype.createGroup = function (groupName, contacts) {
197
- return __awaiter(this, void 0, void 0, function () {
198
- return __generator(this, function (_a) {
199
- switch (_a.label) {
200
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
201
- var groupName = _a.groupName, contacts = _a.contacts;
202
- return WPP.group.create(groupName, contacts, null);
203
- }, { groupName: groupName, contacts: contacts })];
204
- case 1: return [2 /*return*/, _a.sent()];
205
- }
206
- });
207
- });
208
- };
98
+ async createGroup(groupName, contacts) {
99
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupName, contacts }) => WPP.group.create(groupName, contacts, null), { groupName, contacts });
100
+ }
209
101
  /**
210
102
  * Removes participant from group
211
103
  * @category Group
212
104
  * @param groupId Chat id ('0000000000-00000000@g.us')
213
105
  * @param participantId Participant id'000000000000@c.us'
214
106
  */
215
- GroupLayer.prototype.removeParticipant = function (groupId, participantId) {
216
- return __awaiter(this, void 0, void 0, function () {
217
- return __generator(this, function (_a) {
218
- switch (_a.label) {
219
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
220
- var groupId = _a.groupId, participantId = _a.participantId;
221
- return WPP.group.removeParticipants(groupId, participantId);
222
- }, { groupId: groupId, participantId: participantId })];
223
- case 1: return [2 /*return*/, _a.sent()];
224
- }
225
- });
226
- });
227
- };
107
+ async removeParticipant(groupId, participantId) {
108
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, participantId }) => WPP.group.removeParticipants(groupId, participantId), { groupId, participantId });
109
+ }
228
110
  /**
229
111
  * Adds participant to Group
230
112
  * @category Group
231
113
  * @param groupId Chat id ('0000000000-00000000@g.us')
232
114
  * @param participantId Participant id'000000000000@c.us'
233
115
  */
234
- GroupLayer.prototype.addParticipant = function (groupId, participantId) {
235
- return __awaiter(this, void 0, void 0, function () {
236
- return __generator(this, function (_a) {
237
- switch (_a.label) {
238
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
239
- var groupId = _a.groupId, participantId = _a.participantId;
240
- return WPP.group.addParticipants(groupId, participantId);
241
- }, { groupId: groupId, participantId: participantId })];
242
- case 1: return [2 /*return*/, _a.sent()];
243
- }
244
- });
245
- });
246
- };
116
+ async addParticipant(groupId, participantId) {
117
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, participantId }) => WPP.group.addParticipants(groupId, participantId), { groupId, participantId });
118
+ }
247
119
  /**
248
120
  * Promotes participant as Admin in given group
249
121
  * @category Group
250
122
  * @param groupId Chat id ('0000000000-00000000@g.us')
251
123
  * @param participantId Participant id'000000000000@c.us'
252
124
  */
253
- GroupLayer.prototype.promoteParticipant = function (groupId, participantId) {
254
- return __awaiter(this, void 0, void 0, function () {
255
- return __generator(this, function (_a) {
256
- switch (_a.label) {
257
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
258
- var groupId = _a.groupId, participantId = _a.participantId;
259
- return WPP.group.promoteParticipants(groupId, participantId);
260
- }, { groupId: groupId, participantId: participantId })];
261
- case 1:
262
- _a.sent();
263
- return [2 /*return*/, true];
264
- }
265
- });
266
- });
267
- };
125
+ async promoteParticipant(groupId, participantId) {
126
+ await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, participantId }) => WPP.group.promoteParticipants(groupId, participantId), { groupId, participantId });
127
+ return true;
128
+ }
268
129
  /**
269
130
  * Demotes admin privileges of participant
270
131
  * @category Group
271
132
  * @param groupId Chat id ('0000000000-00000000@g.us')
272
133
  * @param participantId Participant id'000000000000@c.us'
273
134
  */
274
- GroupLayer.prototype.demoteParticipant = function (groupId, participantId) {
275
- return __awaiter(this, void 0, void 0, function () {
276
- return __generator(this, function (_a) {
277
- switch (_a.label) {
278
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
279
- var groupId = _a.groupId, participantId = _a.participantId;
280
- return WPP.group.demoteParticipants(groupId, participantId);
281
- }, { groupId: groupId, participantId: participantId })];
282
- case 1: return [2 /*return*/, _a.sent()];
283
- }
284
- });
285
- });
286
- };
135
+ async demoteParticipant(groupId, participantId) {
136
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, participantId }) => WPP.group.demoteParticipants(groupId, participantId), { groupId, participantId });
137
+ return true;
138
+ }
287
139
  /**
288
140
  * Retrieves group admins
289
141
  * @category Group
290
142
  * @param chatId Group/Chat id ('0000000000-00000000@g.us')
291
143
  */
292
- GroupLayer.prototype.getGroupAdmins = function (chatId) {
293
- return __awaiter(this, void 0, void 0, function () {
294
- var participants;
295
- return __generator(this, function (_a) {
296
- switch (_a.label) {
297
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (chatId) {
298
- return Promise.resolve(WPP.group.getParticipants(chatId)).then(function (participants) { return participants.map(function (p) { return p.toJSON(); }); });
299
- }, chatId)];
300
- case 1:
301
- participants = _a.sent();
302
- return [2 /*return*/, participants.filter(function (p) { return p.isAdmin; }).map(function (p) { return p.id; })];
303
- }
304
- });
305
- });
306
- };
144
+ async getGroupAdmins(chatId) {
145
+ const participants = await (0, helpers_1.evaluateAndReturn)(this.page, (chatId) => Promise.resolve(WPP.group.getParticipants(chatId)).then((participants) => participants.map((p) => p.toJSON())), chatId);
146
+ return participants.filter((p) => p.isAdmin).map((p) => p.id);
147
+ }
307
148
  /**
308
149
  * Join a group with an invite code or link
309
150
  * @category Group
@@ -311,21 +152,13 @@ var GroupLayer = /** @class */ (function (_super) {
311
152
  * @example joinGroup('https://chat.whatsapp.com/invite/CMJYfPFqRyE2GxrnkldYED')
312
153
  * @example joinGroup('CMJYfPFqRyE2GxrnkldYED')
313
154
  */
314
- GroupLayer.prototype.joinGroup = function (inviteCode) {
315
- return __awaiter(this, void 0, void 0, function () {
316
- return __generator(this, function (_a) {
317
- switch (_a.label) {
318
- case 0:
319
- inviteCode = inviteCode.replace('chat.whatsapp.com/', '');
320
- inviteCode = inviteCode.replace('invite/', '');
321
- inviteCode = inviteCode.replace('https://', '');
322
- inviteCode = inviteCode.replace('http://', '');
323
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (inviteCode) { return WPP.group.join(inviteCode); }, inviteCode)];
324
- case 1: return [2 /*return*/, _a.sent()];
325
- }
326
- });
327
- });
328
- };
155
+ async joinGroup(inviteCode) {
156
+ inviteCode = inviteCode.replace('chat.whatsapp.com/', '');
157
+ inviteCode = inviteCode.replace('invite/', '');
158
+ inviteCode = inviteCode.replace('https://', '');
159
+ inviteCode = inviteCode.replace('http://', '');
160
+ return await (0, helpers_1.evaluateAndReturn)(this.page, (inviteCode) => WPP.group.join(inviteCode), inviteCode);
161
+ }
329
162
  /**
330
163
  * Set group description (if allowed)
331
164
  * @category Group
@@ -333,19 +166,9 @@ var GroupLayer = /** @class */ (function (_super) {
333
166
  * @param description New group description
334
167
  * @returns empty object
335
168
  */
336
- GroupLayer.prototype.setGroupDescription = function (groupId, description) {
337
- return __awaiter(this, void 0, void 0, function () {
338
- return __generator(this, function (_a) {
339
- switch (_a.label) {
340
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
341
- var groupId = _a.groupId, description = _a.description;
342
- return WPP.group.setDescription(groupId, description);
343
- }, { groupId: groupId, description: description })];
344
- case 1: return [2 /*return*/, _a.sent()];
345
- }
346
- });
347
- });
348
- };
169
+ async setGroupDescription(groupId, description) {
170
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, description }) => WPP.group.setDescription(groupId, description), { groupId, description });
171
+ }
349
172
  /**
350
173
  * Set group subject (if allowed)
351
174
  * @category Group
@@ -353,19 +176,9 @@ var GroupLayer = /** @class */ (function (_super) {
353
176
  * @param title New group subject
354
177
  * @returns empty object
355
178
  */
356
- GroupLayer.prototype.setGroupSubject = function (groupId, title) {
357
- return __awaiter(this, void 0, void 0, function () {
358
- return __generator(this, function (_a) {
359
- switch (_a.label) {
360
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
361
- var groupId = _a.groupId, title = _a.title;
362
- return WPP.group.setSubject(groupId, title);
363
- }, { groupId: groupId, title: title })];
364
- case 1: return [2 /*return*/, _a.sent()];
365
- }
366
- });
367
- });
368
- };
179
+ async setGroupSubject(groupId, title) {
180
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, title }) => WPP.group.setSubject(groupId, title), { groupId, title });
181
+ }
369
182
  /**
370
183
  * Enable or disable group properties, see {@link GroupProperty for details}
371
184
  * @category Group
@@ -374,19 +187,9 @@ var GroupLayer = /** @class */ (function (_super) {
374
187
  * @param value true or false
375
188
  * @returns empty object
376
189
  */
377
- GroupLayer.prototype.setGroupProperty = function (groupId, property, value) {
378
- return __awaiter(this, void 0, void 0, function () {
379
- return __generator(this, function (_a) {
380
- switch (_a.label) {
381
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
382
- var groupId = _a.groupId, property = _a.property, value = _a.value;
383
- return WPP.group.setProperty(groupId, property, value);
384
- }, { groupId: groupId, property: property, value: value })];
385
- case 1: return [2 /*return*/, _a.sent()];
386
- }
387
- });
388
- });
389
- };
190
+ async setGroupProperty(groupId, property, value) {
191
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, property, value }) => WPP.group.setProperty(groupId, property, value), { groupId, property, value });
192
+ }
390
193
  /**
391
194
  * Set group icon
392
195
  * @category Group
@@ -394,100 +197,63 @@ var GroupLayer = /** @class */ (function (_super) {
394
197
  * @param base64 Image in base64 ( data:image/jpeg;base64,..... )
395
198
  * @returns empty object
396
199
  */
397
- GroupLayer.prototype.setGroupIcon = function (groupId, pathOrBase64) {
398
- return __awaiter(this, void 0, void 0, function () {
399
- var base64, fileContent, error, mimeInfo, error;
400
- return __generator(this, function (_a) {
401
- switch (_a.label) {
402
- case 0:
403
- base64 = '';
404
- if (!pathOrBase64.startsWith('data:')) return [3 /*break*/, 1];
405
- base64 = pathOrBase64;
406
- return [3 /*break*/, 5];
407
- case 1: return [4 /*yield*/, (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
408
- 'image/gif',
409
- 'image/png',
410
- 'image/jpg',
411
- 'image/jpeg',
412
- 'image/webp',
413
- ])];
414
- case 2:
415
- fileContent = _a.sent();
416
- if (!!fileContent) return [3 /*break*/, 4];
417
- return [4 /*yield*/, (0, helpers_1.fileToBase64)(pathOrBase64)];
418
- case 3:
419
- fileContent = _a.sent();
420
- _a.label = 4;
421
- case 4:
422
- if (fileContent) {
423
- base64 = fileContent;
424
- }
425
- _a.label = 5;
426
- case 5:
427
- if (!base64) {
428
- error = new Error('Empty or invalid file or base64');
429
- Object.assign(error, {
430
- code: 'empty_file',
431
- });
432
- throw error;
433
- }
434
- mimeInfo = (0, helpers_1.base64MimeType)(base64);
435
- if (!mimeInfo || !mimeInfo.includes('image')) {
436
- error = new Error('Not an image, allowed formats png, jpeg and webp');
437
- Object.assign(error, {
438
- code: 'invalid_image',
439
- });
440
- throw error;
441
- }
442
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
443
- var groupId = _a.groupId, base64 = _a.base64;
444
- return WPP.group.setIcon(groupId, base64);
445
- }, { groupId: groupId, base64: base64 })];
446
- case 6: return [2 /*return*/, _a.sent()];
447
- }
200
+ async setGroupIcon(groupId, pathOrBase64) {
201
+ let base64 = '';
202
+ if (pathOrBase64.startsWith('data:')) {
203
+ base64 = pathOrBase64;
204
+ }
205
+ else {
206
+ let fileContent = await (0, helpers_1.downloadFileToBase64)(pathOrBase64, [
207
+ 'image/gif',
208
+ 'image/png',
209
+ 'image/jpg',
210
+ 'image/jpeg',
211
+ 'image/webp',
212
+ ]);
213
+ if (!fileContent) {
214
+ fileContent = await (0, helpers_1.fileToBase64)(pathOrBase64);
215
+ }
216
+ if (fileContent) {
217
+ base64 = fileContent;
218
+ }
219
+ }
220
+ if (!base64) {
221
+ const error = new Error('Empty or invalid file or base64');
222
+ Object.assign(error, {
223
+ code: 'empty_file',
448
224
  });
449
- });
450
- };
225
+ throw error;
226
+ }
227
+ const mimeInfo = (0, helpers_1.base64MimeType)(base64);
228
+ if (!mimeInfo || !mimeInfo.includes('image')) {
229
+ const error = new Error('Not an image, allowed formats png, jpeg and webp');
230
+ Object.assign(error, {
231
+ code: 'invalid_image',
232
+ });
233
+ throw error;
234
+ }
235
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, base64 }) => WPP.group.setIcon(groupId, base64), { groupId, base64 });
236
+ }
451
237
  /**
452
238
  * Set group subject (if allowed)
453
239
  * @category Group
454
240
  * @param groupId Group ID ('0000000000@g.us')
455
241
  * @returns empty object
456
242
  */
457
- GroupLayer.prototype.removeGroupIcon = function (groupId) {
458
- return __awaiter(this, void 0, void 0, function () {
459
- return __generator(this, function (_a) {
460
- switch (_a.label) {
461
- case 0:
462
- if (!groupId) {
463
- throw new Error('Empty or invalid group id');
464
- }
465
- return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
466
- var groupId = _a.groupId;
467
- return WPP.group.removeIcon(groupId);
468
- }, { groupId: groupId })];
469
- case 1: return [2 /*return*/, _a.sent()];
470
- }
471
- });
472
- });
473
- };
243
+ async removeGroupIcon(groupId) {
244
+ if (!groupId) {
245
+ throw new Error('Empty or invalid group id');
246
+ }
247
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId }) => WPP.group.removeIcon(groupId), { groupId });
248
+ }
474
249
  /**
475
250
  * Get the max number of participants for a group
476
251
  * @category Group
477
252
  * @returns number
478
253
  */
479
- GroupLayer.prototype.getGroupSizeLimit = function () {
480
- return __awaiter(this, void 0, void 0, function () {
481
- return __generator(this, function (_a) {
482
- switch (_a.label) {
483
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function () {
484
- return WPP.group.getGroupSizeLimit();
485
- })];
486
- case 1: return [2 /*return*/, _a.sent()];
487
- }
488
- });
489
- });
490
- };
254
+ async getGroupSizeLimit() {
255
+ return await (0, helpers_1.evaluateAndReturn)(this.page, () => WPP.group.getGroupSizeLimit());
256
+ }
491
257
  /**
492
258
  * Approve a membership request to group
493
259
  * @category Group
@@ -495,19 +261,9 @@ var GroupLayer = /** @class */ (function (_super) {
495
261
  * @param wid <number>@c.us
496
262
  * @returns Promise
497
263
  */
498
- GroupLayer.prototype.approveGroupMembershipRequest = function (groupId, membershipIds) {
499
- return __awaiter(this, void 0, void 0, function () {
500
- return __generator(this, function (_a) {
501
- switch (_a.label) {
502
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
503
- var groupId = _a.groupId, membershipIds = _a.membershipIds;
504
- return WPP.group.approve(groupId, membershipIds);
505
- }, { groupId: groupId, membershipIds: membershipIds })];
506
- case 1: return [2 /*return*/, _a.sent()];
507
- }
508
- });
509
- });
510
- };
264
+ async approveGroupMembershipRequest(groupId, membershipIds) {
265
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, membershipIds }) => WPP.group.approve(groupId, membershipIds), { groupId, membershipIds });
266
+ }
511
267
  /**
512
268
  * Reject a membership request to group
513
269
  * @category Group
@@ -515,38 +271,17 @@ var GroupLayer = /** @class */ (function (_super) {
515
271
  * @param wid <number>@c.us
516
272
  * @returns Promise
517
273
  */
518
- GroupLayer.prototype.rejectGroupMembershipRequest = function (groupId, membershipIds) {
519
- return __awaiter(this, void 0, void 0, function () {
520
- return __generator(this, function (_a) {
521
- switch (_a.label) {
522
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
523
- var groupId = _a.groupId, membershipIds = _a.membershipIds;
524
- return WPP.group.reject(groupId, membershipIds);
525
- }, { groupId: groupId, membershipIds: membershipIds })];
526
- case 1: return [2 /*return*/, _a.sent()];
527
- }
528
- });
529
- });
530
- };
274
+ async rejectGroupMembershipRequest(groupId, membershipIds) {
275
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, membershipIds }) => WPP.group.reject(groupId, membershipIds), { groupId, membershipIds });
276
+ }
531
277
  /**
532
278
  * Retrieve a list of a membership approval requests
533
279
  * @category Group
534
280
  * @param groupId Group ID ('000000-000000@g.us')
535
281
  * @returns Promise
536
282
  */
537
- GroupLayer.prototype.getGroupMembershipRequests = function (groupId) {
538
- return __awaiter(this, void 0, void 0, function () {
539
- return __generator(this, function (_a) {
540
- switch (_a.label) {
541
- case 0: return [4 /*yield*/, (0, helpers_1.evaluateAndReturn)(this.page, function (_a) {
542
- var groupId = _a.groupId;
543
- return WPP.group.getMembershipRequests(groupId);
544
- }, { groupId: groupId })];
545
- case 1: return [2 /*return*/, _a.sent()];
546
- }
547
- });
548
- });
549
- };
550
- return GroupLayer;
551
- }(retriever_layer_1.RetrieverLayer));
283
+ async getGroupMembershipRequests(groupId) {
284
+ return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId }) => WPP.group.getMembershipRequests(groupId), { groupId });
285
+ }
286
+ }
552
287
  exports.GroupLayer = GroupLayer;