@auxcode/auxta 1.3.78-beta.107 → 1.3.78-beta.109

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.
@@ -12,7 +12,6 @@ export declare class AuxGoogleAuth {
12
12
  private static authorizeHeadless;
13
13
  private static getNewToken;
14
14
  private static getNewTokenHeadless;
15
- private static LogIn;
16
15
  }
17
16
  declare const _default: AuxGoogleAuth;
18
17
  export default _default;
@@ -36,13 +36,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.AuxGoogleAuth = void 0;
39
- const config_1 = require("../../auxta/configs/config");
40
- const puppeteer_extra_1 = __importDefault(require("../../puppeteer/puppeteer-extra"));
41
39
  const code_helper_1 = __importDefault(require("../helpers/code.helper"));
42
40
  const status_of_step_1 = __importDefault(require("../../auxta/enums/status-of.step"));
43
41
  const fs = require('fs');
44
42
  const readline = require('readline');
45
43
  const process = __importStar(require("process"));
44
+ const os = __importStar(require("os"));
46
45
  const { google } = require("googleapis");
47
46
  const SCOPES = [
48
47
  'https://www.googleapis.com/auth/gmail.addons.current.action.compose',
@@ -59,9 +58,10 @@ const SCOPES = [
59
58
  ];
60
59
  const TOKEN_PATH = 'token.json';
61
60
  let TOKEN;
61
+ let TOKEN_LOCAL = { "access_token": "ya29.a0AfB_byC3wrz-fq6dH4V1TtgLoRZYUWaz4bmfSmKhrZpJ8m3fGE57f-MlNjkmsXNQq1Vlod79HxZ2Kl1Gcd7dVAeJoZe0RTvv9SoA-Epg1MfYfkHmHqUAajn0tqelMQpU_nwZsf3JVd3_gBFKBy3OSKMVeMe9ypbSxcK4aCgYKAe0SARASFQHGX2MiUdpxBp978i0lcm4cMPGOmQ0171", "refresh_token": "1//09mXy9YbxS7M-CgYIARAAGAkSNwF-L9Ir_InxbeTeFnEW-9dokuVSEZZGhgumZyglH0ls4MXruOMdpQU6Jq4oZ2b1vhQCOmkvk4Q", "scope": "https://mail.google.com/ https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.message.metadata https://www.googleapis.com/auth/gmail.addons.current.action.compose https://www.googleapis.com/auth/gmail.compose https://www.googleapis.com/auth/gmail.send https://www.googleapis.com/auth/gmail.addons.current.message.action https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.insert https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.addons.current.message.readonly", "token_type": "Bearer", "expiry_date": 1702312809725 };
62
+ let TOKEN_LIVE = { "access_token": "ya29.a0AfB_byDSMJG3P21NM_Yg2Smb4zqKzqHQqsebIxZdurEM0D6ZFJc83MIBqjbLrHunQARDMGlyds91pYxPwlG8TGHG92sVJOciRVKk1FajWDgV8NB2DUaR2C1VyqMvG6u_CNOAh8ipwkyl61IV9LQRUq68Pst4IgMUIE0vaCgYKAWQSARASFQHGX2MiupiNUzT4iPGG55veqTkvyg0171", "refresh_token": "1//09-NODQSczV7oCgYIARAAGAkSNwF-L9IrH4shG3hyGtXJdadMchVIjQs5yF6pbqJ9owKzuiq2agTtall0qsspNY5fhqMYoun48EY", "scope": "https://www.googleapis.com/auth/gmail.addons.current.message.action https://www.googleapis.com/auth/gmail.compose https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.insert https://mail.google.com/ https://www.googleapis.com/auth/gmail.addons.current.message.readonly https://www.googleapis.com/auth/gmail.labels https://www.googleapis.com/auth/gmail.addons.current.message.metadata https://www.googleapis.com/auth/gmail.addons.current.action.compose https://www.googleapis.com/auth/gmail.send", "token_type": "Bearer", "expiry_date": 1702312878701 };
62
63
  let EMAIL;
63
64
  let PASSWORD;
64
- let count = 0;
65
65
  class AuxGoogleAuth {
66
66
  static get oAuth2Client() {
67
67
  return this._oAuth2Client;
@@ -81,6 +81,7 @@ class AuxGoogleAuth {
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
82
  EMAIL = email;
83
83
  PASSWORD = password;
84
+ console.log(EMAIL, PASSWORD);
84
85
  });
85
86
  }
86
87
  static setupHeadless() {
@@ -120,7 +121,7 @@ class AuxGoogleAuth {
120
121
  yield this.getNewTokenHeadless(oAuth2Client);
121
122
  }
122
123
  catch (e) {
123
- yield this.getNewTokenHeadless(oAuth2Client);
124
+ code_helper_1.default.log('Then', 'Getting the existing token', status_of_step_1.default.FAILED);
124
125
  }
125
126
  });
126
127
  }
@@ -154,95 +155,22 @@ class AuxGoogleAuth {
154
155
  }
155
156
  static getNewTokenHeadless(oAuth2Client) {
156
157
  return __awaiter(this, void 0, void 0, function* () {
157
- const authUrl = oAuth2Client.generateAuthUrl({
158
- access_type: 'offline',
159
- prompt: 'consent',
160
- scope: SCOPES,
161
- });
162
- const code = yield this.LogIn(authUrl);
163
- this._oAuth2Client = yield (new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
164
- yield oAuth2Client.getToken(code, (err, token) => {
165
- if (err)
166
- return console.error('Error retrieving access token', err);
167
- oAuth2Client.setCredentials(token);
168
- TOKEN = token;
158
+ const platform = os.platform();
159
+ if (process.env.ENVIRONMENT === 'LOCAL') {
160
+ oAuth2Client.setCredentials(TOKEN_LOCAL);
161
+ this._oAuth2Client = oAuth2Client;
162
+ code_helper_1.default.log('Then', 'I login with the google account', status_of_step_1.default.PASSED);
163
+ }
164
+ if (process.env.ENVIRONMENT !== 'LOCAL') {
165
+ if (platform.includes("win32") || platform.includes("darwin")) {
166
+ oAuth2Client.setCredentials(TOKEN_LOCAL);
169
167
  this._oAuth2Client = oAuth2Client;
170
- code_helper_1.default.log('Then', 'I login with the google account', status_of_step_1.default.PASSED);
171
- resolve(oAuth2Client);
172
- });
173
- })));
174
- });
175
- }
176
- static LogIn(authUrl) {
177
- var _a, _b;
178
- return __awaiter(this, void 0, void 0, function* () {
179
- const email = EMAIL ? EMAIL : process.env.google_account;
180
- const password = PASSWORD ? PASSWORD : process.env.google_password;
181
- yield puppeteer_extra_1.default.startBrowser();
182
- let screenshot;
183
- count++;
184
- if (email && password) {
185
- const context = yield puppeteer_extra_1.default.defaultPage.browser().createIncognitoBrowserContext();
186
- const page = yield context.newPage();
187
- yield page.goto(authUrl);
188
- yield code_helper_1.default.waitForSelector('visible', '#identifierId', config_1.config.timeout, page, count >= 2);
189
- yield ((_a = (yield page.$('#identifierId'))) === null || _a === void 0 ? void 0 : _a.type(email));
190
- if (count >= 2) {
191
- screenshot = yield code_helper_1.default.screenshot(page);
192
- code_helper_1.default.log('Then', 'screenshot after #identifierId', status_of_step_1.default.PASSED, screenshot);
193
- }
194
- yield (yield page.$$('button'))[3].click();
195
- yield code_helper_1.default.timeout(5000);
196
- yield code_helper_1.default.waitForSelector('visible', 'input[type="password"]', config_1.config.timeout, page, count >= 2);
197
- yield ((_b = (yield page.$('input[type="password"]'))) === null || _b === void 0 ? void 0 : _b.type(password));
198
- if (count >= 2) {
199
- screenshot = yield code_helper_1.default.screenshot(page);
200
- code_helper_1.default.log('Then', 'screenshot after #password', status_of_step_1.default.PASSED, screenshot);
201
- }
202
- yield (yield page.$$('button'))[1].click();
203
- yield code_helper_1.default.timeout(5000);
204
- yield code_helper_1.default.waitForSelector('visible', '#headingText', config_1.config.timeout, page, count >= 2);
205
- yield code_helper_1.default.timeout(5000);
206
- if (count >= 2) {
207
- screenshot = yield code_helper_1.default.screenshot(page);
208
- code_helper_1.default.log('Then', 'screenshot after #headingText', status_of_step_1.default.PASSED, screenshot);
209
- }
210
- yield code_helper_1.default.waitForSelector('visible', 'button', config_1.config.timeout, page, count >= 2);
211
- yield (yield page.$$('button'))[2].click();
212
- yield code_helper_1.default.timeout(5000);
213
- const checkbox = yield page.$$('input[type="checkbox"]');
214
- if (checkbox.length > 0) {
215
- yield code_helper_1.default.waitForSelector('visible', 'input[type="checkbox"]', config_1.config.timeout, page, count >= 2);
216
- yield code_helper_1.default.timeout(5000);
217
- yield checkbox[0].click();
218
- if (count >= 2) {
219
- screenshot = yield code_helper_1.default.screenshot(page);
220
- code_helper_1.default.log('Then', 'screenshot after input[type="checkbox"]', status_of_step_1.default.PASSED, screenshot);
221
- }
222
- yield (yield page.$$('button'))[2].click();
223
168
  }
224
169
  else {
225
- yield code_helper_1.default.waitForSelector('visible', `div[data-email="${email.toLocaleLowerCase()}"]`, config_1.config.timeout, page, count >= 2);
226
- yield code_helper_1.default.timeout(5000);
227
- if (count >= 2) {
228
- screenshot = yield code_helper_1.default.screenshot(page);
229
- code_helper_1.default.log('Then', 'screenshot after div email', status_of_step_1.default.PASSED, screenshot);
230
- }
231
- yield code_helper_1.default.waitForSelector('visible', 'button', config_1.config.timeout, page, count >= 2);
232
- yield (yield page.$$('button'))[2].click();
170
+ oAuth2Client.setCredentials(TOKEN_LIVE);
171
+ this._oAuth2Client = oAuth2Client;
233
172
  }
234
- yield code_helper_1.default.timeout(5000);
235
- yield code_helper_1.default.waitForSelector('visible', 'body', config_1.config.timeout, page, count >= 2);
236
- const currentUrl = page.url();
237
- const code = currentUrl.substring(currentUrl.indexOf("code=") + 5, currentUrl.lastIndexOf("&"));
238
- code_helper_1.default.log('Then', 'I get the code form the url', status_of_step_1.default.PASSED);
239
- yield page.close();
240
- yield puppeteer_extra_1.default.close();
241
- return decodeURIComponent(code);
242
- }
243
- else {
244
- yield puppeteer_extra_1.default.close();
245
- throw new Error('The email or password for the google account are empty');
173
+ code_helper_1.default.log('Then', 'I login with the google account', status_of_step_1.default.PASSED);
246
174
  }
247
175
  });
248
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "1.3.78-beta.107",
3
+ "version": "1.3.78-beta.109",
4
4
  "description": "",
5
5
  "main": "./build/AuxTA.js",
6
6
  "types": "./build/AuxTA.d.ts",