@auxcode/auxta 1.3.60 → 1.3.62

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.
@@ -1,4 +1,3 @@
1
- import { gmail_v1 } from "googleapis";
2
1
  export declare class EmailHelper {
3
2
  verifyEmail(from_name: string, from_email: string, subject: string, body: string, link?: boolean): Promise<{
4
3
  id: string;
@@ -13,7 +12,5 @@ export declare class EmailHelper {
13
12
  private getCurrentUserEmail;
14
13
  private getUrl;
15
14
  }
16
- export interface gmailResponse extends gmail_v1.Gmail {
17
- }
18
15
  declare const _default: EmailHelper;
19
16
  export default _default;
@@ -21,67 +21,72 @@ const MailComposer = require('nodemailer/lib/mail-composer');
21
21
  class EmailHelper {
22
22
  verifyEmail(from_name, from_email, subject, body, link = false) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- yield AuxGoogleAuth_1.AuxGoogleAuth.setupHeadless();
25
- yield new Promise(r => setTimeout(r, 35000));
26
- let timeoutCount = 12000;
27
- while (timeoutCount <= 60000) {
28
- const res = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.list({
29
- userId: "me",
30
- maxResults: 20
31
- });
32
- const messagesIds = res.data.messages;
33
- if (!messagesIds || messagesIds.length === 0) {
34
- throw new Error('No messagesIds found.');
35
- }
36
- const runs = [];
37
- for (const messageId of messagesIds) {
38
- if (messageId.id) {
39
- runs.push(yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
40
- userId: "me",
41
- id: messageId.id.toString(),
42
- format: 'FULL'
43
- }));
24
+ try {
25
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setupHeadless();
26
+ yield new Promise(r => setTimeout(r, 35000));
27
+ let timeoutCount = 12000;
28
+ while (timeoutCount <= 60000) {
29
+ const res = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.list({
30
+ userId: "me",
31
+ maxResults: 20
32
+ });
33
+ const messagesIds = res.data.messages;
34
+ if (!messagesIds || messagesIds.length === 0) {
35
+ throw new Error('No messagesIds found.');
44
36
  }
45
- }
46
- yield Promise.all(runs);
47
- for (const gmailResponse of runs) {
48
- if (gmailResponse) {
49
- if (gmailResponse.data.payload && gmailResponse.data.id && gmailResponse.data.threadId) {
50
- const message_sender = this.getHeader('from', gmailResponse);
51
- const message_subject = this.getHeader('subject', gmailResponse);
52
- const message_body = this.getBody(subject, gmailResponse);
53
- if (message_sender.toLocaleLowerCase().includes(from_email) && message_sender.toLocaleLowerCase().includes(from_name.toLocaleLowerCase()) &&
54
- message_subject.toLocaleLowerCase().includes(subject.toLocaleLowerCase()) && message_body.toLocaleLowerCase().includes(body.toLocaleLowerCase())) {
55
- log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.PASSED);
56
- yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.modify({
57
- userId: "me",
58
- id: gmailResponse.data.id,
59
- requestBody: {
60
- 'addLabelIds': [],
61
- 'removeLabelIds': ['UNREAD']
62
- }
63
- });
64
- if (link) {
65
- const html_link = yield this.getUrl(message_body);
66
- yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.delete({
37
+ const runs = [];
38
+ for (const messageId of messagesIds) {
39
+ if (messageId.id) {
40
+ runs.push(yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
41
+ userId: "me",
42
+ id: messageId.id.toString(),
43
+ format: 'FULL'
44
+ }));
45
+ }
46
+ }
47
+ yield Promise.all(runs);
48
+ for (const gmailResponse of runs) {
49
+ if (gmailResponse) {
50
+ if (gmailResponse.data.payload && gmailResponse.data.id && gmailResponse.data.threadId) {
51
+ const message_sender = this.getHeader('from', gmailResponse);
52
+ const message_subject = this.getHeader('subject', gmailResponse);
53
+ const message_body = this.getBody(subject, gmailResponse);
54
+ if (message_sender.toLocaleLowerCase().includes(from_email) && message_sender.toLocaleLowerCase().includes(from_name.toLocaleLowerCase()) &&
55
+ message_subject.toLocaleLowerCase().includes(subject.toLocaleLowerCase()) && message_body.toLocaleLowerCase().includes(body.toLocaleLowerCase())) {
56
+ log_service_1.default.push('Then', `Email from: ${from_name} ${from_email} with subject: ${subject} and body: ${body} is found`, AuxTA_1.StepStatus.PASSED);
57
+ yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.modify({
67
58
  userId: "me",
68
59
  id: gmailResponse.data.id,
60
+ requestBody: {
61
+ 'addLabelIds': [],
62
+ 'removeLabelIds': ['UNREAD']
63
+ }
69
64
  });
70
- return {
71
- id: gmailResponse.data.id,
72
- threadId: gmailResponse.data.threadId,
73
- link: html_link
74
- };
65
+ if (link) {
66
+ const html_link = yield this.getUrl(message_body);
67
+ yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.delete({
68
+ userId: "me",
69
+ id: gmailResponse.data.id,
70
+ });
71
+ return {
72
+ id: gmailResponse.data.id,
73
+ threadId: gmailResponse.data.threadId,
74
+ link: html_link
75
+ };
76
+ }
77
+ return { id: gmailResponse.data.id, threadId: gmailResponse.data.threadId, link: '' };
75
78
  }
76
- return { id: gmailResponse.data.id, threadId: gmailResponse.data.threadId, link: '' };
77
79
  }
78
80
  }
79
81
  }
82
+ yield new Promise(r => setTimeout(r, timeoutCount));
83
+ timeoutCount += 12000;
80
84
  }
81
- yield new Promise(r => setTimeout(r, timeoutCount));
82
- timeoutCount += 12000;
85
+ 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);
86
+ }
87
+ catch (e) {
88
+ throw new Error(e);
83
89
  }
84
- 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);
85
90
  });
86
91
  }
87
92
  sendEmail(to, subject, body) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "1.3.60",
3
+ "version": "1.3.62",
4
4
  "description": "",
5
5
  "main": "./build/AuxTA.js",
6
6
  "types": "./build/AuxTA.d.ts",