@auxcode/auxta 1.3.23-beta.5 → 1.3.23-beta.7

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.
@@ -5,7 +5,6 @@ export declare class AuxGoogleAuth {
5
5
  static get oAuth2Client(): googleType.Auth.OAuth2Client;
6
6
  static get googleClient(): googleType.GoogleApis;
7
7
  static get gmailClient(): googleType.gmail_v1.Gmail;
8
- static get currentUser(): currentUser;
9
8
  static setup(): Promise<void>;
10
9
  private static authorize;
11
10
  private static getNewToken;
@@ -37,11 +37,6 @@ class AuxGoogleAuth {
37
37
  static get gmailClient() {
38
38
  return google.gmail({ version: 'v1', auth: this._oAuth2Client });
39
39
  }
40
- static get currentUser() {
41
- const auth2 = google.auth2.getAuthInstance();
42
- const profile = auth2.currentUser.get().getBasicProfile();
43
- return { name: profile.getName(), email: profile.profile.getEmail() };
44
- }
45
40
  static setup() {
46
41
  return __awaiter(this, void 0, void 0, function* () {
47
42
  yield this.authorize(this.credentialsJson);
@@ -89,7 +89,7 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
89
89
  }
90
90
  timeout(timeout = this.defaultTimeout, page = puppeteer_1.default.defaultPage) {
91
91
  return __awaiter(this, void 0, void 0, function* () {
92
- new Promise(r => setTimeout(r, timeout));
92
+ yield new Promise(r => setTimeout(r, timeout));
93
93
  });
94
94
  }
95
95
  waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer_1.default.defaultPage, log_message = true) {
@@ -1,15 +1,10 @@
1
1
  import { gmail_v1 } from "googleapis";
2
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>;
3
+ verifyEmail(from_name: string, from_email: string, subject: string, body: string, reply?: boolean, reply_body?: string): Promise<void>;
4
+ private replyEmail;
11
5
  private getHeader;
12
6
  private getBody;
7
+ private getCurrentUserEmail;
13
8
  }
14
9
  export interface gmailResponse extends gmail_v1.Gmail {
15
10
  }
@@ -19,7 +19,7 @@ const buffer_1 = require("buffer");
19
19
  const AuxTA_1 = require("../../AuxTA");
20
20
  const MailComposer = require('nodemailer/lib/mail-composer');
21
21
  class EmailHelper {
22
- verifyEmail(from_name, from_email, subject, body) {
22
+ verifyEmail(from_name, from_email, subject, body, reply = false, reply_body) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
25
25
  const res = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.list({
@@ -40,9 +40,9 @@ class EmailHelper {
40
40
  format: 'FULL'
41
41
  });
42
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);
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
46
  if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
47
47
  message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
48
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);
@@ -54,38 +54,39 @@ class EmailHelper {
54
54
  'removeLabelIds': ['UNREAD']
55
55
  }
56
56
  });
57
- return { id: gmailResponse.data.id.toString(), threadId: gmailResponse.data.threadId.toString() };
57
+ if (reply && reply_body) {
58
+ yield this.replyEmail(gmailResponse.data.id.toString(), gmailResponse.data.threadId.toString(), reply_body);
59
+ }
58
60
  }
59
61
  }
60
62
  break;
61
63
  }
62
64
  }
63
- new Promise(r => setTimeout(r, 12000));
65
+ yield new Promise(r => setTimeout(r, timeoutCount));
64
66
  timeoutCount += 12000;
65
67
  }
66
68
  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
69
  });
68
70
  }
69
- replyEmail(ids, body) {
71
+ replyEmail(id, threadId, body) {
70
72
  return __awaiter(this, void 0, void 0, function* () {
71
73
  yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
72
74
  const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
73
75
  userId: "me",
74
- id: ids.id,
76
+ id: id,
75
77
  format: 'FULL'
76
78
  });
77
79
  if (gmailResponse.data.payload) {
78
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
79
- const message_messageID = this.getHeader('Message-ID', gmailResponse.data.payload.headers);
80
- const reply_to = this.getHeader('reply-to', gmailResponse.data.payload.headers);
80
+ const message_subject = this.getHeader('subject', gmailResponse);
81
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
82
+ const reply_to = this.getHeader('reply-to', gmailResponse);
81
83
  const options = {
82
- "to": reply_to,
83
- "from": AuxGoogleAuth_1.AuxGoogleAuth.currentUser.email,
84
- "subject": `Re: ${message_subject}`,
85
- "References": message_messageID,
86
- "In-Reply-To": message_messageID,
87
- "threadId": ids.threadId,
88
- "html": body
84
+ to: reply_to,
85
+ from: this.getCurrentUserEmail(),
86
+ subject: `Re: ${message_subject}`,
87
+ references: message_messageID,
88
+ inReplyTo: [message_messageID],
89
+ html: body
89
90
  };
90
91
  const mailComposer = new MailComposer(options);
91
92
  const message = yield mailComposer.compile().build();
@@ -93,6 +94,7 @@ class EmailHelper {
93
94
  yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.send({
94
95
  userId: "me",
95
96
  requestBody: {
97
+ threadId: threadId,
96
98
  raw: encodeMessage
97
99
  }
98
100
  });
@@ -100,21 +102,28 @@ class EmailHelper {
100
102
  });
101
103
  }
102
104
  getHeader(value, headers) {
103
- for (const header of headers) {
105
+ for (const header of headers.data.payload.headers) {
104
106
  if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
105
107
  return header.value.toLocaleLowerCase();
106
108
  }
107
109
  }
108
110
  }
109
- getBody(from_name, from_email, subject, gmailResponse) {
111
+ getBody(subject, gmailResponse) {
110
112
  const body = gmailResponse.data.payload.parts[0].body.data;
111
113
  if (body) {
112
114
  return (0, buffer_1.atob)(body).toLocaleLowerCase();
113
115
  }
114
116
  else {
115
- throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
117
+ throw new Error(`Email with subject: ${subject} body is empty`);
116
118
  }
117
119
  }
120
+ getCurrentUserEmail() {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
123
+ const profile = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
124
+ return profile.data.emailAddress;
125
+ });
126
+ }
118
127
  }
119
128
  exports.EmailHelper = EmailHelper;
120
129
  exports.default = new EmailHelper();
@@ -1,5 +1,5 @@
1
1
  export declare class ExtendDefaultPage {
2
- defaultTimeout: number;
2
+ readonly defaultTimeout: number;
3
3
  extend_page_functions(page: any, time?: number): Promise<any>;
4
4
  }
5
5
  declare const _default: ExtendDefaultPage;
@@ -22,7 +22,6 @@ class ExtendDefaultPage {
22
22
  }
23
23
  extend_page_functions(page, time = this.defaultTimeout) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- this.defaultTimeout = config_1.config.timeout;
26
25
  const { goto: original_goto, click: original_click, type: original_type, waitForNetworkIdle: original_waitForNetworkIdle } = page;
27
26
  page.goto = function goto(url, options) {
28
27
  log_service_1.default.push('Then', `I go to the '${url}' page`, status_of_step_1.StatusOfStep.PASSED);
@@ -5,7 +5,6 @@ export declare class AuxGoogleAuth {
5
5
  static get oAuth2Client(): googleType.Auth.OAuth2Client;
6
6
  static get googleClient(): googleType.GoogleApis;
7
7
  static get gmailClient(): googleType.gmail_v1.Gmail;
8
- static get currentUser(): currentUser;
9
8
  static setup(): Promise<void>;
10
9
  private static authorize;
11
10
  private static getNewToken;
@@ -34,11 +34,6 @@ export class AuxGoogleAuth {
34
34
  static get gmailClient() {
35
35
  return google.gmail({ version: 'v1', auth: this._oAuth2Client });
36
36
  }
37
- static get currentUser() {
38
- const auth2 = google.auth2.getAuthInstance();
39
- const profile = auth2.currentUser.get().getBasicProfile();
40
- return { name: profile.getName(), email: profile.profile.getEmail() };
41
- }
42
37
  static setup() {
43
38
  return __awaiter(this, void 0, void 0, function* () {
44
39
  yield this.authorize(this.credentialsJson);
@@ -83,7 +83,7 @@ export class FunctionHelper extends ExtendDefaultPage {
83
83
  }
84
84
  timeout(timeout = this.defaultTimeout, page = puppeteer.defaultPage) {
85
85
  return __awaiter(this, void 0, void 0, function* () {
86
- new Promise(r => setTimeout(r, timeout));
86
+ yield new Promise(r => setTimeout(r, timeout));
87
87
  });
88
88
  }
89
89
  waitForSelector(option, selector, time = this.defaultTimeout, page = puppeteer.defaultPage, log_message = true) {
@@ -1,15 +1,10 @@
1
1
  import { gmail_v1 } from "googleapis";
2
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>;
3
+ verifyEmail(from_name: string, from_email: string, subject: string, body: string, reply?: boolean, reply_body?: string): Promise<void>;
4
+ private replyEmail;
11
5
  private getHeader;
12
6
  private getBody;
7
+ private getCurrentUserEmail;
13
8
  }
14
9
  export interface gmailResponse extends gmail_v1.Gmail {
15
10
  }
@@ -13,7 +13,7 @@ import { atob } from "buffer";
13
13
  import { StepStatus } from "../../AuxTA";
14
14
  const MailComposer = require('nodemailer/lib/mail-composer');
15
15
  export class EmailHelper {
16
- verifyEmail(from_name, from_email, subject, body) {
16
+ verifyEmail(from_name, from_email, subject, body, reply = false, reply_body) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  yield AuxGoogleAuth.setup();
19
19
  const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
@@ -34,9 +34,9 @@ export class EmailHelper {
34
34
  format: 'FULL'
35
35
  });
36
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);
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
40
  if (message_sender.includes(from_email) && message_sender.includes(from_name.toLocaleLowerCase()) &&
41
41
  message_subject.includes(subject.toLocaleLowerCase()) && message_body.includes(body.toLocaleLowerCase())) {
42
42
  log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.PASSED);
@@ -48,38 +48,39 @@ export class EmailHelper {
48
48
  'removeLabelIds': ['UNREAD']
49
49
  }
50
50
  });
51
- return { id: gmailResponse.data.id.toString(), threadId: gmailResponse.data.threadId.toString() };
51
+ if (reply && reply_body) {
52
+ yield this.replyEmail(gmailResponse.data.id.toString(), gmailResponse.data.threadId.toString(), reply_body);
53
+ }
52
54
  }
53
55
  }
54
56
  break;
55
57
  }
56
58
  }
57
- new Promise(r => setTimeout(r, 12000));
59
+ yield new Promise(r => setTimeout(r, timeoutCount));
58
60
  timeoutCount += 12000;
59
61
  }
60
62
  yield log.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, StepStatus.FAILED);
61
63
  });
62
64
  }
63
- replyEmail(ids, body) {
65
+ replyEmail(id, threadId, body) {
64
66
  return __awaiter(this, void 0, void 0, function* () {
65
67
  yield AuxGoogleAuth.setup();
66
68
  const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
67
69
  userId: "me",
68
- id: ids.id,
70
+ id: id,
69
71
  format: 'FULL'
70
72
  });
71
73
  if (gmailResponse.data.payload) {
72
- const message_subject = this.getHeader('subject', gmailResponse.data.payload.headers);
73
- const message_messageID = this.getHeader('Message-ID', gmailResponse.data.payload.headers);
74
- const reply_to = this.getHeader('reply-to', gmailResponse.data.payload.headers);
74
+ const message_subject = this.getHeader('subject', gmailResponse);
75
+ const message_messageID = this.getHeader('Message-ID', gmailResponse);
76
+ const reply_to = this.getHeader('reply-to', gmailResponse);
75
77
  const options = {
76
- "to": reply_to,
77
- "from": AuxGoogleAuth.currentUser.email,
78
- "subject": `Re: ${message_subject}`,
79
- "References": message_messageID,
80
- "In-Reply-To": message_messageID,
81
- "threadId": ids.threadId,
82
- "html": body
78
+ to: reply_to,
79
+ from: this.getCurrentUserEmail(),
80
+ subject: `Re: ${message_subject}`,
81
+ references: message_messageID,
82
+ inReplyTo: [message_messageID],
83
+ html: body
83
84
  };
84
85
  const mailComposer = new MailComposer(options);
85
86
  const message = yield mailComposer.compile().build();
@@ -87,6 +88,7 @@ export class EmailHelper {
87
88
  yield AuxGoogleAuth.gmailClient.users.messages.send({
88
89
  userId: "me",
89
90
  requestBody: {
91
+ threadId: threadId,
90
92
  raw: encodeMessage
91
93
  }
92
94
  });
@@ -94,20 +96,27 @@ export class EmailHelper {
94
96
  });
95
97
  }
96
98
  getHeader(value, headers) {
97
- for (const header of headers) {
99
+ for (const header of headers.data.payload.headers) {
98
100
  if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
99
101
  return header.value.toLocaleLowerCase();
100
102
  }
101
103
  }
102
104
  }
103
- getBody(from_name, from_email, subject, gmailResponse) {
105
+ getBody(subject, gmailResponse) {
104
106
  const body = gmailResponse.data.payload.parts[0].body.data;
105
107
  if (body) {
106
108
  return atob(body).toLocaleLowerCase();
107
109
  }
108
110
  else {
109
- throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
111
+ throw new Error(`Email with subject: ${subject} body is empty`);
110
112
  }
111
113
  }
114
+ getCurrentUserEmail() {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ yield AuxGoogleAuth.setup();
117
+ const profile = yield AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
118
+ return profile.data.emailAddress;
119
+ });
120
+ }
112
121
  }
113
122
  export default new EmailHelper();
@@ -1,5 +1,5 @@
1
1
  export declare class ExtendDefaultPage {
2
- defaultTimeout: number;
2
+ readonly defaultTimeout: number;
3
3
  extend_page_functions(page: any, time?: number): Promise<any>;
4
4
  }
5
5
  declare const _default: ExtendDefaultPage;
@@ -16,7 +16,6 @@ export class ExtendDefaultPage {
16
16
  }
17
17
  extend_page_functions(page, time = this.defaultTimeout) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
- this.defaultTimeout = config.timeout;
20
19
  const { goto: original_goto, click: original_click, type: original_type, waitForNetworkIdle: original_waitForNetworkIdle } = page;
21
20
  page.goto = function goto(url, options) {
22
21
  log.push('Then', `I go to the '${url}' page`, StatusOfStep.PASSED);