@dotenvx/dotenvx-ops 0.23.0 → 0.23.2
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 +2 -1
- package/src/cli/actions/rotate/npm/login.js +32 -4
- package/src/cli/actions/rotate/npm/rotate.js +9 -0
- package/src/cli/commands/rotate/npm.js +13 -26
- package/src/lib/api/postRotateLogin.js +54 -0
- package/src/lib/helpers/playwrightConnect.js +4 -4
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.2...main)
|
|
6
|
+
|
|
7
|
+
## [0.23.2](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.1...v0.23.2) (2025-12-04)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* Create passcard on successful login ([#11](https://github.com/dotenvx/dotenvx-ops/pull/11))
|
|
12
|
+
|
|
13
|
+
## [0.23.1](https://github.com/dotenvx/dotenvx-ops/compare/v0.23.0...v0.23.1) (2025-12-03)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
* Stdout storageState with `rotate npm login` ([#10](https://github.com/dotenvx/dotenvx-ops/pull/10))
|
|
6
18
|
|
|
7
19
|
## [0.23.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.22.2...v0.23.0) (2025-12-03)
|
|
8
20
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.23.
|
|
2
|
+
"version": "0.23.2",
|
|
3
3
|
"name": "@dotenvx/dotenvx-ops",
|
|
4
4
|
"description": "Dotenvx Ops – commercial tooling for .env files",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@clack/core": "^0.4.2",
|
|
44
44
|
"@dotenvx/dotenvx": "^1.48.1",
|
|
45
|
+
"@inquirer/prompts": "^7.10.1",
|
|
45
46
|
"arch": "^2.1.1",
|
|
46
47
|
"commander": "^11.1.0",
|
|
47
48
|
"conf": "^10.2.0",
|
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
const { logger } = require('@dotenvx/dotenvx')
|
|
2
|
+
const PostRotateLogin = require('./../../../../lib/api/postRotateLogin')
|
|
3
|
+
const Session = require('./../../../../db/session')
|
|
2
4
|
const playwrightConnect = require('./../../../../lib/helpers/playwrightConnect')
|
|
3
5
|
|
|
4
|
-
const TIMEOUT =
|
|
6
|
+
const TIMEOUT = 500 // visibility timeout
|
|
5
7
|
|
|
6
8
|
async function login () {
|
|
7
9
|
const options = this.opts()
|
|
8
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()
|
|
9
14
|
|
|
10
|
-
const
|
|
15
|
+
const usernameSelector = 'input[type="text"]'
|
|
16
|
+
const passwordSelector = 'input[type="password"]'
|
|
11
17
|
|
|
12
18
|
await page.goto('https://npmjs.com/login', { waitUntil: 'domcontentloaded' })
|
|
13
19
|
await page.waitForTimeout(TIMEOUT)
|
|
14
|
-
await
|
|
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
|
|
15
29
|
|
|
16
|
-
process.
|
|
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)
|
|
17
45
|
}
|
|
18
46
|
|
|
19
47
|
module.exports = login
|
|
@@ -3,38 +3,25 @@ const { Command } = require('commander')
|
|
|
3
3
|
const npm = new Command('npm')
|
|
4
4
|
|
|
5
5
|
npm
|
|
6
|
-
.description('
|
|
6
|
+
.description('npm')
|
|
7
7
|
.allowUnknownOption()
|
|
8
8
|
|
|
9
9
|
// dotenvx-ops rotate npm login
|
|
10
10
|
const loginAction = require('./../../actions/rotate/npm/login')
|
|
11
11
|
npm
|
|
12
12
|
.command('login')
|
|
13
|
-
.description('
|
|
13
|
+
.description('connect passcard')
|
|
14
|
+
.requiredOption('--org <organizationSlug>')
|
|
15
|
+
.requiredOption('--username <username>')
|
|
16
|
+
.requiredOption('--password <password>')
|
|
17
|
+
.option('--email <email>')
|
|
14
18
|
.action(loginAction)
|
|
15
19
|
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// .action(tokenAction)
|
|
24
|
-
//
|
|
25
|
-
// // dotenvx-ops settings device
|
|
26
|
-
// const deviceAction = require('./../actions/settings/device')
|
|
27
|
-
// settings
|
|
28
|
-
// .command('device')
|
|
29
|
-
// .description('print your device pubkey (--unmask)')
|
|
30
|
-
// .option('--unmask', 'unmask device pubkey')
|
|
31
|
-
// .action(deviceAction)
|
|
32
|
-
//
|
|
33
|
-
// // dotenvx-ops settings hostname
|
|
34
|
-
// const hostnameAction = require('./../actions/settings/hostname')
|
|
35
|
-
// settings
|
|
36
|
-
// .command('hostname')
|
|
37
|
-
// .description('print hostname')
|
|
38
|
-
// .action(hostnameAction)
|
|
39
|
-
//
|
|
20
|
+
// dotenvx-ops rotate npm rotate
|
|
21
|
+
const rotateAction = require('./../../actions/rotate/npm/rotate')
|
|
22
|
+
npm
|
|
23
|
+
.command('rotate')
|
|
24
|
+
.description('rotate api key')
|
|
25
|
+
.action(rotateAction)
|
|
26
|
+
|
|
40
27
|
module.exports = npm
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const { http } = require('../../lib/helpers/http')
|
|
2
|
+
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
|
+
|
|
4
|
+
class PostRotateLogin {
|
|
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/login`
|
|
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 = PostRotateLogin
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
const { logger } = require('@dotenvx/dotenvx')
|
|
2
2
|
const { chromium } = require('playwright')
|
|
3
3
|
|
|
4
|
-
async function playwrightConnect () {
|
|
5
|
-
const browser = await ensurePlaywrightBrowser()
|
|
4
|
+
async function playwrightConnect (channel = 'chrome') {
|
|
5
|
+
const browser = await ensurePlaywrightBrowser(channel)
|
|
6
6
|
const context = await browser.newContext()
|
|
7
7
|
const page = await context.newPage()
|
|
8
8
|
|
|
9
9
|
return { browser, context, page }
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
async function ensurePlaywrightBrowser () {
|
|
12
|
+
async function ensurePlaywrightBrowser (channel = 'chrome') {
|
|
13
13
|
try {
|
|
14
|
-
return await chromium.launch({ headless: false })
|
|
14
|
+
return await chromium.launch({ headless: false, channel })
|
|
15
15
|
} catch (err) {
|
|
16
16
|
if (String(err).includes('Executable doesn\'t exist')) {
|
|
17
17
|
logger.info('Installing chromium...')
|