@auxcode/auxta 1.3.23-beta.4 → 1.3.23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "1.3.23-beta.4",
3
+ "version": "1.3.23",
4
4
  "description": "",
5
5
  "main": "./build/cjs/AuxTA.js",
6
6
  "module": "./build/esm/AuxTA.js",
@@ -22,7 +22,6 @@
22
22
  "fs": "^0.0.1-security",
23
23
  "googleapis": "^118.0.0",
24
24
  "node-2fa": "^2.0.3",
25
- "nodemailer": "^6.9.2",
26
25
  "puppeteer": "^19.7.5",
27
26
  "readline": "^1.3.0",
28
27
  "typescript": "^4.5.2"
@@ -1,17 +0,0 @@
1
- import { gmail_v1 } from "googleapis";
2
- export declare class EmailHelper {
3
- verifyEmail(from_name: string, from_email: string, subject: string, body: string): Promise<{
4
- id: string;
5
- threadId: string;
6
- } | undefined>;
7
- replyEmail(ids: {
8
- id: string;
9
- threadId: string;
10
- }, body: string): Promise<void>;
11
- private getHeader;
12
- private getBody;
13
- }
14
- export interface gmailResponse extends gmail_v1.Gmail {
15
- }
16
- declare const _default: EmailHelper;
17
- export default _default;
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.EmailHelper = void 0;
16
- const log_service_1 = __importDefault(require("../../auxta/services/log.service"));
17
- const AuxGoogleAuth_1 = require("./AuxGoogleAuth");
18
- const buffer_1 = require("buffer");
19
- const AuxTA_1 = require("../../AuxTA");
20
- const MailComposer = require('nodemailer/lib/mail-composer');
21
- class EmailHelper {
22
- verifyEmail(from_name, from_email, subject, body) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
25
- const res = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.list({
26
- userId: "me",
27
- maxResults: 3
28
- });
29
- const messagesIds = res.data.messages;
30
- if (!messagesIds || messagesIds.length === 0) {
31
- throw new Error('No messagesIds found.');
32
- }
33
- let timeoutCount = 12000;
34
- while (timeoutCount <= 60000) {
35
- for (const messageId of messagesIds) {
36
- if (messageId.id) {
37
- const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
38
- userId: "me",
39
- id: messageId.id.toString(),
40
- format: 'FULL'
41
- });
42
- if (gmailResponse.data.payload && gmailResponse.data.id && gmailResponse.data.threadId) {
43
- const message_sender = this.getHeader('from', gmailResponse.data.payload.headers);
44
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
45
- const message_body = this.getBody(from_name, from_email, subject, gmailResponse);
46
- if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
47
- message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
48
- log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.PASSED);
49
- yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.modify({
50
- userId: "me",
51
- id: gmailResponse.data.id,
52
- requestBody: {
53
- 'addLabelIds': [],
54
- 'removeLabelIds': ['UNREAD']
55
- }
56
- });
57
- return { id: gmailResponse.data.id.toString(), threadId: gmailResponse.data.threadId.toString() };
58
- }
59
- }
60
- break;
61
- }
62
- }
63
- new Promise(r => setTimeout(r, 12000));
64
- timeoutCount += 12000;
65
- }
66
- yield log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.FAILED);
67
- });
68
- }
69
- replyEmail(ids, body) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
72
- const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
73
- userId: "me",
74
- id: ids.id,
75
- format: 'FULL'
76
- });
77
- if (gmailResponse.data.payload) {
78
- const from = this.getHeader('from', gmailResponse.data.payload.headers);
79
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
80
- const message_messageID = this.getHeader('Message-ID', gmailResponse.data.payload.headers);
81
- const to = this.getHeader('to', gmailResponse.data.payload.headers);
82
- const options = {
83
- "to": from,
84
- "from": to,
85
- "subject": `Re: ${message_subject}`,
86
- "References": message_messageID,
87
- "In-Reply-To": message_messageID,
88
- "threadId": ids.threadId,
89
- "html": body
90
- };
91
- const mailComposer = new MailComposer(options);
92
- const message = yield mailComposer.compile().build();
93
- const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
94
- yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.send({
95
- userId: "me",
96
- requestBody: {
97
- raw: encodeMessage
98
- }
99
- });
100
- }
101
- });
102
- }
103
- getHeader(value, headers) {
104
- for (const header of headers) {
105
- if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
106
- return header.value.toLocaleLowerCase();
107
- }
108
- }
109
- }
110
- getBody(from_name, from_email, subject, gmailResponse) {
111
- const body = gmailResponse.data.payload.parts[0].body.data;
112
- if (body) {
113
- return (0, buffer_1.atob)(body).toLocaleLowerCase();
114
- }
115
- else {
116
- throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
117
- }
118
- }
119
- }
120
- exports.EmailHelper = EmailHelper;
121
- exports.default = new EmailHelper();
@@ -1,17 +0,0 @@
1
- import { gmail_v1 } from "googleapis";
2
- export declare class EmailHelper {
3
- verifyEmail(from_name: string, from_email: string, subject: string, body: string): Promise<{
4
- id: string;
5
- threadId: string;
6
- } | undefined>;
7
- replyEmail(ids: {
8
- id: string;
9
- threadId: string;
10
- }, body: string): Promise<void>;
11
- private getHeader;
12
- private getBody;
13
- }
14
- export interface gmailResponse extends gmail_v1.Gmail {
15
- }
16
- declare const _default: EmailHelper;
17
- export default _default;
@@ -1,114 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import log from "../../auxta/services/log.service";
11
- import { AuxGoogleAuth } from "./AuxGoogleAuth";
12
- import { atob } from "buffer";
13
- import { StepStatus } from "../../AuxTA";
14
- const MailComposer = require('nodemailer/lib/mail-composer');
15
- export class EmailHelper {
16
- verifyEmail(from_name, from_email, subject, body) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- yield AuxGoogleAuth.setup();
19
- const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
20
- userId: "me",
21
- maxResults: 3
22
- });
23
- const messagesIds = res.data.messages;
24
- if (!messagesIds || messagesIds.length === 0) {
25
- throw new Error('No messagesIds found.');
26
- }
27
- let timeoutCount = 12000;
28
- while (timeoutCount <= 60000) {
29
- for (const messageId of messagesIds) {
30
- if (messageId.id) {
31
- const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
32
- userId: "me",
33
- id: messageId.id.toString(),
34
- format: 'FULL'
35
- });
36
- if (gmailResponse.data.payload && gmailResponse.data.id && gmailResponse.data.threadId) {
37
- const message_sender = this.getHeader('from', gmailResponse.data.payload.headers);
38
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
39
- const message_body = this.getBody(from_name, from_email, subject, gmailResponse);
40
- if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
41
- message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
42
- log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.PASSED);
43
- yield AuxGoogleAuth.gmailClient.users.messages.modify({
44
- userId: "me",
45
- id: gmailResponse.data.id,
46
- requestBody: {
47
- 'addLabelIds': [],
48
- 'removeLabelIds': ['UNREAD']
49
- }
50
- });
51
- return { id: gmailResponse.data.id.toString(), threadId: gmailResponse.data.threadId.toString() };
52
- }
53
- }
54
- break;
55
- }
56
- }
57
- new Promise(r => setTimeout(r, 12000));
58
- timeoutCount += 12000;
59
- }
60
- yield log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.FAILED);
61
- });
62
- }
63
- replyEmail(ids, body) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- yield AuxGoogleAuth.setup();
66
- const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
67
- userId: "me",
68
- id: ids.id,
69
- format: 'FULL'
70
- });
71
- if (gmailResponse.data.payload) {
72
- const from = this.getHeader('from', gmailResponse.data.payload.headers);
73
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
74
- const message_messageID = this.getHeader('Message-ID', gmailResponse.data.payload.headers);
75
- const to = this.getHeader('to', gmailResponse.data.payload.headers);
76
- const options = {
77
- "to": from,
78
- "from": to,
79
- "subject": `Re: ${message_subject}`,
80
- "References": message_messageID,
81
- "In-Reply-To": message_messageID,
82
- "threadId": ids.threadId,
83
- "html": body
84
- };
85
- const mailComposer = new MailComposer(options);
86
- const message = yield mailComposer.compile().build();
87
- const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
88
- yield AuxGoogleAuth.gmailClient.users.messages.send({
89
- userId: "me",
90
- requestBody: {
91
- raw: encodeMessage
92
- }
93
- });
94
- }
95
- });
96
- }
97
- getHeader(value, headers) {
98
- for (const header of headers) {
99
- if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
100
- return header.value.toLocaleLowerCase();
101
- }
102
- }
103
- }
104
- getBody(from_name, from_email, subject, gmailResponse) {
105
- const body = gmailResponse.data.payload.parts[0].body.data;
106
- if (body) {
107
- return atob(body).toLocaleLowerCase();
108
- }
109
- else {
110
- throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
111
- }
112
- }
113
- }
114
- export default new EmailHelper();