@auxcode/auxta 1.3.19-beta.1 → 1.3.19-beta.11
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 +3 -0
- package/build/cjs/AuxTA.js +2 -0
- package/build/cjs/auxta/configs/config.d.ts +3 -0
- package/build/cjs/auxta/configs/config.js +2 -0
- package/build/cjs/macros/helpers/AuxGoogleAuth.d.ts +13 -0
- package/build/cjs/macros/helpers/AuxGoogleAuth.js +105 -0
- package/build/cjs/macros/helpers/code.helper.d.ts +2 -0
- package/build/cjs/macros/helpers/code.helper.js +42 -0
- package/build/esm/AuxTA.d.ts +3 -0
- package/build/esm/AuxTA.js +2 -0
- package/build/esm/auxta/configs/config.d.ts +3 -0
- package/build/esm/auxta/configs/config.js +2 -0
- package/build/esm/macros/helpers/AuxGoogleAuth.d.ts +13 -0
- package/build/esm/macros/helpers/AuxGoogleAuth.js +101 -0
- package/build/esm/macros/helpers/code.helper.d.ts +2 -0
- package/build/esm/macros/helpers/code.helper.js +42 -0
- package/build/tsconfig-cjs.tsbuildinfo +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/build/cjs/AuxTA.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { Puppeteer } from "./puppeteer/puppeteer";
|
|
|
2
2
|
import { FunctionHelper } from "./macros/helpers/code.helper";
|
|
3
3
|
import StatusOfStep from "./auxta/enums/status-of.step";
|
|
4
4
|
import { UploadModel } from "./auxta/models/upload.model";
|
|
5
|
+
import { AuxGoogleAuth } from "./macros/helpers/AuxGoogleAuth";
|
|
5
6
|
declare class AuxTA extends FunctionHelper {
|
|
6
7
|
puppeteer: Puppeteer;
|
|
7
8
|
aux2fa: import("./macros/helpers/Aux2faAuth").Aux2faAuth;
|
|
9
|
+
google: typeof AuxGoogleAuth;
|
|
8
10
|
config: {
|
|
9
11
|
auxtaURL: string;
|
|
10
12
|
baseURL: string;
|
|
@@ -17,6 +19,7 @@ declare class AuxTA extends FunctionHelper {
|
|
|
17
19
|
screenHeight: number;
|
|
18
20
|
timeout: number;
|
|
19
21
|
suitesList: never[];
|
|
22
|
+
googleEmail: string;
|
|
20
23
|
auxtaCredentials: {
|
|
21
24
|
email: string;
|
|
22
25
|
password: string;
|
package/build/cjs/AuxTA.js
CHANGED
|
@@ -47,12 +47,14 @@ const config_1 = require("./auxta/configs/config");
|
|
|
47
47
|
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
|
+
const AuxGoogleAuth_1 = require("./macros/helpers/AuxGoogleAuth");
|
|
50
51
|
dotenv.config();
|
|
51
52
|
class AuxTA extends code_helper_1.FunctionHelper {
|
|
52
53
|
constructor() {
|
|
53
54
|
super();
|
|
54
55
|
this.puppeteer = puppeteer_1.default;
|
|
55
56
|
this.aux2fa = Aux2faAuth_1.default;
|
|
57
|
+
this.google = AuxGoogleAuth_1.AuxGoogleAuth;
|
|
56
58
|
this.config = config_1.config;
|
|
57
59
|
let file;
|
|
58
60
|
if (!process.env.RPA) {
|
|
@@ -10,6 +10,7 @@ export declare function setupConfig(jsonConfig: any): {
|
|
|
10
10
|
screenHeight: number;
|
|
11
11
|
timeout: number;
|
|
12
12
|
suitesList: never[];
|
|
13
|
+
googleEmail: string;
|
|
13
14
|
auxtaCredentials: {
|
|
14
15
|
email: string;
|
|
15
16
|
password: string;
|
|
@@ -27,6 +28,7 @@ export declare function setupOverrideConfig(overrideConfig: any): {
|
|
|
27
28
|
screenHeight: number;
|
|
28
29
|
timeout: number;
|
|
29
30
|
suitesList: never[];
|
|
31
|
+
googleEmail: string;
|
|
30
32
|
auxtaCredentials: {
|
|
31
33
|
email: string;
|
|
32
34
|
password: string;
|
|
@@ -44,6 +46,7 @@ export declare let config: {
|
|
|
44
46
|
screenHeight: number;
|
|
45
47
|
timeout: number;
|
|
46
48
|
suitesList: never[];
|
|
49
|
+
googleEmail: string;
|
|
47
50
|
auxtaCredentials: {
|
|
48
51
|
email: string;
|
|
49
52
|
password: string;
|
|
@@ -23,6 +23,7 @@ function setupConfig(jsonConfig) {
|
|
|
23
23
|
if (!jsonConfig.suitesList)
|
|
24
24
|
throw new Error("suitesList");
|
|
25
25
|
exports.config.suitesList = jsonConfig.suitesList;
|
|
26
|
+
exports.config.googleEmail = jsonConfig.googleEmail;
|
|
26
27
|
if (jsonConfig.timeout)
|
|
27
28
|
exports.config.timeout = jsonConfig.timeout;
|
|
28
29
|
if (jsonConfig.screenWidth)
|
|
@@ -56,6 +57,7 @@ exports.config = {
|
|
|
56
57
|
screenHeight: 1080,
|
|
57
58
|
timeout: 60000,
|
|
58
59
|
suitesList: [],
|
|
60
|
+
googleEmail: "",
|
|
59
61
|
auxtaCredentials: {
|
|
60
62
|
email: "",
|
|
61
63
|
password: "",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import googleType = require("googleapis");
|
|
2
|
+
export declare class AuxGoogleAuth {
|
|
3
|
+
private static _oAuth2Client;
|
|
4
|
+
private static credentialsJson;
|
|
5
|
+
static get oAuth2Client(): googleType.Auth.OAuth2Client;
|
|
6
|
+
static get googleClient(): googleType.GoogleApis;
|
|
7
|
+
static get gmailClient(): googleType.gmail_v1.Gmail;
|
|
8
|
+
static setup(): Promise<void>;
|
|
9
|
+
private static authorize;
|
|
10
|
+
private static getNewToken;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: AuxGoogleAuth;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuxGoogleAuth = void 0;
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const readline = require('readline');
|
|
15
|
+
const { google } = require("googleapis");
|
|
16
|
+
const SCOPES = [
|
|
17
|
+
'https://www.googleapis.com/auth/gmail.addons.current.action.compose',
|
|
18
|
+
'https://www.googleapis.com/auth/gmail.addons.current.message.action',
|
|
19
|
+
'https://www.googleapis.com/auth/gmail.labels',
|
|
20
|
+
'https://www.googleapis.com/auth/gmail.addons.current.message.metadata',
|
|
21
|
+
'https://www.googleapis.com/auth/gmail.addons.current.message.readonly',
|
|
22
|
+
'https://www.googleapis.com/auth/gmail.send',
|
|
23
|
+
'https://mail.google.com/',
|
|
24
|
+
'https://www.googleapis.com/auth/gmail.modify',
|
|
25
|
+
'https://www.googleapis.com/auth/gmail.compose',
|
|
26
|
+
'https://www.googleapis.com/auth/gmail.readonly',
|
|
27
|
+
'https://www.googleapis.com/auth/gmail.metadata',
|
|
28
|
+
'https://www.googleapis.com/auth/gmail.insert',
|
|
29
|
+
];
|
|
30
|
+
const TOKEN_PATH = 'token.json';
|
|
31
|
+
class AuxGoogleAuth {
|
|
32
|
+
static get oAuth2Client() {
|
|
33
|
+
return this._oAuth2Client;
|
|
34
|
+
}
|
|
35
|
+
static get googleClient() {
|
|
36
|
+
return google;
|
|
37
|
+
}
|
|
38
|
+
static get gmailClient() {
|
|
39
|
+
return google.gmail({ version: 'v1', auth: this._oAuth2Client });
|
|
40
|
+
}
|
|
41
|
+
static setup() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
yield this.authorize(this.credentialsJson);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
static authorize(credentials) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const { client_secret, client_id, redirect_uris } = credentials.installed;
|
|
49
|
+
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
|
|
50
|
+
try {
|
|
51
|
+
let token = fs.readFileSync(TOKEN_PATH);
|
|
52
|
+
if (token.length > 0 && token !== undefined) {
|
|
53
|
+
oAuth2Client.setCredentials(JSON.parse(token));
|
|
54
|
+
this._oAuth2Client = oAuth2Client;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
yield this.getNewToken(oAuth2Client);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
yield this.getNewToken(oAuth2Client);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
static getNewToken(oAuth2Client) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const authUrl = oAuth2Client.generateAuthUrl({
|
|
67
|
+
access_type: 'offline',
|
|
68
|
+
prompt: 'consent',
|
|
69
|
+
scope: SCOPES,
|
|
70
|
+
});
|
|
71
|
+
console.log('Authorize this app by visiting this url:', authUrl);
|
|
72
|
+
const rl = readline.createInterface({
|
|
73
|
+
input: process.stdin,
|
|
74
|
+
output: process.stdout,
|
|
75
|
+
});
|
|
76
|
+
rl.question('Enter the code from that page here: ', (code) => {
|
|
77
|
+
rl.close();
|
|
78
|
+
oAuth2Client.getToken(code, (err, token) => {
|
|
79
|
+
if (err)
|
|
80
|
+
return console.error('Error retrieving access token', err);
|
|
81
|
+
oAuth2Client.setCredentials(token);
|
|
82
|
+
fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
|
|
83
|
+
if (err)
|
|
84
|
+
return console.error(err);
|
|
85
|
+
console.log('Token stored to', TOKEN_PATH);
|
|
86
|
+
});
|
|
87
|
+
this._oAuth2Client = oAuth2Client;
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.AuxGoogleAuth = AuxGoogleAuth;
|
|
94
|
+
AuxGoogleAuth.credentialsJson = {
|
|
95
|
+
"installed": {
|
|
96
|
+
"client_id": "120362272213-usevfijf76jj5nsr502i2lai6nu71oq8.apps.googleusercontent.com",
|
|
97
|
+
"project_id": "auxta-library",
|
|
98
|
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
|
99
|
+
"token_uri": "https://oauth2.googleapis.com/token",
|
|
100
|
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
|
101
|
+
"client_secret": "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",
|
|
102
|
+
"redirect_uris": ["https://auxcode.com"]
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.default = new AuxGoogleAuth();
|
|
@@ -16,6 +16,8 @@ export declare class FunctionHelper extends ExtendDefaultPage {
|
|
|
16
16
|
clickAndWaitForPageToBeCreated(selector: string, page?: import("puppeteer").Page): Promise<void>;
|
|
17
17
|
closeLastPage(page?: import("puppeteer").Page): Promise<void>;
|
|
18
18
|
microsoftLogin(button: string, email: string, password: string): Promise<void>;
|
|
19
|
+
clickInMail(from_email: string): Promise<boolean | undefined>;
|
|
20
|
+
private getHeader;
|
|
19
21
|
}
|
|
20
22
|
declare const _default: FunctionHelper;
|
|
21
23
|
export default _default;
|
|
@@ -19,6 +19,8 @@ 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 config_1 = require("../../auxta/configs/config");
|
|
22
24
|
class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
|
|
23
25
|
log(keyword, name, status) {
|
|
24
26
|
log_service_1.default.push(keyword, name, status);
|
|
@@ -187,6 +189,46 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
|
|
|
187
189
|
yield loginPage.waitForNetworkIdle();
|
|
188
190
|
});
|
|
189
191
|
}
|
|
192
|
+
clickInMail(from_email) {
|
|
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: config_1.config.googleEmail,
|
|
197
|
+
maxResults: 3
|
|
198
|
+
});
|
|
199
|
+
const messagesIds = res.data.messages;
|
|
200
|
+
if (!messagesIds || messagesIds.length === 0) {
|
|
201
|
+
console.log('No messagesIds found.');
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let timeoutCount = 12000;
|
|
205
|
+
yield this.timeout(12000);
|
|
206
|
+
while (timeoutCount <= 60000) {
|
|
207
|
+
for (const messageId of messagesIds) {
|
|
208
|
+
if (messageId.id) {
|
|
209
|
+
const message = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({ userId: config_1.config.googleEmail, id: messageId.id.toString(), format: 'FULL' });
|
|
210
|
+
if (message.data.payload) {
|
|
211
|
+
const sender = this.getHeader('sender', message.data.payload.headers);
|
|
212
|
+
if (sender.toLocaleLowerCase().includes(from_email.toLocaleLowerCase())) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
yield this.timeout(12000);
|
|
220
|
+
timeoutCount += 12000;
|
|
221
|
+
}
|
|
222
|
+
return false;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
getHeader(value, headers) {
|
|
226
|
+
for (const header of headers) {
|
|
227
|
+
if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
|
|
228
|
+
return header.value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
190
232
|
}
|
|
191
233
|
exports.FunctionHelper = FunctionHelper;
|
|
192
234
|
exports.default = new FunctionHelper();
|
package/build/esm/AuxTA.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { Puppeteer } from "./puppeteer/puppeteer";
|
|
|
2
2
|
import { FunctionHelper } from "./macros/helpers/code.helper";
|
|
3
3
|
import StatusOfStep from "./auxta/enums/status-of.step";
|
|
4
4
|
import { UploadModel } from "./auxta/models/upload.model";
|
|
5
|
+
import { AuxGoogleAuth } from "./macros/helpers/AuxGoogleAuth";
|
|
5
6
|
declare class AuxTA extends FunctionHelper {
|
|
6
7
|
puppeteer: Puppeteer;
|
|
7
8
|
aux2fa: import("./macros/helpers/Aux2faAuth").Aux2faAuth;
|
|
9
|
+
google: typeof AuxGoogleAuth;
|
|
8
10
|
config: {
|
|
9
11
|
auxtaURL: string;
|
|
10
12
|
baseURL: string;
|
|
@@ -17,6 +19,7 @@ declare class AuxTA extends FunctionHelper {
|
|
|
17
19
|
screenHeight: number;
|
|
18
20
|
timeout: number;
|
|
19
21
|
suitesList: never[];
|
|
22
|
+
googleEmail: string;
|
|
20
23
|
auxtaCredentials: {
|
|
21
24
|
email: string;
|
|
22
25
|
password: string;
|
package/build/esm/AuxTA.js
CHANGED
|
@@ -18,12 +18,14 @@ import { setupConfig, config as c, setupOverrideConfig } from "./auxta/configs/c
|
|
|
18
18
|
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
|
+
import { AuxGoogleAuth } from "./macros/helpers/AuxGoogleAuth";
|
|
21
22
|
dotenv.config();
|
|
22
23
|
class AuxTA extends FunctionHelper {
|
|
23
24
|
constructor() {
|
|
24
25
|
super();
|
|
25
26
|
this.puppeteer = puppeteer;
|
|
26
27
|
this.aux2fa = Aux2faAuth;
|
|
28
|
+
this.google = AuxGoogleAuth;
|
|
27
29
|
this.config = c;
|
|
28
30
|
let file;
|
|
29
31
|
if (!process.env.RPA) {
|
|
@@ -10,6 +10,7 @@ export declare function setupConfig(jsonConfig: any): {
|
|
|
10
10
|
screenHeight: number;
|
|
11
11
|
timeout: number;
|
|
12
12
|
suitesList: never[];
|
|
13
|
+
googleEmail: string;
|
|
13
14
|
auxtaCredentials: {
|
|
14
15
|
email: string;
|
|
15
16
|
password: string;
|
|
@@ -27,6 +28,7 @@ export declare function setupOverrideConfig(overrideConfig: any): {
|
|
|
27
28
|
screenHeight: number;
|
|
28
29
|
timeout: number;
|
|
29
30
|
suitesList: never[];
|
|
31
|
+
googleEmail: string;
|
|
30
32
|
auxtaCredentials: {
|
|
31
33
|
email: string;
|
|
32
34
|
password: string;
|
|
@@ -44,6 +46,7 @@ export declare let config: {
|
|
|
44
46
|
screenHeight: number;
|
|
45
47
|
timeout: number;
|
|
46
48
|
suitesList: never[];
|
|
49
|
+
googleEmail: string;
|
|
47
50
|
auxtaCredentials: {
|
|
48
51
|
email: string;
|
|
49
52
|
password: string;
|
|
@@ -20,6 +20,7 @@ export function setupConfig(jsonConfig) {
|
|
|
20
20
|
if (!jsonConfig.suitesList)
|
|
21
21
|
throw new Error("suitesList");
|
|
22
22
|
config.suitesList = jsonConfig.suitesList;
|
|
23
|
+
config.googleEmail = jsonConfig.googleEmail;
|
|
23
24
|
if (jsonConfig.timeout)
|
|
24
25
|
config.timeout = jsonConfig.timeout;
|
|
25
26
|
if (jsonConfig.screenWidth)
|
|
@@ -51,6 +52,7 @@ export let config = {
|
|
|
51
52
|
screenHeight: 1080,
|
|
52
53
|
timeout: 60000,
|
|
53
54
|
suitesList: [],
|
|
55
|
+
googleEmail: "",
|
|
54
56
|
auxtaCredentials: {
|
|
55
57
|
email: "",
|
|
56
58
|
password: "",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import googleType = require("googleapis");
|
|
2
|
+
export declare class AuxGoogleAuth {
|
|
3
|
+
private static _oAuth2Client;
|
|
4
|
+
private static credentialsJson;
|
|
5
|
+
static get oAuth2Client(): googleType.Auth.OAuth2Client;
|
|
6
|
+
static get googleClient(): googleType.GoogleApis;
|
|
7
|
+
static get gmailClient(): googleType.gmail_v1.Gmail;
|
|
8
|
+
static setup(): Promise<void>;
|
|
9
|
+
private static authorize;
|
|
10
|
+
private static getNewToken;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: AuxGoogleAuth;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
const fs = require('fs');
|
|
11
|
+
const readline = require('readline');
|
|
12
|
+
const { google } = require("googleapis");
|
|
13
|
+
const SCOPES = [
|
|
14
|
+
'https://www.googleapis.com/auth/gmail.addons.current.action.compose',
|
|
15
|
+
'https://www.googleapis.com/auth/gmail.addons.current.message.action',
|
|
16
|
+
'https://www.googleapis.com/auth/gmail.labels',
|
|
17
|
+
'https://www.googleapis.com/auth/gmail.addons.current.message.metadata',
|
|
18
|
+
'https://www.googleapis.com/auth/gmail.addons.current.message.readonly',
|
|
19
|
+
'https://www.googleapis.com/auth/gmail.send',
|
|
20
|
+
'https://mail.google.com/',
|
|
21
|
+
'https://www.googleapis.com/auth/gmail.modify',
|
|
22
|
+
'https://www.googleapis.com/auth/gmail.compose',
|
|
23
|
+
'https://www.googleapis.com/auth/gmail.readonly',
|
|
24
|
+
'https://www.googleapis.com/auth/gmail.metadata',
|
|
25
|
+
'https://www.googleapis.com/auth/gmail.insert',
|
|
26
|
+
];
|
|
27
|
+
const TOKEN_PATH = 'token.json';
|
|
28
|
+
export class AuxGoogleAuth {
|
|
29
|
+
static get oAuth2Client() {
|
|
30
|
+
return this._oAuth2Client;
|
|
31
|
+
}
|
|
32
|
+
static get googleClient() {
|
|
33
|
+
return google;
|
|
34
|
+
}
|
|
35
|
+
static get gmailClient() {
|
|
36
|
+
return google.gmail({ version: 'v1', auth: this._oAuth2Client });
|
|
37
|
+
}
|
|
38
|
+
static setup() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
yield this.authorize(this.credentialsJson);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
static authorize(credentials) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const { client_secret, client_id, redirect_uris } = credentials.installed;
|
|
46
|
+
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
|
|
47
|
+
try {
|
|
48
|
+
let token = fs.readFileSync(TOKEN_PATH);
|
|
49
|
+
if (token.length > 0 && token !== undefined) {
|
|
50
|
+
oAuth2Client.setCredentials(JSON.parse(token));
|
|
51
|
+
this._oAuth2Client = oAuth2Client;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
yield this.getNewToken(oAuth2Client);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
yield this.getNewToken(oAuth2Client);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
static getNewToken(oAuth2Client) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const authUrl = oAuth2Client.generateAuthUrl({
|
|
64
|
+
access_type: 'offline',
|
|
65
|
+
prompt: 'consent',
|
|
66
|
+
scope: SCOPES,
|
|
67
|
+
});
|
|
68
|
+
console.log('Authorize this app by visiting this url:', authUrl);
|
|
69
|
+
const rl = readline.createInterface({
|
|
70
|
+
input: process.stdin,
|
|
71
|
+
output: process.stdout,
|
|
72
|
+
});
|
|
73
|
+
rl.question('Enter the code from that page here: ', (code) => {
|
|
74
|
+
rl.close();
|
|
75
|
+
oAuth2Client.getToken(code, (err, token) => {
|
|
76
|
+
if (err)
|
|
77
|
+
return console.error('Error retrieving access token', err);
|
|
78
|
+
oAuth2Client.setCredentials(token);
|
|
79
|
+
fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
|
|
80
|
+
if (err)
|
|
81
|
+
return console.error(err);
|
|
82
|
+
console.log('Token stored to', TOKEN_PATH);
|
|
83
|
+
});
|
|
84
|
+
this._oAuth2Client = oAuth2Client;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
AuxGoogleAuth.credentialsJson = {
|
|
91
|
+
"installed": {
|
|
92
|
+
"client_id": "120362272213-usevfijf76jj5nsr502i2lai6nu71oq8.apps.googleusercontent.com",
|
|
93
|
+
"project_id": "auxta-library",
|
|
94
|
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
|
95
|
+
"token_uri": "https://oauth2.googleapis.com/token",
|
|
96
|
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
|
97
|
+
"client_secret": "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",
|
|
98
|
+
"redirect_uris": ["https://auxcode.com"]
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
export default new AuxGoogleAuth();
|
|
@@ -16,6 +16,8 @@ export declare class FunctionHelper extends ExtendDefaultPage {
|
|
|
16
16
|
clickAndWaitForPageToBeCreated(selector: string, page?: import("puppeteer").Page): Promise<void>;
|
|
17
17
|
closeLastPage(page?: import("puppeteer").Page): Promise<void>;
|
|
18
18
|
microsoftLogin(button: string, email: string, password: string): Promise<void>;
|
|
19
|
+
clickInMail(from_email: string): Promise<boolean | undefined>;
|
|
20
|
+
private getHeader;
|
|
19
21
|
}
|
|
20
22
|
declare const _default: FunctionHelper;
|
|
21
23
|
export default _default;
|
|
@@ -13,6 +13,8 @@ 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 { config } from "../../auxta/configs/config";
|
|
16
18
|
export class FunctionHelper extends ExtendDefaultPage {
|
|
17
19
|
log(keyword, name, status) {
|
|
18
20
|
log.push(keyword, name, status);
|
|
@@ -181,5 +183,45 @@ export class FunctionHelper extends ExtendDefaultPage {
|
|
|
181
183
|
yield loginPage.waitForNetworkIdle();
|
|
182
184
|
});
|
|
183
185
|
}
|
|
186
|
+
clickInMail(from_email) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
yield AuxGoogleAuth.setup();
|
|
189
|
+
const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
|
|
190
|
+
userId: config.googleEmail,
|
|
191
|
+
maxResults: 3
|
|
192
|
+
});
|
|
193
|
+
const messagesIds = res.data.messages;
|
|
194
|
+
if (!messagesIds || messagesIds.length === 0) {
|
|
195
|
+
console.log('No messagesIds found.');
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
let timeoutCount = 12000;
|
|
199
|
+
yield this.timeout(12000);
|
|
200
|
+
while (timeoutCount <= 60000) {
|
|
201
|
+
for (const messageId of messagesIds) {
|
|
202
|
+
if (messageId.id) {
|
|
203
|
+
const message = yield AuxGoogleAuth.gmailClient.users.messages.get({ userId: config.googleEmail, id: messageId.id.toString(), format: 'FULL' });
|
|
204
|
+
if (message.data.payload) {
|
|
205
|
+
const sender = this.getHeader('sender', message.data.payload.headers);
|
|
206
|
+
if (sender.toLocaleLowerCase().includes(from_email.toLocaleLowerCase())) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
yield this.timeout(12000);
|
|
214
|
+
timeoutCount += 12000;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
getHeader(value, headers) {
|
|
220
|
+
for (const header of headers) {
|
|
221
|
+
if (header.name.toLocaleLowerCase() === value.toLocaleLowerCase()) {
|
|
222
|
+
return header.value;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
184
226
|
}
|
|
185
227
|
export default new FunctionHelper();
|