bot-functions 1.3.4 → 1.5.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.
Files changed (2) hide show
  1. package/index.js +41 -29
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -324,42 +324,29 @@ class EmailManager {
324
324
  if (!this.connection) {
325
325
  throw new Error('Not connected to email account');
326
326
  }
327
+
327
328
  const uidArray = Array.isArray(uids) ? uids : [uids];
329
+
328
330
  try {
329
- try {
330
- for (const uid of uidArray) {
331
- await this.connection.move(uid, '[Gmail]/Trash');
332
- }
333
- return { success: true, deletedCount: uidArray.length, action: 'moved_to_trash' };
334
- } catch (moveError) {
335
- try {
336
- for (const uid of uidArray) {
337
- await this.connection.move(uid, 'Deleted Items');
338
- }
339
- return { success: true, deletedCount: uidArray.length, action: 'moved_to_deleted_items' };
340
- } catch (moveError2) {
341
- try {
342
- for (const uid of uidArray) {
343
- await this.connection.move(uid, 'TRASH');
344
- }
345
- return { success: true, deletedCount: uidArray.length, action: 'moved_to_trash_folder' };
346
- } catch (moveError3) {
347
- for (const uid of uidArray) {
348
- await this.connection.addFlags(uid, '\\Deleted');
349
- }
350
- await this.connection.closeBox(false);
351
- await this.connection.openBox('INBOX');
352
- return { success: true, deletedCount: uidArray.length, action: 'marked_deleted' };
353
- }
354
- }
331
+ for (const uid of uidArray) {
332
+ await this.connection.addFlags(uid, '\\Deleted');
355
333
  }
334
+ await this.connection.imap.expunge();
335
+ log.info(`Successfully deleted ${uidArray.length} email(s)`);
336
+
337
+ return {
338
+ success: true,
339
+ deletedCount: uidArray.length,
340
+ action: 'deleted'
341
+ };
342
+
356
343
  } catch (error) {
357
344
  log.error("Error deleting emails:", error);
358
- return;
345
+ throw new Error(`Failed to delete emails: ${error.message}`);
359
346
  } finally {
360
347
  if (this.connection) {
361
348
  try {
362
- this.connection.end();
349
+ await this.connection.end();
363
350
  this.connection = null;
364
351
  } catch (error) {
365
352
  log.error("Error disconnecting:", error);
@@ -1357,6 +1344,28 @@ function diferenciaHoras(tiempo1, tiempo2) {
1357
1344
  return `${horas.toString().padStart(2, "0")}:${minutos.toString().padStart(2, "0")}`;
1358
1345
  }
1359
1346
 
1347
+ const insertCatspecs = async ({ db, area, cadena, nivel, fecha, val1, val5 }) => {
1348
+ try {
1349
+ const insertCatspecsResponse = await axios.post(process.env.POST_CATSPECS, {
1350
+ db, area, cadena, nivel, fecha, val1, val5
1351
+ });
1352
+ return insertCatspecsResponse.data;
1353
+ } catch (e) {
1354
+ log.error(e.message);
1355
+ throw new Error("No se pudo insertar la información de catspecs");
1356
+ }
1357
+ }
1358
+
1359
+ const uploadImageToS3 = async (filePath, key) => {
1360
+ const fileData = fs.readFileSync(filePath);
1361
+ const regs = await axios.post(process.env.AUTH_PATH, { email: process.env.EMAIL_API });
1362
+ const body = { type: 1, bucketName: process.env.S3_BUCKET, file: fileData.toString('base64'), key };
1363
+ const uploadFileResponse = await axios.post(process.env.S3_UPLOAD_FILE, body,
1364
+ { maxBodyLength: Infinity, headers: { 'Authorization': regs.data.data, 'Content-Type': 'application/json' } }
1365
+ );
1366
+ return uploadFileResponse.data.data;
1367
+ }
1368
+
1360
1369
 
1361
1370
  module.exports = {
1362
1371
  waitNtype,
@@ -1409,5 +1418,8 @@ module.exports = {
1409
1418
  EmailManager,
1410
1419
  manageEmails,
1411
1420
  insertLogExec,
1412
- sendDataCH
1421
+ sendDataCH,
1422
+ processDataDaily,
1423
+ uploadImageToS3,
1424
+ insertCatspecs,
1413
1425
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bot-functions",
3
- "version": "1.3.4",
3
+ "version": "1.5.0",
4
4
  "description": "Bot functions",
5
5
  "main": "index.js",
6
6
  "scripts": {