@auxcode/auxta 1.3.23-beta.5 → 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/build/cjs/AuxTA.d.ts +0 -1
- package/build/cjs/AuxTA.js +0 -2
- package/build/cjs/macros/helpers/AuxGoogleAuth.d.ts +0 -5
- package/build/cjs/macros/helpers/AuxGoogleAuth.js +0 -5
- package/build/cjs/macros/helpers/code.helper.d.ts +6 -0
- package/build/cjs/macros/helpers/code.helper.js +69 -2
- package/build/esm/AuxTA.d.ts +0 -1
- package/build/esm/AuxTA.js +0 -2
- package/build/esm/macros/helpers/AuxGoogleAuth.d.ts +0 -5
- package/build/esm/macros/helpers/AuxGoogleAuth.js +0 -5
- package/build/esm/macros/helpers/code.helper.d.ts +6 -0
- package/build/esm/macros/helpers/code.helper.js +69 -2
- package/build/tsconfig-cjs.tsbuildinfo +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/build/cjs/macros/helpers/emailHelper.d.ts +0 -17
- package/build/cjs/macros/helpers/emailHelper.js +0 -120
- package/build/esm/macros/helpers/emailHelper.d.ts +0 -17
- package/build/esm/macros/helpers/emailHelper.js +0 -113
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auxcode/auxta",
|
|
3
|
-
"version": "1.3.23
|
|
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,120 +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 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);
|
|
81
|
-
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
|
|
89
|
-
};
|
|
90
|
-
const mailComposer = new MailComposer(options);
|
|
91
|
-
const message = yield mailComposer.compile().build();
|
|
92
|
-
const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
93
|
-
yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.send({
|
|
94
|
-
userId: "me",
|
|
95
|
-
requestBody: {
|
|
96
|
-
raw: encodeMessage
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
getHeader(value, headers) {
|
|
103
|
-
for (const header of headers) {
|
|
104
|
-
if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
|
|
105
|
-
return header.value.toLocaleLowerCase();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
getBody(from_name, from_email, subject, gmailResponse) {
|
|
110
|
-
const body = gmailResponse.data.payload.parts[0].body.data;
|
|
111
|
-
if (body) {
|
|
112
|
-
return (0, buffer_1.atob)(body).toLocaleLowerCase();
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.EmailHelper = EmailHelper;
|
|
120
|
-
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,113 +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 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);
|
|
75
|
-
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
|
|
83
|
-
};
|
|
84
|
-
const mailComposer = new MailComposer(options);
|
|
85
|
-
const message = yield mailComposer.compile().build();
|
|
86
|
-
const encodeMessage = Buffer.from(message).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
87
|
-
yield AuxGoogleAuth.gmailClient.users.messages.send({
|
|
88
|
-
userId: "me",
|
|
89
|
-
requestBody: {
|
|
90
|
-
raw: encodeMessage
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
getHeader(value, headers) {
|
|
97
|
-
for (const header of headers) {
|
|
98
|
-
if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
|
|
99
|
-
return header.value.toLocaleLowerCase();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
getBody(from_name, from_email, subject, gmailResponse) {
|
|
104
|
-
const body = gmailResponse.data.payload.parts[0].body.data;
|
|
105
|
-
if (body) {
|
|
106
|
-
return atob(body).toLocaleLowerCase();
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
throw new Error(`Email from: ${from_name} ${from_email} with subject: ${subject} body is empty`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
export default new EmailHelper();
|