@dotenvx/dotenvx-ops 0.20.1 → 0.21.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 +13 -1
- package/package.json +1 -1
- package/src/cli/actions/login.js +3 -1
- package/src/cli/actions/observe.js +2 -1
- package/src/cli/dotenvx-ops.js +1 -0
- package/src/lib/api/postOauthDeviceCode.js +5 -2
- package/src/lib/api/postObserve.js +5 -2
- package/src/lib/helpers/dotenvxProjectId.js +36 -0
- package/src/lib/main.js +4 -1
- package/src/lib/services/sync.js +3 -29
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.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.21.0...main)
|
|
6
|
+
|
|
7
|
+
## [0.21.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.20.2...v0.21.0) (2025-10-11)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Send `DOTENVX_PROJECT_ID` along with `observe` call ([#5](https://github.com/dotenvx/dotenvx-ops/pull/5))
|
|
12
|
+
|
|
13
|
+
## [0.20.2](https://github.com/dotenvx/dotenvx-ops/compare/v0.20.1...v0.20.2) (2025-10-07)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
* Send `DOTENVX_PROJECT_ID` along with login request for redirect convenience when present
|
|
6
18
|
|
|
7
19
|
## [0.20.1](https://github.com/dotenvx/dotenvx-ops/compare/v0.20.0...v0.20.1) (2025-10-07)
|
|
8
20
|
|
package/package.json
CHANGED
package/src/cli/actions/login.js
CHANGED
|
@@ -8,6 +8,7 @@ const { createSpinner } = require('./../../lib/helpers/createSpinner')
|
|
|
8
8
|
const confirm = require('./../../lib/helpers/confirm')
|
|
9
9
|
const truncate = require('./../../lib/helpers/truncate')
|
|
10
10
|
const formatCode = require('./../../lib/helpers/formatCode')
|
|
11
|
+
const dotenvxProjectId = require('./../../lib/helpers/dotenvxProjectId')
|
|
11
12
|
|
|
12
13
|
const spinner = createSpinner('waiting on browser authorization')
|
|
13
14
|
|
|
@@ -73,7 +74,8 @@ async function login () {
|
|
|
73
74
|
const sesh = new Session()
|
|
74
75
|
const devicePublicKey = sesh.devicePublicKey()
|
|
75
76
|
const systemInformation = await sesh.systemInformation()
|
|
76
|
-
const
|
|
77
|
+
const _dotenvxProjectId = dotenvxProjectId(process.cwd(), false)
|
|
78
|
+
const data = await new PostOauthDeviceCode(hostname, devicePublicKey, systemInformation, _dotenvxProjectId).run()
|
|
77
79
|
|
|
78
80
|
const deviceCode = data.device_code
|
|
79
81
|
const userCode = data.user_code
|
|
@@ -11,9 +11,10 @@ async function observe (base64) {
|
|
|
11
11
|
|
|
12
12
|
const hostname = options.hostname
|
|
13
13
|
const token = options.token
|
|
14
|
+
const dotenvxProjectId = options.dotenvxProjectId
|
|
14
15
|
|
|
15
16
|
try {
|
|
16
|
-
await main.observe(base64, { hostname, token })
|
|
17
|
+
await main.observe(base64, { hostname, token, dotenvxProjectId })
|
|
17
18
|
} catch (error) {
|
|
18
19
|
if (error.message) {
|
|
19
20
|
logger.error(error.message)
|
package/src/cli/dotenvx-ops.js
CHANGED
|
@@ -39,6 +39,7 @@ program.command('observe')
|
|
|
39
39
|
.argument('BASE64', 'BASE64')
|
|
40
40
|
.option('--hostname <url>', 'set hostname', sesh.hostname())
|
|
41
41
|
.option('--token <token>', 'set token')
|
|
42
|
+
.option('--dotenvxProjectId <identifier>', 'set DOTENVX_PROJECT_ID')
|
|
42
43
|
.action(function (...args) {
|
|
43
44
|
observeAction.apply(this, args)
|
|
44
45
|
})
|
|
@@ -6,16 +6,18 @@ const buildOauthError = require('../../lib/helpers/buildOauthError')
|
|
|
6
6
|
const OAUTH_CLIENT_ID = 'oac_dotenvxcli'
|
|
7
7
|
|
|
8
8
|
class PostOauthDeviceCode {
|
|
9
|
-
constructor (hostname, devicePublicKey, systemInformation) {
|
|
9
|
+
constructor (hostname, devicePublicKey, systemInformation, dotenvxProjectId = null) {
|
|
10
10
|
this.hostname = hostname
|
|
11
11
|
this.devicePublicKey = devicePublicKey
|
|
12
12
|
this.systemInformation = systemInformation
|
|
13
|
+
this.dotenvxProjectId = dotenvxProjectId
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
async run () {
|
|
16
17
|
const url = `${this.hostname}/oauth/device/code`
|
|
17
18
|
const devicePublicKey = this.devicePublicKey
|
|
18
19
|
const systemInformation = this.systemInformation
|
|
20
|
+
const dotenvxProjectId = this.dotenvxProjectId
|
|
19
21
|
|
|
20
22
|
const resp = await http(url, {
|
|
21
23
|
method: 'POST',
|
|
@@ -25,7 +27,8 @@ class PostOauthDeviceCode {
|
|
|
25
27
|
body: JSON.stringify({
|
|
26
28
|
client_id: OAUTH_CLIENT_ID,
|
|
27
29
|
device_public_key: devicePublicKey,
|
|
28
|
-
system_information: systemInformation
|
|
30
|
+
system_information: systemInformation,
|
|
31
|
+
dotenvx_project_id: dotenvxProjectId
|
|
29
32
|
})
|
|
30
33
|
})
|
|
31
34
|
|
|
@@ -3,7 +3,7 @@ const buildApiError = require('../../lib/helpers/buildApiError')
|
|
|
3
3
|
const packageJson = require('../../lib/helpers/packageJson')
|
|
4
4
|
|
|
5
5
|
class PostObserve {
|
|
6
|
-
constructor (hostname, token, encoded, pwd = null, gitUrl = null, gitBranch = null, systemUuid = null, osPlatform = null, osArch = null) {
|
|
6
|
+
constructor (hostname, token, encoded, pwd = null, gitUrl = null, gitBranch = null, systemUuid = null, osPlatform = null, osArch = null, dotenvxProjectId = null) {
|
|
7
7
|
this.hostname = hostname || 'https://ops.dotenvx.com'
|
|
8
8
|
this.token = token
|
|
9
9
|
this.encoded = encoded
|
|
@@ -13,6 +13,7 @@ class PostObserve {
|
|
|
13
13
|
this.systemUuid = systemUuid
|
|
14
14
|
this.osPlatform = osPlatform
|
|
15
15
|
this.osArch = osArch
|
|
16
|
+
this.dotenvxProjectId = dotenvxProjectId
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
async run () {
|
|
@@ -26,6 +27,7 @@ class PostObserve {
|
|
|
26
27
|
const systemUuid = this.systemUuid
|
|
27
28
|
const osPlatform = this.osPlatform
|
|
28
29
|
const osArch = this.osArch
|
|
30
|
+
const dotenvxProjectId = this.dotenvxProjectId
|
|
29
31
|
|
|
30
32
|
const resp = await http(url, {
|
|
31
33
|
method: 'POST',
|
|
@@ -42,7 +44,8 @@ class PostObserve {
|
|
|
42
44
|
system_uuid: systemUuid,
|
|
43
45
|
os_platform: osPlatform,
|
|
44
46
|
os_arch: osArch,
|
|
45
|
-
cli_version: packageJson.version
|
|
47
|
+
cli_version: packageJson.version,
|
|
48
|
+
dotenvx_project_id: dotenvxProjectId
|
|
46
49
|
})
|
|
47
50
|
})
|
|
48
51
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
4
|
+
const Errors = require('./errors')
|
|
5
|
+
|
|
6
|
+
function dotenvxProjectId (cwd = process.cwd(), raiseErrors = true) {
|
|
7
|
+
// 1. Prefer environment variable
|
|
8
|
+
if (process.env.DOTENVX_PROJECT_ID && process.env.DOTENVX_PROJECT_ID.trim()) {
|
|
9
|
+
return process.env.DOTENVX_PROJECT_ID.trim()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 2. Otherwise, parse .env.x contents
|
|
13
|
+
const filepath = path.join(cwd, '.env.x')
|
|
14
|
+
// file must exist
|
|
15
|
+
if (!fs.existsSync(filepath)) {
|
|
16
|
+
const filename = path.basename(filepath)
|
|
17
|
+
if (raiseErrors) {
|
|
18
|
+
throw new Errors({ filename, filepath }).envXFileMissing()
|
|
19
|
+
} else {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (fs.existsSync(filepath)) {
|
|
25
|
+
const src = fs.readFileSync(filepath, 'utf8')
|
|
26
|
+
const parsed = dotenvx.parse(src)
|
|
27
|
+
if (parsed.DOTENVX_PROJECT_ID && parsed.DOTENVX_PROJECT_ID.trim()) {
|
|
28
|
+
return parsed.DOTENVX_PROJECT_ID.trim()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 3. Nothing found
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = dotenvxProjectId
|
package/src/lib/main.js
CHANGED
|
@@ -6,6 +6,7 @@ const PostObserve = require('./api/postObserve')
|
|
|
6
6
|
|
|
7
7
|
const gitUrl = require('./helpers/gitUrl')
|
|
8
8
|
const gitBranch = require('./helpers/gitBranch')
|
|
9
|
+
const dotenvxProjectId = require('./helpers/dotenvxProjectId')
|
|
9
10
|
|
|
10
11
|
const observe = async function (encoded, options = {}) {
|
|
11
12
|
const sesh = new Session() // TODO: handle scenario where constructor fails
|
|
@@ -21,6 +22,8 @@ const observe = async function (encoded, options = {}) {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const _pwd = process.cwd()
|
|
25
|
+
const _dotenvxProjectId = process.env.DOTENVX_PROJECT_ID || options.dotenvxProjectId || dotenvxProjectId(_pwd, false)
|
|
26
|
+
|
|
24
27
|
const _gitUrl = gitUrl()
|
|
25
28
|
const _gitBranch = gitBranch()
|
|
26
29
|
|
|
@@ -31,7 +34,7 @@ const observe = async function (encoded, options = {}) {
|
|
|
31
34
|
const _osPlatform = osInfo.platform
|
|
32
35
|
const _osArch = osInfo.arch
|
|
33
36
|
|
|
34
|
-
const json = await new PostObserve(hostname, token, encoded, _pwd, _gitUrl, _gitBranch, _systemUuid, _osPlatform, _osArch).run()
|
|
37
|
+
const json = await new PostObserve(hostname, token, encoded, _pwd, _gitUrl, _gitBranch, _systemUuid, _osPlatform, _osArch, _dotenvxProjectId).run()
|
|
35
38
|
|
|
36
39
|
return json
|
|
37
40
|
}
|
package/src/lib/services/sync.js
CHANGED
|
@@ -7,7 +7,7 @@ const Session = require('./../../db/session')
|
|
|
7
7
|
|
|
8
8
|
const gitUrl = require('./../helpers/gitUrl')
|
|
9
9
|
const gitBranch = require('./../helpers/gitBranch')
|
|
10
|
-
const
|
|
10
|
+
const dotenvxProjectId = require('./../helpers/dotenvxProjectId')
|
|
11
11
|
|
|
12
12
|
// api calls
|
|
13
13
|
const PostSync = require('./../api/postSync')
|
|
@@ -29,7 +29,7 @@ class Sync {
|
|
|
29
29
|
const files = this._files()
|
|
30
30
|
const payload = { files }
|
|
31
31
|
const encoded = Buffer.from(JSON.stringify(payload)).toString('base64')
|
|
32
|
-
const
|
|
32
|
+
const _dotenvxProjectId = dotenvxProjectId(this.cwd)
|
|
33
33
|
|
|
34
34
|
// optional
|
|
35
35
|
const _pwd = this.cwd
|
|
@@ -43,7 +43,7 @@ class Sync {
|
|
|
43
43
|
const _osPlatform = osInfo.platform
|
|
44
44
|
const _osArch = osInfo.arch
|
|
45
45
|
|
|
46
|
-
const data = await new PostSync(this.hostname, token, devicePublicKey, encoded,
|
|
46
|
+
const data = await new PostSync(this.hostname, token, devicePublicKey, encoded, _dotenvxProjectId, _pwd, _gitUrl, _gitBranch, _systemUuid, _osPlatform, _osArch, this.force).run()
|
|
47
47
|
|
|
48
48
|
return {
|
|
49
49
|
id: data.id,
|
|
@@ -53,32 +53,6 @@ class Sync {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
_dotenvxProjectId () {
|
|
57
|
-
// 1. Prefer environment variable
|
|
58
|
-
if (process.env.DOTENVX_PROJECT_ID && process.env.DOTENVX_PROJECT_ID.trim()) {
|
|
59
|
-
return process.env.DOTENVX_PROJECT_ID.trim()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// 2. Otherwise, parse .env.x contents
|
|
63
|
-
const filepath = path.join(this.cwd, '.env.x')
|
|
64
|
-
// file must exist
|
|
65
|
-
if (!fs.existsSync(filepath)) {
|
|
66
|
-
const filename = path.basename(filepath)
|
|
67
|
-
throw new Errors({ filename, filepath }).envXFileMissing()
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (fs.existsSync(filepath)) {
|
|
71
|
-
const src = fs.readFileSync(filepath, 'utf8')
|
|
72
|
-
const parsed = dotenvx.parse(src)
|
|
73
|
-
if (parsed.DOTENVX_PROJECT_ID && parsed.DOTENVX_PROJECT_ID.trim()) {
|
|
74
|
-
return parsed.DOTENVX_PROJECT_ID.trim()
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 3. Nothing found
|
|
79
|
-
return null
|
|
80
|
-
}
|
|
81
|
-
|
|
82
56
|
_files () {
|
|
83
57
|
const out = []
|
|
84
58
|
const filepaths = dotenvx.ls(this.cwd)
|