@auxcode/auxta 1.3.22 → 1.3.23-beta.10

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.
@@ -25,6 +25,7 @@ declare class AuxTA extends FunctionHelper {
25
25
  password: string;
26
26
  };
27
27
  };
28
+ email: import("./macros/helpers/emailHelper").EmailHelper;
28
29
  private readonly uploadModel;
29
30
  constructor();
30
31
  run(event: any, overrideConfig?: any): Promise<{
@@ -48,6 +48,7 @@ const start_suite_helper_1 = require("./auxta/utilities/start-suite.helper");
48
48
  const report_service_1 = require("./auxta/services/report.service");
49
49
  const Aux2faAuth_1 = __importDefault(require("./macros/helpers/Aux2faAuth"));
50
50
  const AuxGoogleAuth_1 = require("./macros/helpers/AuxGoogleAuth");
51
+ const emailHelper_1 = __importDefault(require("./macros/helpers/emailHelper"));
51
52
  dotenv.config();
52
53
  class AuxTA extends code_helper_1.FunctionHelper {
53
54
  constructor() {
@@ -56,6 +57,7 @@ class AuxTA extends code_helper_1.FunctionHelper {
56
57
  this.aux2fa = Aux2faAuth_1.default;
57
58
  this.google = AuxGoogleAuth_1.AuxGoogleAuth;
58
59
  this.config = config_1.config;
60
+ this.email = emailHelper_1.default;
59
61
  let file;
60
62
  if (!process.env.RPA) {
61
63
  try {
@@ -11,3 +11,7 @@ export declare class AuxGoogleAuth {
11
11
  }
12
12
  declare const _default: AuxGoogleAuth;
13
13
  export default _default;
14
+ export interface currentUser {
15
+ name: string;
16
+ email: string;
17
+ }
@@ -1,6 +1,5 @@
1
1
  import { StatusOfStep } from "../../auxta/enums/status-of.step";
2
2
  import { ExtendDefaultPage } from "./extend-default-page";
3
- import { gmail_v1 } from "googleapis";
4
3
  export declare class FunctionHelper extends ExtendDefaultPage {
5
4
  log(keyword: string, name: string, status: StatusOfStep): void;
6
5
  suggest(name: string): void;
@@ -17,11 +16,6 @@ export declare class FunctionHelper extends ExtendDefaultPage {
17
16
  clickAndWaitForPageToBeCreated(selector: string, page?: import("puppeteer").Page): Promise<void>;
18
17
  closeLastPage(page?: import("puppeteer").Page): Promise<void>;
19
18
  microsoftLogin(button: string, email: string, password: string): Promise<void>;
20
- clickInMail(from_name: string, from_email: string, subject: string, body: string): Promise<true | undefined>;
21
- private getHeader;
22
- private getBody;
23
- }
24
- export interface gmailResponse extends gmail_v1.Gmail {
25
19
  }
26
20
  declare const _default: FunctionHelper;
27
21
  export default _default;
@@ -19,8 +19,6 @@ const status_of_step_1 = require("../../auxta/enums/status-of.step");
19
19
  const AuxTA_1 = require("../../AuxTA");
20
20
  const extend_default_page_1 = require("./extend-default-page");
21
21
  const puppeteer_2 = require("puppeteer");
22
- const AuxGoogleAuth_1 = require("./AuxGoogleAuth");
23
- const buffer_1 = require("buffer");
24
22
  class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
25
23
  log(keyword, name, status) {
26
24
  log_service_1.default.push(keyword, name, status);
@@ -91,7 +89,7 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
91
89
  }
92
90
  timeout(timeout = this.defaultTimeout, page = puppeteer_1.default.defaultPage) {
93
91
  return __awaiter(this, void 0, void 0, function* () {
94
- yield page.waitForTimeout(timeout);
92
+ yield new Promise(r => setTimeout(r, timeout));
95
93
  });
96
94
  }
97
95
  waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer_1.default.defaultPage, log_message = true) {
@@ -189,62 +187,6 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
189
187
  yield loginPage.waitForNetworkIdle();
190
188
  });
191
189
  }
192
- clickInMail(from_name, from_email, subject, body) {
193
- return __awaiter(this, void 0, void 0, function* () {
194
- yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
195
- const res = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.list({
196
- userId: "me",
197
- maxResults: 3
198
- });
199
- const messagesIds = res.data.messages;
200
- if (!messagesIds || messagesIds.length === 0) {
201
- throw new Error('No messagesIds found.');
202
- }
203
- let timeoutCount = 12000;
204
- yield this.timeout(12000);
205
- while (timeoutCount <= 60000) {
206
- for (const messageId of messagesIds) {
207
- if (messageId.id) {
208
- const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
209
- userId: "me",
210
- id: messageId.id.toString(),
211
- format: 'FULL'
212
- });
213
- if (gmailResponse.data.payload) {
214
- const message_sender = this.getHeader('from', gmailResponse.data.payload.headers);
215
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
216
- const message_body = this.getBody(from_name, from_email, subject, gmailResponse);
217
- if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
218
- message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
219
- yield this.log('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.PASSED);
220
- return true;
221
- }
222
- }
223
- break;
224
- }
225
- }
226
- yield this.timeout(12000);
227
- timeoutCount += 12000;
228
- }
229
- yield this.log('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.FAILED);
230
- });
231
- }
232
- getHeader(value, headers) {
233
- for (const header of headers) {
234
- if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
235
- return header.value.toLocaleLowerCase();
236
- }
237
- }
238
- }
239
- getBody(from_name, from_email, subject, gmailResponse) {
240
- const body = gmailResponse.data.payload.parts[0].body.data;
241
- if (body) {
242
- return (0, buffer_1.atob)(body).toLocaleLowerCase();
243
- }
244
- else {
245
- throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
246
- }
247
- }
248
190
  }
249
191
  exports.FunctionHelper = FunctionHelper;
250
192
  exports.default = new FunctionHelper();
@@ -0,0 +1,17 @@
1
+ import { gmail_v1 } from "googleapis";
2
+ export declare class EmailHelper {
3
+ verifyEmail(from_name: string, from_email: string, subject: string, body: string, reply?: boolean, reply_body?: string): Promise<{
4
+ id: string;
5
+ threadId: string;
6
+ } | undefined>;
7
+ sendEmail(to: string, subject: string, body: string): Promise<void>;
8
+ replyEmail(id: string, threadId: string, body: string): Promise<void>;
9
+ private static send;
10
+ private getHeader;
11
+ private getBody;
12
+ private getCurrentUserEmail;
13
+ }
14
+ export interface gmailResponse extends gmail_v1.Gmail {
15
+ }
16
+ declare const _default: EmailHelper;
17
+ export default _default;
@@ -0,0 +1,143 @@
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, reply = false, reply_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);
44
+ const message_subject = this.getHeader('subject', gmailResponse);
45
+ const message_body = this.getBody(subject, gmailResponse);
46
+ if (message_sender.toLocaleLowerCase().includes(from_email) && message_sender.toLocaleLowerCase().includes(from_name.toLocaleLowerCase()) &&
47
+ message_subject.toLocaleLowerCase().includes(subject.toLocaleLowerCase()) && message_body.toLocaleLowerCase().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, threadId: gmailResponse.data.threadId };
58
+ }
59
+ }
60
+ break;
61
+ }
62
+ }
63
+ yield new Promise(r => setTimeout(r, timeoutCount));
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
+ sendEmail(to, subject, body) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const options = {
72
+ to: to,
73
+ from: this.getCurrentUserEmail(),
74
+ subject: subject,
75
+ html: body
76
+ };
77
+ yield EmailHelper.send(options);
78
+ });
79
+ }
80
+ replyEmail(id, threadId, body) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
83
+ const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
84
+ userId: "me",
85
+ id: id,
86
+ format: 'FULL'
87
+ });
88
+ if (gmailResponse.data.payload) {
89
+ const message_subject = this.getHeader('subject', gmailResponse);
90
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
91
+ const reply_to = this.getHeader('reply-to', gmailResponse);
92
+ const options = {
93
+ to: reply_to,
94
+ from: this.getCurrentUserEmail(),
95
+ subject: `Re: ${message_subject}`,
96
+ references: message_messageID,
97
+ inReplyTo: [message_messageID],
98
+ html: body
99
+ };
100
+ yield EmailHelper.send(options, threadId);
101
+ }
102
+ });
103
+ }
104
+ static send(options, threadId) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const mailComposer = new MailComposer(options);
107
+ const message = yield mailComposer.compile().build();
108
+ const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
109
+ yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.send({
110
+ userId: "me",
111
+ requestBody: {
112
+ threadId: threadId,
113
+ raw: encodeMessage
114
+ }
115
+ });
116
+ });
117
+ }
118
+ getHeader(value, headers) {
119
+ for (const header of headers.data.payload.headers) {
120
+ if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
121
+ return header.value;
122
+ }
123
+ }
124
+ }
125
+ getBody(subject, gmailResponse) {
126
+ const body = gmailResponse.data.payload.parts[0].body.data;
127
+ if (body) {
128
+ return (0, buffer_1.atob)(body).toLocaleLowerCase();
129
+ }
130
+ else {
131
+ throw new Error(`Email with subject: ${subject} body is empty`);
132
+ }
133
+ }
134
+ getCurrentUserEmail() {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
137
+ const profile = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
138
+ return profile.data.emailAddress;
139
+ });
140
+ }
141
+ }
142
+ exports.EmailHelper = EmailHelper;
143
+ exports.default = new EmailHelper();
@@ -25,6 +25,7 @@ declare class AuxTA extends FunctionHelper {
25
25
  password: string;
26
26
  };
27
27
  };
28
+ email: import("./macros/helpers/emailHelper").EmailHelper;
28
29
  private readonly uploadModel;
29
30
  constructor();
30
31
  run(event: any, overrideConfig?: any): Promise<{
@@ -19,6 +19,7 @@ import { startSuite } from "./auxta/utilities/start-suite.helper";
19
19
  import { createEmptyReport } from "./auxta/services/report.service";
20
20
  import Aux2faAuth from "./macros/helpers/Aux2faAuth";
21
21
  import { AuxGoogleAuth } from "./macros/helpers/AuxGoogleAuth";
22
+ import emailHelper from "./macros/helpers/emailHelper";
22
23
  dotenv.config();
23
24
  class AuxTA extends FunctionHelper {
24
25
  constructor() {
@@ -27,6 +28,7 @@ class AuxTA extends FunctionHelper {
27
28
  this.aux2fa = Aux2faAuth;
28
29
  this.google = AuxGoogleAuth;
29
30
  this.config = c;
31
+ this.email = emailHelper;
30
32
  let file;
31
33
  if (!process.env.RPA) {
32
34
  try {
@@ -11,3 +11,7 @@ export declare class AuxGoogleAuth {
11
11
  }
12
12
  declare const _default: AuxGoogleAuth;
13
13
  export default _default;
14
+ export interface currentUser {
15
+ name: string;
16
+ email: string;
17
+ }
@@ -1,6 +1,5 @@
1
1
  import { StatusOfStep } from "../../auxta/enums/status-of.step";
2
2
  import { ExtendDefaultPage } from "./extend-default-page";
3
- import { gmail_v1 } from "googleapis";
4
3
  export declare class FunctionHelper extends ExtendDefaultPage {
5
4
  log(keyword: string, name: string, status: StatusOfStep): void;
6
5
  suggest(name: string): void;
@@ -17,11 +16,6 @@ export declare class FunctionHelper extends ExtendDefaultPage {
17
16
  clickAndWaitForPageToBeCreated(selector: string, page?: import("puppeteer").Page): Promise<void>;
18
17
  closeLastPage(page?: import("puppeteer").Page): Promise<void>;
19
18
  microsoftLogin(button: string, email: string, password: string): Promise<void>;
20
- clickInMail(from_name: string, from_email: string, subject: string, body: string): Promise<true | undefined>;
21
- private getHeader;
22
- private getBody;
23
- }
24
- export interface gmailResponse extends gmail_v1.Gmail {
25
19
  }
26
20
  declare const _default: FunctionHelper;
27
21
  export default _default;
@@ -13,8 +13,6 @@ import { StatusOfStep } from "../../auxta/enums/status-of.step";
13
13
  import { StepStatus } from "../../AuxTA";
14
14
  import { ExtendDefaultPage } from "./extend-default-page";
15
15
  import { KnownDevices } from "puppeteer";
16
- import { AuxGoogleAuth } from "./AuxGoogleAuth";
17
- import { atob } from "buffer";
18
16
  export class FunctionHelper extends ExtendDefaultPage {
19
17
  log(keyword, name, status) {
20
18
  log.push(keyword, name, status);
@@ -85,7 +83,7 @@ export class FunctionHelper extends ExtendDefaultPage {
85
83
  }
86
84
  timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
87
85
  return __awaiter(this, void 0, void 0, function* () {
88
- yield page.waitForTimeout(timeout);
86
+ yield new Promise(r => setTimeout(r, timeout));
89
87
  });
90
88
  }
91
89
  waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer.defaultPage, log_message = true) {
@@ -183,61 +181,5 @@ export class FunctionHelper extends ExtendDefaultPage {
183
181
  yield loginPage.waitForNetworkIdle();
184
182
  });
185
183
  }
186
- clickInMail(from_name, from_email, subject, body) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- yield AuxGoogleAuth.setup();
189
- const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
190
- userId: "me",
191
- maxResults: 3
192
- });
193
- const messagesIds = res.data.messages;
194
- if (!messagesIds || messagesIds.length === 0) {
195
- throw new Error('No messagesIds found.');
196
- }
197
- let timeoutCount = 12000;
198
- yield this.timeout(12000);
199
- while (timeoutCount <= 60000) {
200
- for (const messageId of messagesIds) {
201
- if (messageId.id) {
202
- const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
203
- userId: "me",
204
- id: messageId.id.toString(),
205
- format: 'FULL'
206
- });
207
- if (gmailResponse.data.payload) {
208
- const message_sender = this.getHeader('from', gmailResponse.data.payload.headers);
209
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
210
- const message_body = this.getBody(from_name, from_email, subject, gmailResponse);
211
- if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
212
- message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
213
- yield this.log('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.PASSED);
214
- return true;
215
- }
216
- }
217
- break;
218
- }
219
- }
220
- yield this.timeout(12000);
221
- timeoutCount += 12000;
222
- }
223
- yield this.log('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.FAILED);
224
- });
225
- }
226
- getHeader(value, headers) {
227
- for (const header of headers) {
228
- if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
229
- return header.value.toLocaleLowerCase();
230
- }
231
- }
232
- }
233
- getBody(from_name, from_email, subject, gmailResponse) {
234
- const body = gmailResponse.data.payload.parts[0].body.data;
235
- if (body) {
236
- return atob(body).toLocaleLowerCase();
237
- }
238
- else {
239
- throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
240
- }
241
- }
242
184
  }
243
185
  export default new FunctionHelper();
@@ -0,0 +1,17 @@
1
+ import { gmail_v1 } from "googleapis";
2
+ export declare class EmailHelper {
3
+ verifyEmail(from_name: string, from_email: string, subject: string, body: string, reply?: boolean, reply_body?: string): Promise<{
4
+ id: string;
5
+ threadId: string;
6
+ } | undefined>;
7
+ sendEmail(to: string, subject: string, body: string): Promise<void>;
8
+ replyEmail(id: string, threadId: string, body: string): Promise<void>;
9
+ private static send;
10
+ private getHeader;
11
+ private getBody;
12
+ private getCurrentUserEmail;
13
+ }
14
+ export interface gmailResponse extends gmail_v1.Gmail {
15
+ }
16
+ declare const _default: EmailHelper;
17
+ export default _default;
@@ -0,0 +1,136 @@
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, reply = false, reply_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);
38
+ const message_subject = this.getHeader('subject', gmailResponse);
39
+ const message_body = this.getBody(subject, gmailResponse);
40
+ if (message_sender.toLocaleLowerCase().includes(from_email) && message_sender.toLocaleLowerCase().includes(from_name.toLocaleLowerCase()) &&
41
+ message_subject.toLocaleLowerCase().includes(subject.toLocaleLowerCase()) && message_body.toLocaleLowerCase().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, threadId: gmailResponse.data.threadId };
52
+ }
53
+ }
54
+ break;
55
+ }
56
+ }
57
+ yield new Promise(r => setTimeout(r, timeoutCount));
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
+ sendEmail(to, subject, body) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const options = {
66
+ to: to,
67
+ from: this.getCurrentUserEmail(),
68
+ subject: subject,
69
+ html: body
70
+ };
71
+ yield EmailHelper.send(options);
72
+ });
73
+ }
74
+ replyEmail(id, threadId, body) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ yield AuxGoogleAuth.setup();
77
+ const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
78
+ userId: "me",
79
+ id: id,
80
+ format: 'FULL'
81
+ });
82
+ if (gmailResponse.data.payload) {
83
+ const message_subject = this.getHeader('subject', gmailResponse);
84
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
85
+ const reply_to = this.getHeader('reply-to', gmailResponse);
86
+ const options = {
87
+ to: reply_to,
88
+ from: this.getCurrentUserEmail(),
89
+ subject: `Re: ${message_subject}`,
90
+ references: message_messageID,
91
+ inReplyTo: [message_messageID],
92
+ html: body
93
+ };
94
+ yield EmailHelper.send(options, threadId);
95
+ }
96
+ });
97
+ }
98
+ static send(options, threadId) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const mailComposer = new MailComposer(options);
101
+ const message = yield mailComposer.compile().build();
102
+ const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
103
+ yield AuxGoogleAuth.gmailClient.users.messages.send({
104
+ userId: "me",
105
+ requestBody: {
106
+ threadId: threadId,
107
+ raw: encodeMessage
108
+ }
109
+ });
110
+ });
111
+ }
112
+ getHeader(value, headers) {
113
+ for (const header of headers.data.payload.headers) {
114
+ if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
115
+ return header.value;
116
+ }
117
+ }
118
+ }
119
+ getBody(subject, gmailResponse) {
120
+ const body = gmailResponse.data.payload.parts[0].body.data;
121
+ if (body) {
122
+ return atob(body).toLocaleLowerCase();
123
+ }
124
+ else {
125
+ throw new Error(`Email with subject: ${subject} body is empty`);
126
+ }
127
+ }
128
+ getCurrentUserEmail() {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ yield AuxGoogleAuth.setup();
131
+ const profile = yield AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
132
+ return profile.data.emailAddress;
133
+ });
134
+ }
135
+ }
136
+ export default new EmailHelper();