@wppconnect-team/wppconnect 2.2.6 → 2.3.0

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.
@@ -52,7 +52,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
52
52
  exports.fileToBase64 = fileToBase64;
53
53
  exports.Mine = Mine;
54
54
  const mimeTypes = __importStar(require("mime-types"));
55
- const fileType = __importStar(require("file-type"));
56
55
  const fs = __importStar(require("fs"));
57
56
  /**
58
57
  * Converts given file into base64 string
@@ -65,10 +64,6 @@ async function fileToBase64(path, mime) {
65
64
  if (mime === undefined) {
66
65
  mime = mimeTypes.lookup(path);
67
66
  }
68
- if (!mime) {
69
- const result = await fileType.fromFile(path);
70
- mime = result?.mime;
71
- }
72
67
  if (!mime) {
73
68
  mime = 'application/octet-stream';
74
69
  }
@@ -26,10 +26,10 @@ async function stickerSelect(_B, _t) {
26
26
  let _w, _ins;
27
27
  switch (_t) {
28
28
  case 0:
29
- _ins = await (0, sharp_1.default)(_B, { failOnError: false })
29
+ _ins = await (0, sharp_1.default)(_B, { failOn: 'none' })
30
30
  .resize({ width: 512, height: 512 })
31
31
  .toBuffer();
32
- _w = (0, sharp_1.default)(_ins, { failOnError: false }).webp();
32
+ _w = (0, sharp_1.default)(_ins, { failOn: 'none' }).webp();
33
33
  break;
34
34
  case 1:
35
35
  _w = (0, sharp_1.default)(_B, { animated: true }).webp();
@@ -53,8 +53,8 @@ async function stickerSelect(_B, _t) {
53
53
  return obj;
54
54
  }
55
55
  async function resizeImg(buff, size) {
56
- const _ins = await (0, sharp_1.default)(buff, { failOnError: false })
56
+ const _ins = await (0, sharp_1.default)(buff, { failOn: 'none' })
57
57
  .resize({ width: size.width, height: size.height })
58
- .toBuffer(), _w = (0, sharp_1.default)(_ins, { failOnError: false }).jpeg(), _webb64 = (await _w.toBuffer()).toString('base64');
58
+ .toBuffer(), _w = (0, sharp_1.default)(_ins, { failOn: 'none' }).jpeg(), _webb64 = (await _w.toBuffer()).toString('base64');
59
59
  return _webb64;
60
60
  }
@@ -125,14 +125,14 @@ export declare class GroupLayer extends RetrieverLayer {
125
125
  * @param groupId Chat id ('0000000000-00000000@g.us')
126
126
  * @param participantId Participant id'000000000000@c.us'
127
127
  */
128
- promoteParticipant(groupId: string, participantId: string | string[]): Promise<boolean>;
128
+ promoteParticipant(groupId: string, participantId: string | string[]): Promise<void>;
129
129
  /**
130
130
  * Demotes admin privileges of participant
131
131
  * @category Group
132
132
  * @param groupId Chat id ('0000000000-00000000@g.us')
133
133
  * @param participantId Participant id'000000000000@c.us'
134
134
  */
135
- demoteParticipant(groupId: string, participantId: string | string[]): Promise<true | void>;
135
+ demoteParticipant(groupId: string, participantId: string | string[]): Promise<void>;
136
136
  /**
137
137
  * Retrieves group admins
138
138
  * @category Group
@@ -124,7 +124,6 @@ class GroupLayer extends retriever_layer_1.RetrieverLayer {
124
124
  */
125
125
  async promoteParticipant(groupId, participantId) {
126
126
  await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, participantId }) => WPP.group.promoteParticipants(groupId, participantId), { groupId, participantId });
127
- return true;
128
127
  }
129
128
  /**
130
129
  * Demotes admin privileges of participant
@@ -134,7 +133,6 @@ class GroupLayer extends retriever_layer_1.RetrieverLayer {
134
133
  */
135
134
  async demoteParticipant(groupId, participantId) {
136
135
  return await (0, helpers_1.evaluateAndReturn)(this.page, ({ groupId, participantId }) => WPP.group.demoteParticipants(groupId, participantId), { groupId, participantId });
137
- return true;
138
136
  }
139
137
  /**
140
138
  * Retrieves group admins
@@ -322,11 +322,6 @@ class HostLayer {
322
322
  this.cancelAutoClose();
323
323
  return true;
324
324
  }
325
- if (authenticated === false) {
326
- this.tryAutoClose();
327
- this.log('warn', 'Not logged');
328
- throw new Error('Not logged');
329
- }
330
325
  this.tryAutoClose();
331
326
  if (this.autoCloseCalled) {
332
327
  this.log('error', 'Auto Close Called');
@@ -55,6 +55,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
55
55
  exports.Whatsapp = void 0;
56
56
  const axios_1 = __importDefault(require("axios"));
57
57
  const fs = __importStar(require("fs"));
58
+ const promises_1 = require("stream/promises");
58
59
  const WAuserAgente_1 = require("../config/WAuserAgente");
59
60
  const sleep_1 = require("../utils/sleep");
60
61
  const helpers_1 = require("./helpers");
@@ -250,30 +251,10 @@ class Whatsapp extends business_layer_1.BusinessLayer {
250
251
  const inputReadStream = fs.createReadStream(tempSavePath);
251
252
  const outputWriteStream = fs.createWriteStream(savePath);
252
253
  const decryptedStream = (0, decrypt_1.newMagix)(message.mediaKey, message.type, message.size);
253
- inputReadStream.pipe(decryptedStream).pipe(outputWriteStream);
254
- await new Promise((resolve, reject) => {
255
- outputWriteStream.on('finish', () => {
256
- console.log(`Deciphering complete. Deleting the encrypted file: ${tempSavePath}`);
257
- fs.unlink(tempSavePath, (error) => {
258
- if (error) {
259
- console.error(`Error deleting the input file: ${tempSavePath}`, error);
260
- reject(error);
261
- }
262
- else {
263
- console.log('Encrypted file deleted successfully');
264
- resolve();
265
- }
266
- });
267
- });
268
- outputWriteStream.on('error', (error) => {
269
- console.error(`Error during writing file: ${savePath}`, error);
270
- reject(error);
271
- });
272
- decryptedStream.on('error', (error) => {
273
- console.error('An error occurred while decrypting the file', error);
274
- reject(error);
275
- });
276
- });
254
+ await (0, promises_1.pipeline)(inputReadStream, decryptedStream, outputWriteStream);
255
+ console.log(`Deciphering complete. Deleting the encrypted file: ${tempSavePath}`);
256
+ await fs.promises.unlink(tempSavePath);
257
+ console.log('Encrypted file deleted successfully');
277
258
  }
278
259
  catch (error) {
279
260
  throw error;
@@ -283,12 +264,8 @@ class Whatsapp extends business_layer_1.BusinessLayer {
283
264
  for (let attempt = 1; attempt <= retries; attempt++) {
284
265
  try {
285
266
  const response = await axios_1.default.get(url, (0, decrypt_1.makeOptions)(WAuserAgente_1.useragentOverride, 'stream'));
286
- await new Promise((resolve, reject) => {
287
- const writer = fs.createWriteStream(outputPath);
288
- response.data.pipe(writer);
289
- writer.on('finish', resolve);
290
- writer.on('error', reject);
291
- });
267
+ const writer = fs.createWriteStream(outputPath);
268
+ await (0, promises_1.pipeline)(response.data, writer);
292
269
  console.log(`Encrypted file downloaded at ${outputPath}`);
293
270
  return;
294
271
  }