@dotenvx/dotenvx-ops 0.26.0 → 0.28.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 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.26.0...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.28.0...main)
6
+
7
+ ## [0.28.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.27.0...v0.28.0) (2025-12-22)
8
+
9
+ ### Added
10
+
11
+ * Add `backup` command for backing up .env.keys files. Will serve as entry-level low priced product to serve many. ([#18](https://github.com/dotenvx/dotenvx-ops/pull/18))
12
+
13
+ ## [0.27.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.26.0...v0.27.0) (2025-12-14)
14
+
15
+ ### Added
16
+
17
+ * Add `rotate openai connect` ([#16](https://github.com/dotenvx/dotenvx-ops/pull/17))
6
18
 
7
19
  ## [0.26.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.25.2...v0.26.0) (2025-12-14)
8
20
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.26.0",
2
+ "version": "0.28.0",
3
3
  "name": "@dotenvx/dotenvx-ops",
4
4
  "description": "Dotenvx Ops – commercial tooling for .env files",
5
5
  "author": "@motdotla",
@@ -0,0 +1,53 @@
1
+ // const fs = require('fs')
2
+ // const crypto = require('crypto')
3
+
4
+ const { logger } = require('@dotenvx/dotenvx')
5
+
6
+ const { createSpinner } = require('./../../lib/helpers/createSpinner')
7
+
8
+ const Backup = require('./../../lib/services/backup')
9
+
10
+ const spinner = createSpinner('backing up')
11
+
12
+ async function backup () {
13
+ // debug opts
14
+ const options = this.opts()
15
+
16
+ try {
17
+ logger.debug(`options: ${JSON.stringify(options)}`)
18
+
19
+ spinner.start()
20
+
21
+ const {
22
+ projectUsernameName,
23
+ files
24
+ } = await new Backup(options.hostname, options.force).run()
25
+ logger.debug(`files: ${JSON.stringify(files)}`)
26
+
27
+ // write output files
28
+ // for (const file of files) {
29
+ // // const { filepath, src, sha } = file
30
+ // }
31
+
32
+ spinner.stop()
33
+
34
+ logger.success(`✔ backed up [${projectUsernameName}]`)
35
+ } catch (error) {
36
+ spinner.stop()
37
+ if (error.message) {
38
+ logger.error(error.message)
39
+ } else {
40
+ logger.error(error)
41
+ }
42
+ if (error.help) {
43
+ logger.help(error.help)
44
+ }
45
+ if (error.stack) {
46
+ logger.debug(error.stack)
47
+ }
48
+
49
+ process.exit(1)
50
+ }
51
+ }
52
+
53
+ module.exports = backup
@@ -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')
@@ -30,6 +30,14 @@ program
30
30
  .version(packageJson.version)
31
31
  .allowUnknownOption()
32
32
 
33
+ // dotenvx-ops backup
34
+ const backupAction = require('./actions/backup')
35
+ program
36
+ .command('backup')
37
+ .description('backup .env.keys file(s)')
38
+ .option('-h, --hostname <url>', 'set hostname', sesh.hostname())
39
+ .action(backupAction)
40
+
33
41
  // dotenvx-ops observe base64String
34
42
  const observeAction = require('./actions/observe')
35
43
  program.command('observe')
@@ -0,0 +1,65 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+ const packageJson = require('../../lib/helpers/packageJson')
4
+
5
+ class PostBackup {
6
+ constructor (hostname, token, devicePublicKey, encoded, dotenvxProjectId, pwd = null, gitUrl = null, gitBranch = null, systemUuid = null, osPlatform = null, osArch = null) {
7
+ this.hostname = hostname || 'https://ops.dotenvx.com'
8
+ this.token = token
9
+ this.devicePublicKey = devicePublicKey
10
+ this.encoded = encoded
11
+ this.dotenvxProjectId = dotenvxProjectId
12
+ this.pwd = pwd
13
+ this.gitUrl = gitUrl
14
+ this.gitBranch = gitBranch
15
+ this.systemUuid = systemUuid
16
+ this.osPlatform = osPlatform
17
+ this.osArch = osArch
18
+ }
19
+
20
+ async run () {
21
+ const token = this.token
22
+ const devicePublicKey = this.devicePublicKey
23
+ const url = `${this.hostname}/api/backup`
24
+ const encoded = this.encoded
25
+ const dotenvxProjectId = this.dotenvxProjectId
26
+ const backedupAt = new Date().toISOString()
27
+ const pwd = this.pwd
28
+ const gitUrl = this.gitUrl
29
+ const gitBranch = this.gitBranch
30
+ const systemUuid = this.systemUuid
31
+ const osPlatform = this.osPlatform
32
+ const osArch = this.osArch
33
+
34
+ const resp = await http(url, {
35
+ method: 'POST',
36
+ headers: {
37
+ Authorization: `Bearer ${token}`,
38
+ 'Content-Type': 'application/json'
39
+ },
40
+ body: JSON.stringify({
41
+ device_public_key: devicePublicKey,
42
+ encoded,
43
+ dotenvx_project_id: dotenvxProjectId,
44
+ backedup_at: backedupAt,
45
+ pwd,
46
+ git_url: gitUrl,
47
+ git_branch: gitBranch,
48
+ system_uuid: systemUuid,
49
+ os_platform: osPlatform,
50
+ os_arch: osArch,
51
+ cli_version: packageJson.version
52
+ })
53
+ })
54
+
55
+ const json = await resp.body.json()
56
+
57
+ if (resp.statusCode >= 400) {
58
+ throw buildApiError(resp.statusCode, json)
59
+ }
60
+
61
+ return json
62
+ }
63
+ }
64
+
65
+ module.exports = PostBackup
@@ -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, args: CHROME_ARGS })
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, args: CHROME_ARGS })
24
+ return await chromium.launch({ headless: false })
31
25
  }
32
26
  }
33
27
  }
@@ -0,0 +1,68 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const si = require('systeminformation')
4
+ const dotenvx = require('@dotenvx/dotenvx')
5
+
6
+ const Session = require('./../../db/session')
7
+
8
+ const gitUrl = require('./../helpers/gitUrl')
9
+ const gitBranch = require('./../helpers/gitBranch')
10
+ const dotenvxProjectId = require('./../helpers/dotenvxProjectId')
11
+
12
+ // api calls
13
+ const PostBackup = require('./../api/postBackup')
14
+
15
+ class Backup {
16
+ constructor (hostname) {
17
+ this.hostname = hostname
18
+ this.cwd = process.cwd()
19
+ }
20
+
21
+ async run () {
22
+ const sesh = new Session()
23
+ const token = sesh.token()
24
+ const devicePublicKey = sesh.devicePublicKey()
25
+
26
+ // required
27
+ const files = this._files()
28
+ const payload = { files }
29
+ const encoded = Buffer.from(JSON.stringify(payload)).toString('base64')
30
+ const _dotenvxProjectId = dotenvxProjectId(this.cwd)
31
+
32
+ // optional
33
+ const _pwd = this.cwd
34
+ const _gitUrl = gitUrl()
35
+ const _gitBranch = gitBranch()
36
+
37
+ const system = await si.system()
38
+ const _systemUuid = system.uuid
39
+
40
+ const osInfo = await si.osInfo()
41
+ const _osPlatform = osInfo.platform
42
+ const _osArch = osInfo.arch
43
+
44
+ const data = await new PostBackup(this.hostname, token, devicePublicKey, encoded, _dotenvxProjectId, _pwd, _gitUrl, _gitBranch, _systemUuid, _osPlatform, _osArch).run()
45
+
46
+ return {
47
+ id: data.id,
48
+ dotenvxProjectId: data.dotenvx_project_id,
49
+ projectUsernameName: data.project_username_name,
50
+ files: data.files
51
+ }
52
+ }
53
+
54
+ _files () {
55
+ const out = []
56
+ const filepaths = dotenvx.ls(this.cwd, '.env.keys*')
57
+
58
+ for (const fp of filepaths) {
59
+ const abs = path.join(this.cwd, fp)
60
+ const src = fs.readFileSync(abs, 'utf8')
61
+ out.push({ filepath: fp, src })
62
+ }
63
+
64
+ return out
65
+ }
66
+ }
67
+
68
+ module.exports = Backup
@@ -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