@dotenvx/dotenvx-ops 0.23.1 → 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 +13 -1
- package/package.json +1 -1
- package/src/cli/actions/rotate/npm/connect.js +44 -0
- package/src/cli/actions/rotate/npm/rotate.js +9 -0
- package/src/cli/commands/rotate/npm.js +20 -30
- package/src/lib/api/postRotateConnect.js +54 -0
- 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 -25
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,19 @@
|
|
|
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))
|
|
12
|
+
|
|
13
|
+
## [0.23.2](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.1...v0.23.2) (2025-12-04)
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
* Create passcard on successful login ([#11](https://github.com/dotenvx/dotenvx-ops/pull/11))
|
|
6
18
|
|
|
7
19
|
## [0.23.1](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.0...v0.23.1) (2025-12-03)
|
|
8
20
|
|
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,41 +2,31 @@ 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
|
-
.description('
|
|
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('
|
|
13
|
-
.description('
|
|
15
|
+
.command('connect')
|
|
16
|
+
.description('connect passcard')
|
|
17
|
+
.requiredOption('--org <organizationSlug>')
|
|
14
18
|
.requiredOption('--username <username>')
|
|
15
19
|
.requiredOption('--password <password>')
|
|
16
|
-
.
|
|
20
|
+
.option('--email <email>')
|
|
21
|
+
.option('--hostname <url>', 'set hostname', sesh.hostname())
|
|
22
|
+
.option('--token <token>', 'set token', sesh.token())
|
|
23
|
+
.action(connectAction)
|
|
24
|
+
|
|
25
|
+
// dotenvx-ops rotate npm rotate
|
|
26
|
+
const rotateAction = require('./../../actions/rotate/npm/rotate')
|
|
27
|
+
npm
|
|
28
|
+
.command('rotate')
|
|
29
|
+
.description('rotate api key')
|
|
30
|
+
.action(rotateAction)
|
|
17
31
|
|
|
18
|
-
//
|
|
19
|
-
// // dotenvx-ops settings token
|
|
20
|
-
// const tokenAction = require('./../actions/settings/token')
|
|
21
|
-
// settings
|
|
22
|
-
// .command('token')
|
|
23
|
-
// .description('print your access token (--unmask)')
|
|
24
|
-
// .option('--unmask', 'unmask access token')
|
|
25
|
-
// .action(tokenAction)
|
|
26
|
-
//
|
|
27
|
-
// // dotenvx-ops settings device
|
|
28
|
-
// const deviceAction = require('./../actions/settings/device')
|
|
29
|
-
// settings
|
|
30
|
-
// .command('device')
|
|
31
|
-
// .description('print your device pubkey (--unmask)')
|
|
32
|
-
// .option('--unmask', 'unmask device pubkey')
|
|
33
|
-
// .action(deviceAction)
|
|
34
|
-
//
|
|
35
|
-
// // dotenvx-ops settings hostname
|
|
36
|
-
// const hostnameAction = require('./../actions/settings/hostname')
|
|
37
|
-
// settings
|
|
38
|
-
// .command('hostname')
|
|
39
|
-
// .description('print hostname')
|
|
40
|
-
// .action(hostnameAction)
|
|
41
|
-
//
|
|
42
32
|
module.exports = npm
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const { http } = require('../../lib/helpers/http')
|
|
2
|
+
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
|
+
|
|
4
|
+
class PostRotateConnect {
|
|
5
|
+
constructor (hostname, token, org, slug, username, password, email = null, playwrightStorageStateStringified) {
|
|
6
|
+
this.hostname = hostname || 'https://ops.dotenvx.com'
|
|
7
|
+
this.token = token
|
|
8
|
+
|
|
9
|
+
this.org = org
|
|
10
|
+
this.slug = slug
|
|
11
|
+
this.username = username
|
|
12
|
+
this.password = password
|
|
13
|
+
this.email = email
|
|
14
|
+
this.playwrightStorageStateStringified = playwrightStorageStateStringified
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async run () {
|
|
18
|
+
const token = this.token
|
|
19
|
+
const url = `${this.hostname}/api/rotate/connect`
|
|
20
|
+
|
|
21
|
+
const org = this.org
|
|
22
|
+
const slug = this.slug
|
|
23
|
+
const username = this.username
|
|
24
|
+
const password = this.password
|
|
25
|
+
const email = this.email
|
|
26
|
+
const playwrightStorageStateStringified = this.playwrightStorageStateStringified
|
|
27
|
+
|
|
28
|
+
const resp = await http(url, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${token}`,
|
|
32
|
+
'Content-Type': 'application/json'
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
org,
|
|
36
|
+
slug,
|
|
37
|
+
username,
|
|
38
|
+
password,
|
|
39
|
+
email,
|
|
40
|
+
playwright_storage_state: playwrightStorageStateStringified
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const json = await resp.body.json()
|
|
45
|
+
|
|
46
|
+
if (resp.statusCode >= 400) {
|
|
47
|
+
throw buildApiError(resp.statusCode, json)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return json
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
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,25 +0,0 @@
|
|
|
1
|
-
const { logger } = require('@dotenvx/dotenvx')
|
|
2
|
-
const playwrightConnect = require('./../../../../lib/helpers/playwrightConnect')
|
|
3
|
-
|
|
4
|
-
const TIMEOUT = 1200 // visibility timeout
|
|
5
|
-
|
|
6
|
-
async function login () {
|
|
7
|
-
const options = this.opts()
|
|
8
|
-
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
9
|
-
const { username, password } = options
|
|
10
|
-
const { browser, context, page } = await playwrightConnect()
|
|
11
|
-
await page.goto('https://npmjs.com/login', { waitUntil: 'domcontentloaded' })
|
|
12
|
-
await page.waitForTimeout(TIMEOUT)
|
|
13
|
-
await page.fill('input[type="text"]', username)
|
|
14
|
-
await page.waitForTimeout(TIMEOUT)
|
|
15
|
-
await page.fill('input[type="password"]', password)
|
|
16
|
-
await page.waitForTimeout(TIMEOUT)
|
|
17
|
-
await page.press('input[type="password"]', 'Enter')
|
|
18
|
-
await page.waitForNavigation({ timeout: 0 })
|
|
19
|
-
await page.waitForSelector('img[alt="avatar"]', { state: 'visible', timeout: 0 })
|
|
20
|
-
const storageState = JSON.stringify(await context.storageState())
|
|
21
|
-
await browser.close()
|
|
22
|
-
process.stdout.write(storageState)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = login
|