@auxcode/auxta 1.3.52 → 1.3.53

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,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,6 +42,7 @@ const code_helper_1 = __importDefault(require("../helpers/code.helper"));
19
42
  const status_of_step_1 = __importDefault(require("../../auxta/enums/status-of.step"));
20
43
  const fs = require('fs');
21
44
  const readline = require('readline');
45
+ const process = __importStar(require("process"));
22
46
  const { google } = require("googleapis");
23
47
  const SCOPES = [
24
48
  'https://www.googleapis.com/auth/gmail.addons.current.action.compose',
@@ -34,9 +58,9 @@ const SCOPES = [
34
58
  'https://www.googleapis.com/auth/gmail.insert',
35
59
  ];
36
60
  const TOKEN_PATH = 'token.json';
37
- let TOKEN = '';
38
- let EMAIL = '';
39
- let PASSWORD = '';
61
+ let TOKEN;
62
+ let EMAIL;
63
+ let PASSWORD;
40
64
  class AuxGoogleAuth {
41
65
  static get oAuth2Client() {
42
66
  return this._oAuth2Client;
@@ -150,35 +174,44 @@ class AuxGoogleAuth {
150
174
  static LogIn(authUrl) {
151
175
  var _a, _b;
152
176
  return __awaiter(this, void 0, void 0, function* () {
153
- const context = yield puppeteer_1.default.defaultPage.browser().createIncognitoBrowserContext();
154
- const page = yield context.newPage();
155
- yield page.goto(authUrl);
156
- yield code_helper_1.default.waitForSelector('visible', '#identifierId', config_1.config.timeout, page);
157
- yield ((_a = (yield page.$('#identifierId'))) === null || _a === void 0 ? void 0 : _a.type(EMAIL));
158
- yield (yield page.$$('button'))[3].click();
159
- yield code_helper_1.default.timeout(3000);
160
- yield code_helper_1.default.waitForSelector('visible', 'input[type="password"]', config_1.config.timeout, page);
161
- yield ((_b = (yield page.$('input[type="password"]'))) === null || _b === void 0 ? void 0 : _b.type(PASSWORD));
162
- yield (yield page.$$('button'))[1].click();
163
- yield code_helper_1.default.timeout(3000);
164
- yield code_helper_1.default.waitForSelector('visible', '#headingText', config_1.config.timeout, page);
165
- yield (yield page.$$('button'))[2].click();
166
- yield code_helper_1.default.timeout(3000);
167
- const checkbox = yield page.$$('input[type="checkbox"]');
168
- if (checkbox.length > 0) {
169
- yield code_helper_1.default.waitForSelector('visible', 'input[type="checkbox"]', config_1.config.timeout, page);
170
- yield checkbox[0].click();
177
+ const email = EMAIL ? EMAIL : process.env.google_account;
178
+ const password = PASSWORD ? PASSWORD : process.env.google_password;
179
+ if (email && password) {
180
+ const context = yield puppeteer_1.default.defaultPage.browser().createIncognitoBrowserContext();
181
+ const page = yield context.newPage();
182
+ yield page.goto(authUrl);
183
+ yield code_helper_1.default.waitForSelector('visible', '#identifierId', config_1.config.timeout, page);
184
+ yield ((_a = (yield page.$('#identifierId'))) === null || _a === void 0 ? void 0 : _a.type(email));
185
+ yield (yield page.$$('button'))[3].click();
186
+ yield code_helper_1.default.timeout(3000);
187
+ yield code_helper_1.default.waitForSelector('visible', 'input[type="password"]', config_1.config.timeout, page);
188
+ yield ((_b = (yield page.$('input[type="password"]'))) === null || _b === void 0 ? void 0 : _b.type(password));
189
+ yield (yield page.$$('button'))[1].click();
190
+ yield code_helper_1.default.timeout(3000);
191
+ yield code_helper_1.default.waitForSelector('visible', '#headingText', config_1.config.timeout, page);
171
192
  yield (yield page.$$('button'))[2].click();
193
+ yield code_helper_1.default.timeout(3000);
194
+ const checkbox = yield page.$$('input[type="checkbox"]');
195
+ if (checkbox.length > 0) {
196
+ yield code_helper_1.default.waitForSelector('visible', 'input[type="checkbox"]', config_1.config.timeout, page);
197
+ yield checkbox[0].click();
198
+ yield (yield page.$$('button'))[2].click();
199
+ }
200
+ else {
201
+ yield code_helper_1.default.waitForSelector('visible', `div[data-email="${email.toLocaleLowerCase()}"]`, config_1.config.timeout, page);
202
+ yield (yield page.$$('button'))[2].click();
203
+ }
204
+ yield code_helper_1.default.timeout(3000);
205
+ yield code_helper_1.default.waitForSelector('visible', '#app', config_1.config.timeout, page);
206
+ const currentUrl = page.url();
207
+ const code = currentUrl.substring(currentUrl.indexOf("code=") + 5, currentUrl.lastIndexOf("&"));
208
+ code_helper_1.default.log('Then', 'I get the code form the url', status_of_step_1.default.PASSED);
209
+ yield page.close();
210
+ return decodeURIComponent(code);
172
211
  }
173
212
  else {
174
- yield (yield page.$$('button'))[2].click();
213
+ throw new Error('The email or password for the google account are empty');
175
214
  }
176
- yield code_helper_1.default.timeout(3000);
177
- const currentUrl = page.url();
178
- const code = currentUrl.substring(currentUrl.indexOf("code=") + 5, currentUrl.lastIndexOf("&"));
179
- code_helper_1.default.log('Then', 'I get the code form the url', status_of_step_1.default.PASSED);
180
- yield page.close();
181
- return decodeURIComponent(code);
182
215
  });
183
216
  }
184
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxcode/auxta",
3
- "version": "1.3.52",
3
+ "version": "1.3.53",
4
4
  "description": "",
5
5
  "main": "./build/AuxTA.js",
6
6
  "types": "./build/AuxTA.d.ts",