@dotenvx/dotenvx-ops 0.23.2 → 0.23.3
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/CHANGELOG.md +7 -1
- package/package.json +1 -1
- package/src/cli/actions/rotate/npm/connect.js +44 -0
- package/src/cli/commands/rotate/npm.js +9 -4
- package/src/lib/api/{postRotateLogin.js → postRotateConnect.js} +3 -3
- package/src/lib/helpers/playwrightConnect.js +13 -3
- package/src/lib/services/rotateNpmConnect.js +55 -0
- package/src/cli/actions/rotate/npm/login.js +0 -47
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.3...main)
|
|
6
|
+
|
|
7
|
+
## [0.23.3](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.2...v0.23.3) (2025-12-09)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* Rename `rotate npm login` to `rotate npm connect` ([#12](https://github.com/dotenvx/dotenvx-ops/pull/12))
|
|
6
12
|
|
|
7
13
|
## [0.23.2](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.1...v0.23.2) (2025-12-04)
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const { logger } = require('@dotenvx/dotenvx')
|
|
2
|
+
const RotateNpmConnect = require('./../../../../lib/services/rotateNpmConnect')
|
|
3
|
+
const { createSpinner } = require('./../../../../lib/helpers/createSpinner')
|
|
4
|
+
|
|
5
|
+
const spinner = createSpinner('waiting on browser completion')
|
|
6
|
+
|
|
7
|
+
async function connect () {
|
|
8
|
+
const options = this.opts()
|
|
9
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
spinner.start()
|
|
13
|
+
|
|
14
|
+
const hostname = options.hostname
|
|
15
|
+
const token = options.token
|
|
16
|
+
const org = options.org
|
|
17
|
+
const username = options.username
|
|
18
|
+
const password = options.password
|
|
19
|
+
const email = options.email
|
|
20
|
+
|
|
21
|
+
const { url } = await new RotateNpmConnect(hostname, token, org, username, password, email).run()
|
|
22
|
+
|
|
23
|
+
spinner.stop()
|
|
24
|
+
|
|
25
|
+
logger.success(`✔ connected [${url}]`)
|
|
26
|
+
logger.help('⮕ next run [dotenvx-ops rotate npm rotate]')
|
|
27
|
+
} catch (error) {
|
|
28
|
+
spinner.stop()
|
|
29
|
+
if (error.message) {
|
|
30
|
+
logger.error(error.message)
|
|
31
|
+
} else {
|
|
32
|
+
logger.error(error)
|
|
33
|
+
}
|
|
34
|
+
if (error.help) {
|
|
35
|
+
logger.help(error.help)
|
|
36
|
+
}
|
|
37
|
+
if (error.stack) {
|
|
38
|
+
logger.debug(error.stack)
|
|
39
|
+
}
|
|
40
|
+
process.exit(1)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = connect
|
|
@@ -2,20 +2,25 @@ const { Command } = require('commander')
|
|
|
2
2
|
|
|
3
3
|
const npm = new Command('npm')
|
|
4
4
|
|
|
5
|
+
const Session = require('./../../../db/session')
|
|
6
|
+
const sesh = new Session()
|
|
7
|
+
|
|
5
8
|
npm
|
|
6
9
|
.description('npm')
|
|
7
10
|
.allowUnknownOption()
|
|
8
11
|
|
|
9
|
-
// dotenvx-ops rotate npm
|
|
10
|
-
const
|
|
12
|
+
// dotenvx-ops rotate npm connect
|
|
13
|
+
const connectAction = require('./../../actions/rotate/npm/connect')
|
|
11
14
|
npm
|
|
12
|
-
.command('
|
|
15
|
+
.command('connect')
|
|
13
16
|
.description('connect passcard')
|
|
14
17
|
.requiredOption('--org <organizationSlug>')
|
|
15
18
|
.requiredOption('--username <username>')
|
|
16
19
|
.requiredOption('--password <password>')
|
|
17
20
|
.option('--email <email>')
|
|
18
|
-
.
|
|
21
|
+
.option('--hostname <url>', 'set hostname', sesh.hostname())
|
|
22
|
+
.option('--token <token>', 'set token', sesh.token())
|
|
23
|
+
.action(connectAction)
|
|
19
24
|
|
|
20
25
|
// dotenvx-ops rotate npm rotate
|
|
21
26
|
const rotateAction = require('./../../actions/rotate/npm/rotate')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { http } = require('../../lib/helpers/http')
|
|
2
2
|
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class PostRotateConnect {
|
|
5
5
|
constructor (hostname, token, org, slug, username, password, email = null, playwrightStorageStateStringified) {
|
|
6
6
|
this.hostname = hostname || 'https://ops.dotenvx.com'
|
|
7
7
|
this.token = token
|
|
@@ -16,7 +16,7 @@ class PostRotateLogin {
|
|
|
16
16
|
|
|
17
17
|
async run () {
|
|
18
18
|
const token = this.token
|
|
19
|
-
const url = `${this.hostname}/api/rotate/
|
|
19
|
+
const url = `${this.hostname}/api/rotate/connect`
|
|
20
20
|
|
|
21
21
|
const org = this.org
|
|
22
22
|
const slug = this.slug
|
|
@@ -51,4 +51,4 @@ class PostRotateLogin {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
module.exports =
|
|
54
|
+
module.exports = PostRotateConnect
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
const { logger } = require('@dotenvx/dotenvx')
|
|
2
2
|
const { chromium } = require('playwright')
|
|
3
3
|
|
|
4
|
+
const VIEWPORT_WIDTH = 1200
|
|
5
|
+
const VIEWPORT_HEIGHT = 742
|
|
6
|
+
const VIEWPORT = { width: VIEWPORT_WIDTH, height: VIEWPORT_HEIGHT }
|
|
7
|
+
const CHROME_ARGS = [
|
|
8
|
+
'--app=data:,', // starts a blank popup
|
|
9
|
+
'--disable-infobars',
|
|
10
|
+
'--disable-session-crashed-bubble',
|
|
11
|
+
'--noerrdialogs'
|
|
12
|
+
]
|
|
13
|
+
|
|
4
14
|
async function playwrightConnect (channel = 'chrome') {
|
|
5
15
|
const browser = await ensurePlaywrightBrowser(channel)
|
|
6
|
-
const context = await browser.newContext()
|
|
16
|
+
const context = await browser.newContext({ viewport: VIEWPORT })
|
|
7
17
|
const page = await context.newPage()
|
|
8
18
|
|
|
9
19
|
return { browser, context, page }
|
|
@@ -11,13 +21,13 @@ async function playwrightConnect (channel = 'chrome') {
|
|
|
11
21
|
|
|
12
22
|
async function ensurePlaywrightBrowser (channel = 'chrome') {
|
|
13
23
|
try {
|
|
14
|
-
return await chromium.launch({ headless: false, channel })
|
|
24
|
+
return await chromium.launch({ headless: false, channel, args: CHROME_ARGS })
|
|
15
25
|
} catch (err) {
|
|
16
26
|
if (String(err).includes('Executable doesn\'t exist')) {
|
|
17
27
|
logger.info('Installing chromium...')
|
|
18
28
|
const cp = require('child_process')
|
|
19
29
|
cp.execSync('npx playwright install chromium', { stdio: 'inherit' })
|
|
20
|
-
return await chromium.launch({ headless: false })
|
|
30
|
+
return await chromium.launch({ headless: false, args: CHROME_ARGS })
|
|
21
31
|
}
|
|
22
32
|
}
|
|
23
33
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const PostRotateConnect = require('./../api/postRotateConnect')
|
|
2
|
+
|
|
3
|
+
const playwrightConnect = require('./../helpers/playwrightConnect')
|
|
4
|
+
|
|
5
|
+
const TIMEOUT = 500 // visibility timeout
|
|
6
|
+
|
|
7
|
+
class RotateNpmConnect {
|
|
8
|
+
constructor (hostname, token, org, username, password, email = null) {
|
|
9
|
+
this.hostname = hostname
|
|
10
|
+
this.org = org
|
|
11
|
+
this.token = token
|
|
12
|
+
this.username = username
|
|
13
|
+
this.password = password
|
|
14
|
+
|
|
15
|
+
// optional
|
|
16
|
+
this.email = email
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async run () {
|
|
20
|
+
const hostname = this.hostname
|
|
21
|
+
const token = this.token
|
|
22
|
+
const org = this.org
|
|
23
|
+
const slug = 'npm' // hardcoded
|
|
24
|
+
const username = this.username
|
|
25
|
+
const password = this.password
|
|
26
|
+
const email = this.email
|
|
27
|
+
|
|
28
|
+
const { browser, context, page } = await playwrightConnect()
|
|
29
|
+
|
|
30
|
+
const usernameSelector = 'input[type="text"]'
|
|
31
|
+
const passwordSelector = 'input[type="password"]'
|
|
32
|
+
|
|
33
|
+
await page.goto('https://npmjs.com/login', { waitUntil: 'domcontentloaded' })
|
|
34
|
+
await page.waitForTimeout(TIMEOUT)
|
|
35
|
+
await page.fill(usernameSelector, username)
|
|
36
|
+
await page.waitForTimeout(TIMEOUT)
|
|
37
|
+
await page.fill(passwordSelector, password)
|
|
38
|
+
await page.waitForTimeout(TIMEOUT)
|
|
39
|
+
await page.press('input[type="password"]', 'Enter')
|
|
40
|
+
await page.waitForNavigation({ timeout: 0 })
|
|
41
|
+
await page.waitForSelector('img[alt="avatar"]', { state: 'visible', timeout: 0 })
|
|
42
|
+
|
|
43
|
+
const playwrightStorageStateStringified = JSON.stringify(await context.storageState())
|
|
44
|
+
|
|
45
|
+
const { url } = await new PostRotateConnect(hostname, token, org, slug, username, password, email, playwrightStorageStateStringified).run()
|
|
46
|
+
|
|
47
|
+
await browser.close()
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
url
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = RotateNpmConnect
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const { logger } = require('@dotenvx/dotenvx')
|
|
2
|
-
const PostRotateLogin = require('./../../../../lib/api/postRotateLogin')
|
|
3
|
-
const Session = require('./../../../../db/session')
|
|
4
|
-
const playwrightConnect = require('./../../../../lib/helpers/playwrightConnect')
|
|
5
|
-
|
|
6
|
-
const TIMEOUT = 500 // visibility timeout
|
|
7
|
-
|
|
8
|
-
async function login () {
|
|
9
|
-
const options = this.opts()
|
|
10
|
-
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
11
|
-
const slug = 'npm'
|
|
12
|
-
const { org, username, password, email } = options
|
|
13
|
-
const { browser, context, page } = await playwrightConnect()
|
|
14
|
-
|
|
15
|
-
const usernameSelector = 'input[type="text"]'
|
|
16
|
-
const passwordSelector = 'input[type="password"]'
|
|
17
|
-
|
|
18
|
-
await page.goto('https://npmjs.com/login', { waitUntil: 'domcontentloaded' })
|
|
19
|
-
await page.waitForTimeout(TIMEOUT)
|
|
20
|
-
await page.fill(usernameSelector, username)
|
|
21
|
-
await page.waitForTimeout(TIMEOUT)
|
|
22
|
-
await page.fill(passwordSelector, password)
|
|
23
|
-
await page.waitForTimeout(TIMEOUT)
|
|
24
|
-
await page.press('input[type="password"]', 'Enter')
|
|
25
|
-
await page.waitForNavigation({ timeout: 0 })
|
|
26
|
-
await page.waitForSelector('img[alt="avatar"]', { state: 'visible', timeout: 0 })
|
|
27
|
-
|
|
28
|
-
const sesh = new Session() // TODO: handle scenario where constructor fails
|
|
29
|
-
|
|
30
|
-
let hostname = process.env.DOTENVX_OPS_HOSTNAME || process.env.DOTENVX_RADAR_HOSTNAME || options.hostname
|
|
31
|
-
if (!hostname) {
|
|
32
|
-
hostname = sesh.hostname()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let token = process.env.DOTENVX_OPS_TOKEN || process.env.DOTENVX_RADAR_TOKEN || options.token
|
|
36
|
-
if (!token) {
|
|
37
|
-
token = sesh.token()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const playwrightStorageStateStringified = JSON.stringify(await context.storageState())
|
|
41
|
-
const { uid } = await new PostRotateLogin(hostname, token, org, slug, username, password, email, playwrightStorageStateStringified).run()
|
|
42
|
-
|
|
43
|
-
await browser.close()
|
|
44
|
-
process.stdout.write(uid)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = login
|