@dotenvx/dotenvx-ops 0.26.0 → 0.27.0
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/openai/connect.js +75 -0
- package/src/cli/commands/rotate/openai.js +25 -0
- package/src/cli/commands/rotate.js +1 -0
- package/src/lib/helpers/playwrightConnect.js +2 -8
- package/src/lib/services/rotateOpenaiConnect.js +60 -0
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.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.27.0...main)
|
|
6
|
+
|
|
7
|
+
## [0.27.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.26.0...v0.27.0) (2025-12-14)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add `rotate openai connect` ([#16](https://github.com/dotenvx/dotenvx-ops/pull/17))
|
|
6
12
|
|
|
7
13
|
## [0.26.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.25.2...v0.26.0) (2025-12-14)
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const { logger } = require('@dotenvx/dotenvx')
|
|
2
|
+
const prompts = require('@inquirer/prompts')
|
|
3
|
+
const Session = require('./../../../../db/session')
|
|
4
|
+
const RotateOpenaiConnect = require('./../../../../lib/services/rotateOpenaiConnect')
|
|
5
|
+
const { createSpinner } = require('./../../../../lib/helpers/createSpinner')
|
|
6
|
+
const GetAccount = require('./../../../../lib/api/getAccount')
|
|
7
|
+
|
|
8
|
+
const spinner = createSpinner('waiting on browser completion')
|
|
9
|
+
|
|
10
|
+
async function connect () {
|
|
11
|
+
const options = this.opts()
|
|
12
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const sesh = new Session()
|
|
16
|
+
const hostname = options.hostname
|
|
17
|
+
const token = options.token || sesh.token()
|
|
18
|
+
let org = options.org
|
|
19
|
+
let username = options.username
|
|
20
|
+
let password = options.password
|
|
21
|
+
const email = options.email
|
|
22
|
+
|
|
23
|
+
// user must be logged in to use feature
|
|
24
|
+
const accountJson = await new GetAccount(hostname, token).run()
|
|
25
|
+
|
|
26
|
+
if (!org) {
|
|
27
|
+
const choices = accountJson.organizations.map(o => ({
|
|
28
|
+
name: o.provider_slug,
|
|
29
|
+
value: o.provider_slug
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
if (choices.length === 1) {
|
|
33
|
+
org = choices[0].value // just use first choice
|
|
34
|
+
} else {
|
|
35
|
+
org = await prompts.select({
|
|
36
|
+
message: 'Select dotenvx organization',
|
|
37
|
+
choices
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!username) {
|
|
43
|
+
username = await prompts.input({ message: 'openai username:' })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!password) {
|
|
47
|
+
password = await prompts.password({ message: 'openai password:' })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
spinner.start()
|
|
51
|
+
|
|
52
|
+
const { uid, url } = await new RotateOpenaiConnect(hostname, token, org, username, password, email).run()
|
|
53
|
+
|
|
54
|
+
spinner.stop()
|
|
55
|
+
|
|
56
|
+
logger.success(`✔ connected [${url}]`)
|
|
57
|
+
logger.help(`⮕ next run [dotenvx-ops rotate dotenvx://${uid}]`)
|
|
58
|
+
} catch (error) {
|
|
59
|
+
spinner.stop()
|
|
60
|
+
if (error.message) {
|
|
61
|
+
logger.error(error.message)
|
|
62
|
+
} else {
|
|
63
|
+
logger.error(error)
|
|
64
|
+
}
|
|
65
|
+
if (error.help) {
|
|
66
|
+
logger.help(error.help)
|
|
67
|
+
}
|
|
68
|
+
if (error.stack) {
|
|
69
|
+
logger.debug(error.stack)
|
|
70
|
+
}
|
|
71
|
+
process.exit(1)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = connect
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { Command } = require('commander')
|
|
2
|
+
|
|
3
|
+
const openai = new Command('openai')
|
|
4
|
+
|
|
5
|
+
const Session = require('./../../../db/session')
|
|
6
|
+
const sesh = new Session()
|
|
7
|
+
|
|
8
|
+
openai
|
|
9
|
+
.description('openai')
|
|
10
|
+
.allowUnknownOption()
|
|
11
|
+
|
|
12
|
+
// dotenvx-ops rotate openai connect
|
|
13
|
+
const connectAction = require('./../../actions/rotate/openai/connect')
|
|
14
|
+
openai
|
|
15
|
+
.command('connect')
|
|
16
|
+
.description('connect passcard')
|
|
17
|
+
.option('--org <organizationSlug>')
|
|
18
|
+
.option('--username <username>')
|
|
19
|
+
.option('--password <password>')
|
|
20
|
+
.option('--email <email>')
|
|
21
|
+
.option('--hostname <url>', 'set hostname', sesh.hostname())
|
|
22
|
+
.option('--token <token>', 'set token')
|
|
23
|
+
.action(connectAction)
|
|
24
|
+
|
|
25
|
+
module.exports = openai
|
|
@@ -11,6 +11,7 @@ rotate
|
|
|
11
11
|
|
|
12
12
|
rotate.addCommand(require('./rotate/github'))
|
|
13
13
|
rotate.addCommand(require('./rotate/npm'))
|
|
14
|
+
rotate.addCommand(require('./rotate/openai'))
|
|
14
15
|
|
|
15
16
|
// dotenvx-ops rotate (fallback positional argument handler)
|
|
16
17
|
const rotateAction = require('../actions/rotate')
|
|
@@ -4,12 +4,6 @@ const { chromium } = require('playwright')
|
|
|
4
4
|
const VIEWPORT_WIDTH = 1200
|
|
5
5
|
const VIEWPORT_HEIGHT = 742
|
|
6
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
7
|
|
|
14
8
|
async function playwrightConnect (channel = 'chrome') {
|
|
15
9
|
const browser = await ensurePlaywrightBrowser(channel)
|
|
@@ -21,13 +15,13 @@ async function playwrightConnect (channel = 'chrome') {
|
|
|
21
15
|
|
|
22
16
|
async function ensurePlaywrightBrowser (channel = 'chrome') {
|
|
23
17
|
try {
|
|
24
|
-
return await chromium.launch({ headless: false, channel
|
|
18
|
+
return await chromium.launch({ headless: false, channel })
|
|
25
19
|
} catch (err) {
|
|
26
20
|
if (String(err).includes('Executable doesn\'t exist')) {
|
|
27
21
|
logger.info('Installing chromium...')
|
|
28
22
|
const cp = require('child_process')
|
|
29
23
|
cp.execSync('npx playwright install chromium', { stdio: 'inherit' })
|
|
30
|
-
return await chromium.launch({ headless: false
|
|
24
|
+
return await chromium.launch({ headless: false })
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
27
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const PostRotateConnect = require('./../api/postRotateConnect')
|
|
2
|
+
|
|
3
|
+
const playwrightConnect = require('./../helpers/playwrightConnect')
|
|
4
|
+
|
|
5
|
+
const TIMEOUT = 500 // visibility timeout
|
|
6
|
+
const TIMEOUT_MEDIUM = 5000 // visibility timeout
|
|
7
|
+
const TIMEOUT_LONG = 10000 // visibility timeout
|
|
8
|
+
const SLUG = 'openai' // hardcoded
|
|
9
|
+
|
|
10
|
+
class RotateOpenaiConnect {
|
|
11
|
+
constructor (hostname, token, org, username, password, email = null) {
|
|
12
|
+
this.hostname = hostname
|
|
13
|
+
this.org = org
|
|
14
|
+
this.token = token
|
|
15
|
+
this.username = username
|
|
16
|
+
this.password = password
|
|
17
|
+
|
|
18
|
+
// optional
|
|
19
|
+
this.email = username
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async run () {
|
|
23
|
+
const hostname = this.hostname
|
|
24
|
+
const token = this.token
|
|
25
|
+
const org = this.org
|
|
26
|
+
const username = this.username
|
|
27
|
+
const password = this.password
|
|
28
|
+
const email = this.email
|
|
29
|
+
|
|
30
|
+
const { browser, context, page } = await playwrightConnect()
|
|
31
|
+
|
|
32
|
+
const emailSelector = 'input[type="email"]'
|
|
33
|
+
const passwordSelector = 'input[type="password"]'
|
|
34
|
+
|
|
35
|
+
await page.goto('https://platform.openai.com/login', { waitUntil: 'domcontentloaded' })
|
|
36
|
+
await page.waitForTimeout(TIMEOUT)
|
|
37
|
+
await page.fill(emailSelector, username)
|
|
38
|
+
await page.waitForTimeout(TIMEOUT_MEDIUM)
|
|
39
|
+
await page.getByRole('button', { name: /continue|confirm|/i }).first().click()
|
|
40
|
+
await page.waitForTimeout(TIMEOUT_LONG)
|
|
41
|
+
await page.fill(passwordSelector, password) // await page.fill('input[autocomplete="current-password"]', password)
|
|
42
|
+
await page.waitForTimeout(TIMEOUT)
|
|
43
|
+
await page.press('input[type="password"]', 'Enter')
|
|
44
|
+
await page.waitForNavigation({ timeout: 0 })
|
|
45
|
+
await page.waitForSelector('a[href="/settings"]', { state: 'visible', timeout: 0 })
|
|
46
|
+
|
|
47
|
+
const playwrightStorageStateStringified = JSON.stringify(await context.storageState())
|
|
48
|
+
|
|
49
|
+
const { uid, url } = await new PostRotateConnect(hostname, token, org, SLUG, username, password, email, playwrightStorageStateStringified).run()
|
|
50
|
+
|
|
51
|
+
await browser.close()
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
uid,
|
|
55
|
+
url
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = RotateOpenaiConnect
|