ag-awsauth 0.0.276 → 0.0.278

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/dist/config.d.ts CHANGED
@@ -11,3 +11,4 @@ export declare const setConfig: () => void;
11
11
  export declare const runConfig: () => void;
12
12
  export declare const timeoutMs = 30000;
13
13
  export declare const timeoutShortMs = 3000;
14
+ export declare const timeoutMedMs = 6000;
package/dist/config.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.timeoutShortMs = exports.timeoutMs = exports.runConfig = exports.setConfig = exports.validateConfig = exports.targetRegion = exports.ssoStartUrl = exports.identityCenterRegion = exports.setBasePath = exports.basePath = exports.nativeStsDurationSeconds = exports.stsDurationSeconds = exports.logPath = void 0;
6
+ exports.timeoutMedMs = exports.timeoutShortMs = exports.timeoutMs = exports.runConfig = exports.setConfig = exports.validateConfig = exports.targetRegion = exports.ssoStartUrl = exports.identityCenterRegion = exports.setBasePath = exports.basePath = exports.nativeStsDurationSeconds = exports.stsDurationSeconds = exports.logPath = void 0;
7
7
  const envfile_1 = require("envfile");
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -48,9 +48,9 @@ const runConfig = () => {
48
48
  c.identityCenterRegion = ' //eg us-east-1';
49
49
  }
50
50
  fs_1.default.writeFileSync(pn, (0, envfile_1.stringify)(c));
51
- // eslint-disable-next-line @typescript-eslint/no-var-requires
52
51
  require('child_process').exec(`start "" "${pn}"`);
53
52
  };
54
53
  exports.runConfig = runConfig;
55
54
  exports.timeoutMs = 30000;
56
55
  exports.timeoutShortMs = 3000;
56
+ exports.timeoutMedMs = 6000;
@@ -1,6 +1,7 @@
1
+ import type { Page } from 'puppeteer';
1
2
  export declare const closeBrowser: () => Promise<void>;
2
3
  export declare const launchBrowser: () => Promise<void>;
3
- export declare const goToPage: (url: string) => Promise<import("puppeteer").Page>;
4
+ export declare const goToPage: (url: string) => Promise<Page>;
4
5
  export declare function getMFA(p: {
5
6
  verificationUriComplete: string;
6
7
  creds: {
@@ -12,12 +12,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.goToPage = exports.launchBrowser = exports.closeBrowser = void 0;
13
13
  exports.getMFA = getMFA;
14
14
  const log_1 = require("ag-common/dist/common/helpers/log");
15
- const sleep_1 = require("ag-common/dist/common/helpers/sleep");
16
15
  const puppeteer_1 = require("puppeteer");
17
16
  const __1 = require("..");
18
17
  const config_1 = require("../config");
19
18
  const input_1 = require("./input");
20
19
  let browser;
20
+ /**
21
+ * Helper to wait for network idle, ignoring timeout errors
22
+ */
23
+ const waitForNetworkIdleSafe = (page_1, ...args_1) => __awaiter(void 0, [page_1, ...args_1], void 0, function* (page, options = {}) {
24
+ try {
25
+ yield page.waitForNetworkIdle(options);
26
+ }
27
+ catch (_a) {
28
+ // Ignore timeout errors
29
+ }
30
+ });
21
31
  const closeBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
22
32
  try {
23
33
  if (!browser) {
@@ -35,17 +45,15 @@ const launchBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
35
45
  const opt = {
36
46
  defaultViewport: { height: 1000, width: 500 },
37
47
  headless: (__1.globalargs === null || __1.globalargs === void 0 ? void 0 : __1.globalargs.verbose) ? false : true,
38
- ignoreHTTPSErrors: true,
39
48
  devtools: false,
49
+ args: [
50
+ '--disable-features=AudioServiceOutOfProcess',
51
+ '--disable-features=AudioServiceOutOfProcessKillAtHang',
52
+ '--disable-software-rasterizer',
53
+ '--disable-gpu',
54
+ '--disable-dev-shm-usage',
55
+ ],
40
56
  };
41
- if (!opt.args) {
42
- opt.args = [];
43
- }
44
- opt.args.push('--disable-features=AudioServiceOutOfProcess');
45
- opt.args.push('--disable-features=AudioServiceOutOfProcessKillAtHang');
46
- opt.args.push('--disable-software-rasterizer');
47
- opt.args.push('--disable-gpu');
48
- opt.args.push('--disable-dev-shm-usage');
49
57
  yield (0, exports.closeBrowser)();
50
58
  (0, log_1.debug)('launch browser, opt=', opt);
51
59
  browser = (yield (0, puppeteer_1.launch)(opt));
@@ -92,7 +100,7 @@ function getMFA(p) {
92
100
  yield verif.click();
93
101
  }
94
102
  }
95
- catch (e) {
103
+ catch (_b) {
96
104
  //
97
105
  }
98
106
  //
@@ -107,14 +115,8 @@ function getMFA(p) {
107
115
  yield page.focus('#password-input input');
108
116
  yield page.keyboard.type(p.creds.password);
109
117
  yield page.$eval('#password-submit-button button', (el) => el.click());
110
- yield (0, sleep_1.sleep)(250);
111
- try {
112
- yield page.waitForNetworkIdle({ idleTime: 250, timeout: 3000 });
113
- }
114
- catch (e) {
115
- //
116
- }
117
118
  try {
119
+ yield waitForNetworkIdleSafe(page, { idleTime: 250, timeout: 3000 });
118
120
  (0, log_1.info)('wait optional alert message');
119
121
  const messageDiv = yield page.waitForSelector('.awsui-alert-message', {
120
122
  timeout: config_1.timeoutShortMs,
@@ -133,80 +135,107 @@ function getMFA(p) {
133
135
  }
134
136
  }
135
137
  //
136
- let retry = true;
137
- do {
138
- (0, log_1.info)('mfa block');
139
- const { mfa } = (0, input_1.enterMFA)();
140
- yield page.waitForSelector('.awsui-input-type-text', {
141
- timeout: config_1.timeoutMs,
138
+ (0, log_1.info)('mfa block');
139
+ //enter mfa
140
+ const { mfa } = (0, input_1.enterMFA)();
141
+ yield page.waitForSelector('.awsui-input-type-text', {
142
+ timeout: config_1.timeoutMedMs,
143
+ });
144
+ yield page.focus('.awsui-input-type-text');
145
+ yield page.keyboard.type(mfa);
146
+ yield page.$eval('.awsui-signin-button-container button', (el) => el.click());
147
+ //wait up to timeoutMs until url redirects, and ends up on https://d-9067b92b3b.awsapps.com/start/#/device?user_code=.*?
148
+ try {
149
+ (0, log_1.info)('waiting for redirect to device page');
150
+ yield page.waitForFunction(() => {
151
+ const url = window.location.href;
152
+ return url.includes('awsapps.com/start/#/device?user_code=');
153
+ }, { timeout: config_1.timeoutMs });
154
+ (0, log_1.info)('successfully redirected to device page');
155
+ }
156
+ catch (e) {
157
+ (0, log_1.warn)('timeout waiting for device page redirect:', e);
158
+ // Continue anyway as the flow might still work
159
+ }
160
+ try {
161
+ yield waitForNetworkIdleSafe(page, {
162
+ idleTime: 250,
163
+ timeout: config_1.timeoutShortMs,
142
164
  });
143
- yield page.focus('.awsui-input-type-text');
144
- yield page.keyboard.type(mfa);
145
- yield page.$eval('.awsui-signin-button-container button', (el) => el.click());
146
- //
147
- try {
148
- yield (0, sleep_1.sleep)(250);
149
- yield page.waitForNetworkIdle({ idleTime: 250 });
150
- (0, log_1.info)('waiting for potential error');
151
- const messageDiv = yield page.waitForSelector('.awsui-alert-message', {
152
- timeout: config_1.timeoutShortMs,
153
- });
154
- const value = yield page.evaluate((el) => { var _a; return (_a = el === null || el === void 0 ? void 0 : el.textContent) !== null && _a !== void 0 ? _a : ''; }, messageDiv);
155
- if (value) {
156
- throw new Error(value);
157
- }
158
- retry = false;
165
+ (0, log_1.info)('try to click cookie decline');
166
+ const messageDiv = yield page.waitForSelector('[data-id="awsccc-cb-btn-decline"]', {
167
+ timeout: config_1.timeoutShortMs,
168
+ });
169
+ if (messageDiv) {
170
+ (0, log_1.info)('click decline');
171
+ yield messageDiv.click();
172
+ }
173
+ }
174
+ catch (e) {
175
+ (0, log_1.debug)('error clicking decline:', e);
176
+ }
177
+ //
178
+ try {
179
+ yield waitForNetworkIdleSafe(page, {
180
+ idleTime: 250,
181
+ timeout: config_1.timeoutShortMs,
182
+ });
183
+ (0, log_1.info)('waiting for potential error');
184
+ const messageDiv = yield page.waitForSelector('.awsui-alert-message', {
185
+ timeout: config_1.timeoutShortMs,
186
+ });
187
+ const value = yield page.evaluate((el) => { var _a; return (_a = el === null || el === void 0 ? void 0 : el.textContent) !== null && _a !== void 0 ? _a : ''; }, messageDiv);
188
+ if (value) {
189
+ throw new Error(value);
159
190
  }
160
- catch (e) {
161
- const em = e.toString();
162
- if (!em.includes('exceeded')) {
163
- const em2 = `mfa error:` + em + ' retry';
164
- (0, log_1.error)(em2);
165
- }
166
- else {
167
- retry = false;
168
- }
191
+ }
192
+ catch (e) {
193
+ (0, log_1.debug)('error waiting for potential error:', e);
194
+ }
195
+ try {
196
+ (0, log_1.info)('accept-user-code');
197
+ const messageDiv = yield page.waitForSelector('[data-analytics="accept-user-code"]', {
198
+ timeout: config_1.timeoutMs,
199
+ });
200
+ if (messageDiv) {
201
+ (0, log_1.info)('click accept-user-code');
202
+ yield messageDiv.click();
169
203
  }
170
- try {
171
- (0, log_1.info)('accept-user-code');
172
- const messageDiv = yield page.waitForSelector('[data-analytics="accept-user-code"]', {
173
- timeout: config_1.timeoutShortMs,
174
- });
175
- if (messageDiv) {
176
- (0, log_1.info)('click access prompt');
177
- yield messageDiv.click();
178
- }
179
- else {
180
- throw new Error('access prompt not found');
181
- }
204
+ else {
205
+ throw new Error('access prompt not found');
182
206
  }
183
- catch (e) {
184
- //
207
+ }
208
+ catch (e) {
209
+ (0, log_1.debug)('error accepting user code:', e);
210
+ }
211
+ try {
212
+ (0, log_1.info)('allow-access-button');
213
+ const messageDiv = yield page.waitForSelector('[data-testid="allow-access-button"]', {
214
+ timeout: config_1.timeoutMedMs,
215
+ });
216
+ if (messageDiv) {
217
+ (0, log_1.info)('click allow-access-button');
218
+ yield messageDiv.click();
185
219
  }
186
- try {
187
- (0, log_1.info)('allow-access-button');
188
- const messageDiv = yield page.waitForSelector('[data-testid="allow-access-button"]', {
189
- timeout: config_1.timeoutShortMs,
190
- });
191
- if (messageDiv) {
192
- (0, log_1.info)('click access prompt');
193
- yield messageDiv.click();
194
- }
195
- else {
196
- throw new Error('access prompt not found');
197
- }
220
+ else {
221
+ throw new Error('access prompt not found');
198
222
  }
199
- catch (e) {
200
- const em = e.toString();
201
- if (!em.includes('exceeded')) {
202
- const em2 = `mfa error:` + em + ' retry';
203
- (0, log_1.error)(em2);
204
- }
205
- else {
206
- retry = false;
207
- }
223
+ }
224
+ catch (e) {
225
+ (0, log_1.debug)('error clicking allow-access-button:', e);
226
+ }
227
+ try {
228
+ const verif = yield page.waitForSelector('#cli_verification_btn', {
229
+ timeout: config_1.timeoutShortMs,
230
+ });
231
+ if (verif) {
232
+ (0, log_1.info)('clicking auth request button');
233
+ yield verif.click();
208
234
  }
209
- } while (retry);
235
+ }
236
+ catch (e) {
237
+ (0, log_1.debug)('error clicking auth request button:', e);
238
+ }
210
239
  //
211
240
  (0, log_1.info)('waiting for success');
212
241
  yield page.waitForSelector('[data-analytics-alert="success"]', {
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.requestMFA = requestMFA;
13
+ /* eslint-disable no-await-in-loop */
13
14
  const client_sso_oidc_1 = require("@aws-sdk/client-sso-oidc");
14
15
  const log_1 = require("ag-common/dist/common/helpers/log");
15
16
  const sleep_1 = require("ag-common/dist/common/helpers/sleep");
@@ -28,7 +28,6 @@ const getVersion = () => {
28
28
  if (!fs_1.default.existsSync(pjpath)) {
29
29
  return undefined;
30
30
  }
31
- // eslint-disable-next-line @typescript-eslint/no-var-requires
32
31
  const p = require(pjpath);
33
32
  return p === null || p === void 0 ? void 0 : p.version;
34
33
  };
package/dist/index.js CHANGED
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.globalargs = void 0;
16
16
  exports.main = main;
17
17
  exports.run = run;
18
- /* eslint-disable padding-line-between-statements */
19
18
  const log_1 = require("ag-common/dist/common/helpers/log");
20
19
  const dotenv_1 = require("dotenv");
21
20
  const fs_1 = __importDefault(require("fs"));
@@ -44,7 +43,7 @@ function main(args) {
44
43
  try {
45
44
  fs_1.default.appendFileSync(config_1.logPath, JSON.stringify(a1, null, 2));
46
45
  }
47
- catch (e) {
46
+ catch (_a) {
48
47
  //
49
48
  }
50
49
  });
@@ -59,7 +58,6 @@ function main(args) {
59
58
  }
60
59
  if (args.wipe) {
61
60
  (0, log_1.info)('wiping args');
62
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
61
  yield (0, awsconfig_1.updateAwsCredentials)(undefined);
64
62
  return;
65
63
  }
package/package.json CHANGED
@@ -5,13 +5,11 @@
5
5
  "author": "andrei gec (andreigec@hotmail.com)",
6
6
  "license": "ISC",
7
7
  "private": false,
8
- "version": "0.0.276",
8
+ "version": "0.0.278",
9
9
  "preferGlobal": true,
10
10
  "scripts": {
11
- "format": "eslint --ext .ts,.tsx src --fix",
12
- "lint:tsc": "tsc --noEmit",
13
- "lint:eslint": "eslint --ext .ts,.tsx src",
14
- "lint": "pnpm run /^lint:/",
11
+ "lint": "next lint",
12
+ "format": "eslint src --fix",
15
13
  "start": "tsc && node bin/awsauth.js",
16
14
  "build": "tsc"
17
15
  },
@@ -25,26 +23,26 @@
25
23
  "LICENSE.md"
26
24
  ],
27
25
  "dependencies": {
28
- "@aws-sdk/client-sso": "3.632.0",
29
- "@aws-sdk/client-sso-oidc": "3.632.0",
30
- "@aws-sdk/client-sts": "3.632.0",
31
- "@aws-sdk/shared-ini-file-loader": "^3.374.0",
32
- "ag-common": "0.0.719",
26
+ "@aws-sdk/client-sso": "3.848.0",
27
+ "@aws-sdk/client-sso-oidc": "3.848.0",
28
+ "@aws-sdk/client-sts": "3.848.0",
29
+ "@aws-sdk/shared-ini-file-loader": "3.374.0",
30
+ "ag-common": "0.0.755",
33
31
  "cli-select": "1.1.2",
34
- "dotenv": "16.4.5",
32
+ "dotenv": "17.2.1",
35
33
  "envfile": "7.1.0",
36
- "eslint-config-e7npm": "0.0.114",
37
- "ini": "4.1.3",
38
- "node-fetch": "2.7.0",
39
- "puppeteer": "22.15.0",
34
+ "eslint-config-e7npm": "0.1.23",
35
+ "ini": "5.0.0",
36
+ "node-fetch": "3.3.2",
37
+ "puppeteer": "24.15.0",
40
38
  "readline-sync": "1.4.10",
41
- "typescript": "5.5.4",
42
- "yargs": "17.7.2"
39
+ "typescript": "5.8.3",
40
+ "yargs": "18.0.0"
43
41
  },
44
42
  "devDependencies": {
45
43
  "@types/ini": "4.1.1",
46
- "@types/node": "20.15.0",
47
- "@types/node-fetch": "2.6.11",
44
+ "@types/node": "24.1.0",
45
+ "@types/node-fetch": "2.6.12",
48
46
  "@types/readline-sync": "1.4.8",
49
47
  "@types/yargs": "17.0.33"
50
48
  },