@auxcode/auxta 1.3.51-beta.6 → 1.3.51-beta.8

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,9 +5,14 @@ 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 setup(): Promise<void>;
8
+ static setupBrowser(): Promise<void>;
9
+ static setEmailPassword(email: string, password: string): Promise<void>;
10
+ static setupHeadless(): Promise<void>;
9
11
  private static authorize;
12
+ private static authorizeHeadless;
10
13
  private static getNewToken;
14
+ private static getNewTokenHeadless;
15
+ private static LogIn;
11
16
  }
12
17
  declare const _default: AuxGoogleAuth;
13
18
  export default _default;
@@ -8,10 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.AuxGoogleAuth = void 0;
13
16
  const fs = require('fs');
14
17
  const readline = require('readline');
18
+ const puppeteer_1 = __importDefault(require("../../puppeteer/puppeteer"));
19
+ const code_helper_1 = __importDefault(require("../helpers/code.helper"));
15
20
  const { google } = require("googleapis");
16
21
  const SCOPES = [
17
22
  'https://www.googleapis.com/auth/gmail.addons.current.action.compose',
@@ -27,6 +32,9 @@ const SCOPES = [
27
32
  'https://www.googleapis.com/auth/gmail.insert',
28
33
  ];
29
34
  const TOKEN_PATH = 'token.json';
35
+ let TOKEN = '';
36
+ let EMAIL = '';
37
+ let PASSWORD = '';
30
38
  class AuxGoogleAuth {
31
39
  static get oAuth2Client() {
32
40
  return this._oAuth2Client;
@@ -37,11 +45,22 @@ class AuxGoogleAuth {
37
45
  static get gmailClient() {
38
46
  return google.gmail({ version: 'v1', auth: this._oAuth2Client });
39
47
  }
40
- static setup() {
48
+ static setupBrowser() {
41
49
  return __awaiter(this, void 0, void 0, function* () {
42
50
  yield this.authorize(this.credentialsJson);
43
51
  });
44
52
  }
53
+ static setEmailPassword(email, password) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ EMAIL = email;
56
+ PASSWORD = password;
57
+ });
58
+ }
59
+ static setupHeadless() {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ yield this.authorizeHeadless(this.credentialsJson);
62
+ });
63
+ }
45
64
  static authorize(credentials) {
46
65
  return __awaiter(this, void 0, void 0, function* () {
47
66
  const { client_secret, client_id, redirect_uris } = credentials.installed;
@@ -60,6 +79,23 @@ class AuxGoogleAuth {
60
79
  }
61
80
  });
62
81
  }
82
+ static authorizeHeadless(credentials) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const { client_secret, client_id, redirect_uris } = credentials.installed;
85
+ const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
86
+ try {
87
+ if (TOKEN.length > 0) {
88
+ oAuth2Client.setCredentials(JSON.parse(TOKEN));
89
+ this._oAuth2Client = oAuth2Client;
90
+ return;
91
+ }
92
+ yield this.getNewTokenHeadless(oAuth2Client);
93
+ }
94
+ catch (e) {
95
+ yield this.getNewTokenHeadless(oAuth2Client);
96
+ }
97
+ });
98
+ }
63
99
  static getNewToken(oAuth2Client) {
64
100
  return __awaiter(this, void 0, void 0, function* () {
65
101
  const authUrl = oAuth2Client.generateAuthUrl({
@@ -88,6 +124,50 @@ class AuxGoogleAuth {
88
124
  });
89
125
  });
90
126
  }
127
+ static getNewTokenHeadless(oAuth2Client) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ const authUrl = oAuth2Client.generateAuthUrl({
130
+ access_type: 'offline',
131
+ prompt: 'consent',
132
+ scope: SCOPES,
133
+ });
134
+ const code = yield this.LogIn(authUrl);
135
+ oAuth2Client.getToken(code, (err, token) => {
136
+ if (err)
137
+ return console.error('Error retrieving access token', err);
138
+ oAuth2Client.setCredentials(token);
139
+ TOKEN = token;
140
+ this._oAuth2Client = oAuth2Client;
141
+ });
142
+ });
143
+ }
144
+ static LogIn(authUrl) {
145
+ var _a, _b, _c;
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ const context = yield puppeteer_1.default.defaultPage.browser().createIncognitoBrowserContext();
148
+ const page = yield context.newPage();
149
+ yield page.goto(authUrl);
150
+ yield page.waitForNetworkIdle();
151
+ yield code_helper_1.default.waitForSelector('visible', '#identifierId');
152
+ yield ((_a = (yield page.$('#identifierId'))) === null || _a === void 0 ? void 0 : _a.type(EMAIL));
153
+ yield (yield page.$$('button'))[3].click();
154
+ yield page.waitForNetworkIdle();
155
+ yield code_helper_1.default.waitForSelector('visible', 'input[type="password"]');
156
+ yield ((_b = (yield page.$('input[type="password"]'))) === null || _b === void 0 ? void 0 : _b.type(PASSWORD));
157
+ yield (yield page.$$('button'))[1].click();
158
+ yield page.waitForNetworkIdle();
159
+ yield code_helper_1.default.waitForSelector('visible', '#headingText');
160
+ yield (yield page.$$('button'))[2].click();
161
+ yield page.waitForNetworkIdle();
162
+ yield code_helper_1.default.waitForSelector('visible', 'input[type="checkbox"]');
163
+ yield ((_c = (yield page.$('input[type="checkbox"]'))) === null || _c === void 0 ? void 0 : _c.click());
164
+ yield (yield page.$$('button'))[2].click();
165
+ yield page.waitForNetworkIdle();
166
+ const currentUrl = page.url();
167
+ const code = currentUrl.substring(currentUrl.indexOf("code=") + 5, currentUrl.lastIndexOf("&"));
168
+ return decodeURIComponent(code);
169
+ });
170
+ }
91
171
  }
92
172
  exports.AuxGoogleAuth = AuxGoogleAuth;
93
173
  AuxGoogleAuth.credentialsJson = {
@@ -40,11 +40,11 @@ class FunctionHelper extends extend_default_page_1.ExtendDefaultPage {
40
40
  if (screenshotBuffer) {
41
41
  const screenshot = screenshotBuffer.toString('base64');
42
42
  yield (0, report_service_1.compareScreenshots)(key, screenshot);
43
- log_service_1.default.push('Then', `compare screenshots with key ${key}`, status_of_step_1.StatusOfStep.PASSED, screenshot, key);
43
+ log_service_1.default.push('Then', `I compare screenshots with key ${key}`, status_of_step_1.StatusOfStep.PASSED, screenshot, key);
44
44
  }
45
45
  }
46
46
  else {
47
- log_service_1.default.push('Then', `compare screenshots with key ${key}`, status_of_step_1.StatusOfStep.PASSED, undefined, key);
47
+ log_service_1.default.push('Then', `I compare screenshots with key ${key}`, status_of_step_1.StatusOfStep.PASSED, undefined, key);
48
48
  }
49
49
  });
50
50
  }
@@ -21,7 +21,7 @@ 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.setup();
24
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setupHeadless();
25
25
  let timeoutCount = 12000;
26
26
  while (timeoutCount <= 60000) {
27
27
  const res = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.list({
@@ -76,7 +76,7 @@ class EmailHelper {
76
76
  }
77
77
  sendEmail(to, subject, body) {
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
- yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
79
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setupHeadless();
80
80
  const options = {
81
81
  to: to,
82
82
  from: this.getCurrentUserEmail(),
@@ -88,7 +88,7 @@ class EmailHelper {
88
88
  }
89
89
  replyEmail(id, threadId, body) {
90
90
  return __awaiter(this, void 0, void 0, function* () {
91
- yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
91
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setupHeadless();
92
92
  const gmailResponse = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.messages.get({
93
93
  userId: "me",
94
94
  id: id,
@@ -148,7 +148,7 @@ class EmailHelper {
148
148
  }
149
149
  getCurrentUserEmail() {
150
150
  return __awaiter(this, void 0, void 0, function* () {
151
- yield AuxGoogleAuth_1.AuxGoogleAuth.setup();
151
+ yield AuxGoogleAuth_1.AuxGoogleAuth.setupHeadless();
152
152
  const profile = yield AuxGoogleAuth_1.AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
153
153
  return profile.data.emailAddress;
154
154
  });
@@ -5,9 +5,14 @@ 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 setup(): Promise<void>;
8
+ static setupBrowser(): Promise<void>;
9
+ static setEmailPassword(email: string, password: string): Promise<void>;
10
+ static setupHeadless(): Promise<void>;
9
11
  private static authorize;
12
+ private static authorizeHeadless;
10
13
  private static getNewToken;
14
+ private static getNewTokenHeadless;
15
+ private static LogIn;
11
16
  }
12
17
  declare const _default: AuxGoogleAuth;
13
18
  export default _default;
@@ -9,6 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  const fs = require('fs');
11
11
  const readline = require('readline');
12
+ import puppeteer from "../../puppeteer/puppeteer";
13
+ import FunctionHelper from "../helpers/code.helper";
12
14
  const { google } = require("googleapis");
13
15
  const SCOPES = [
14
16
  'https://www.googleapis.com/auth/gmail.addons.current.action.compose',
@@ -24,6 +26,9 @@ const SCOPES = [
24
26
  'https://www.googleapis.com/auth/gmail.insert',
25
27
  ];
26
28
  const TOKEN_PATH = 'token.json';
29
+ let TOKEN = '';
30
+ let EMAIL = '';
31
+ let PASSWORD = '';
27
32
  export class AuxGoogleAuth {
28
33
  static get oAuth2Client() {
29
34
  return this._oAuth2Client;
@@ -34,11 +39,22 @@ export class AuxGoogleAuth {
34
39
  static get gmailClient() {
35
40
  return google.gmail({ version: 'v1', auth: this._oAuth2Client });
36
41
  }
37
- static setup() {
42
+ static setupBrowser() {
38
43
  return __awaiter(this, void 0, void 0, function* () {
39
44
  yield this.authorize(this.credentialsJson);
40
45
  });
41
46
  }
47
+ static setEmailPassword(email, password) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ EMAIL = email;
50
+ PASSWORD = password;
51
+ });
52
+ }
53
+ static setupHeadless() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ yield this.authorizeHeadless(this.credentialsJson);
56
+ });
57
+ }
42
58
  static authorize(credentials) {
43
59
  return __awaiter(this, void 0, void 0, function* () {
44
60
  const { client_secret, client_id, redirect_uris } = credentials.installed;
@@ -57,6 +73,23 @@ export class AuxGoogleAuth {
57
73
  }
58
74
  });
59
75
  }
76
+ static authorizeHeadless(credentials) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const { client_secret, client_id, redirect_uris } = credentials.installed;
79
+ const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
80
+ try {
81
+ if (TOKEN.length > 0) {
82
+ oAuth2Client.setCredentials(JSON.parse(TOKEN));
83
+ this._oAuth2Client = oAuth2Client;
84
+ return;
85
+ }
86
+ yield this.getNewTokenHeadless(oAuth2Client);
87
+ }
88
+ catch (e) {
89
+ yield this.getNewTokenHeadless(oAuth2Client);
90
+ }
91
+ });
92
+ }
60
93
  static getNewToken(oAuth2Client) {
61
94
  return __awaiter(this, void 0, void 0, function* () {
62
95
  const authUrl = oAuth2Client.generateAuthUrl({
@@ -85,6 +118,50 @@ export class AuxGoogleAuth {
85
118
  });
86
119
  });
87
120
  }
121
+ static getNewTokenHeadless(oAuth2Client) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const authUrl = oAuth2Client.generateAuthUrl({
124
+ access_type: 'offline',
125
+ prompt: 'consent',
126
+ scope: SCOPES,
127
+ });
128
+ const code = yield this.LogIn(authUrl);
129
+ oAuth2Client.getToken(code, (err, token) => {
130
+ if (err)
131
+ return console.error('Error retrieving access token', err);
132
+ oAuth2Client.setCredentials(token);
133
+ TOKEN = token;
134
+ this._oAuth2Client = oAuth2Client;
135
+ });
136
+ });
137
+ }
138
+ static LogIn(authUrl) {
139
+ var _a, _b, _c;
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const context = yield puppeteer.defaultPage.browser().createIncognitoBrowserContext();
142
+ const page = yield context.newPage();
143
+ yield page.goto(authUrl);
144
+ yield page.waitForNetworkIdle();
145
+ yield FunctionHelper.waitForSelector('visible', '#identifierId');
146
+ yield ((_a = (yield page.$('#identifierId'))) === null || _a === void 0 ? void 0 : _a.type(EMAIL));
147
+ yield (yield page.$$('button'))[3].click();
148
+ yield page.waitForNetworkIdle();
149
+ yield FunctionHelper.waitForSelector('visible', 'input[type="password"]');
150
+ yield ((_b = (yield page.$('input[type="password"]'))) === null || _b === void 0 ? void 0 : _b.type(PASSWORD));
151
+ yield (yield page.$$('button'))[1].click();
152
+ yield page.waitForNetworkIdle();
153
+ yield FunctionHelper.waitForSelector('visible', '#headingText');
154
+ yield (yield page.$$('button'))[2].click();
155
+ yield page.waitForNetworkIdle();
156
+ yield FunctionHelper.waitForSelector('visible', 'input[type="checkbox"]');
157
+ yield ((_c = (yield page.$('input[type="checkbox"]'))) === null || _c === void 0 ? void 0 : _c.click());
158
+ yield (yield page.$$('button'))[2].click();
159
+ yield page.waitForNetworkIdle();
160
+ const currentUrl = page.url();
161
+ const code = currentUrl.substring(currentUrl.indexOf("code=") + 5, currentUrl.lastIndexOf("&"));
162
+ return decodeURIComponent(code);
163
+ });
164
+ }
88
165
  }
89
166
  AuxGoogleAuth.credentialsJson = {
90
167
  "installed": {
@@ -34,11 +34,11 @@ export class FunctionHelper extends ExtendDefaultPage {
34
34
  if (screenshotBuffer) {
35
35
  const screenshot = screenshotBuffer.toString('base64');
36
36
  yield compareScreenshots(key, screenshot);
37
- log.push('Then', `compare screenshots with key ${key}`, StatusOfStep.PASSED, screenshot, key);
37
+ log.push('Then', `I compare screenshots with key ${key}`, StatusOfStep.PASSED, screenshot, key);
38
38
  }
39
39
  }
40
40
  else {
41
- log.push('Then', `compare screenshots with key ${key}`, StatusOfStep.PASSED, undefined, key);
41
+ log.push('Then', `I compare screenshots with key ${key}`, StatusOfStep.PASSED, undefined, key);
42
42
  }
43
43
  });
44
44
  }
@@ -15,7 +15,7 @@ const MailComposer = require('nodemailer/lib/mail-composer');
15
15
  export class EmailHelper {
16
16
  verifyEmail(from_name, from_email, subject, body, link = false) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
- yield AuxGoogleAuth.setup();
18
+ yield AuxGoogleAuth.setupHeadless();
19
19
  let timeoutCount = 12000;
20
20
  while (timeoutCount <= 60000) {
21
21
  const res = yield AuxGoogleAuth.gmailClient.users.messages.list({
@@ -70,7 +70,7 @@ export class EmailHelper {
70
70
  }
71
71
  sendEmail(to, subject, body) {
72
72
  return __awaiter(this, void 0, void 0, function* () {
73
- yield AuxGoogleAuth.setup();
73
+ yield AuxGoogleAuth.setupHeadless();
74
74
  const options = {
75
75
  to: to,
76
76
  from: this.getCurrentUserEmail(),
@@ -82,7 +82,7 @@ export class EmailHelper {
82
82
  }
83
83
  replyEmail(id, threadId, body) {
84
84
  return __awaiter(this, void 0, void 0, function* () {
85
- yield AuxGoogleAuth.setup();
85
+ yield AuxGoogleAuth.setupHeadless();
86
86
  const gmailResponse = yield AuxGoogleAuth.gmailClient.users.messages.get({
87
87
  userId: "me",
88
88
  id: id,
@@ -142,7 +142,7 @@ export class EmailHelper {
142
142
  }
143
143
  getCurrentUserEmail() {
144
144
  return __awaiter(this, void 0, void 0, function* () {
145
- yield AuxGoogleAuth.setup();
145
+ yield AuxGoogleAuth.setupHeadless();
146
146
  const profile = yield AuxGoogleAuth.gmailClient.users.getProfile({ userId: "me" });
147
147
  return profile.data.emailAddress;
148
148
  });