@dotenvx/dotenvx-ops 0.17.1 → 0.19.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.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx-ops/compare/v0.19.0...main)
|
|
6
|
+
|
|
7
|
+
## [0.19.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.18.0...v0.19.0) (2025-10-07)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Surface any conflicts during `sync` ([#3](https://github.com/dotenvx/dotenvx-ops/pull3))
|
|
12
|
+
|
|
13
|
+
## [0.18.0](https://github.com/dotenvx/dotenvx-ops/compare/v0.17.1...v0.18.0) (2025-10-06)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
* Display conflict diff ([#2](https://github.com/dotenvx/dotenvx-ops/pull/2))
|
|
6
18
|
|
|
7
19
|
## [0.17.1](https://github.com/dotenvx/dotenvx-ops/compare/v0.17.0...v0.17.1) (2025-10-01)
|
|
8
20
|
|
package/package.json
CHANGED
package/src/cli/actions/sync.js
CHANGED
|
@@ -5,8 +5,10 @@ const { logger } = require('@dotenvx/dotenvx')
|
|
|
5
5
|
|
|
6
6
|
const { createSpinner } = require('./../../lib/helpers/createSpinner')
|
|
7
7
|
const smartMask = require('./../../lib/helpers/smartMask')
|
|
8
|
+
const pluralize = require('./../../lib/helpers/pluralize')
|
|
8
9
|
|
|
9
10
|
const Sync = require('./../../lib/services/sync')
|
|
11
|
+
const SyncConflict = require('./../../lib/services/syncConflict')
|
|
10
12
|
|
|
11
13
|
const spinner = createSpinner('syncing')
|
|
12
14
|
|
|
@@ -16,9 +18,10 @@ function sha256File (filepath) {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
async function sync () {
|
|
21
|
+
// debug opts
|
|
22
|
+
const options = this.opts()
|
|
23
|
+
|
|
19
24
|
try {
|
|
20
|
-
// debug opts
|
|
21
|
-
const options = this.opts()
|
|
22
25
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
23
26
|
|
|
24
27
|
spinner.start()
|
|
@@ -64,6 +67,40 @@ async function sync () {
|
|
|
64
67
|
if (error.stack) {
|
|
65
68
|
logger.debug(error.stack)
|
|
66
69
|
}
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
if (error.code === 'DOTENVX_SYNC_CONFLICT') {
|
|
73
|
+
spinner.start()
|
|
74
|
+
|
|
75
|
+
const synchronizationId = error.meta.synchronization_id
|
|
76
|
+
const { conflictedFiles } = await new SyncConflict(options.hostname, synchronizationId).run()
|
|
77
|
+
|
|
78
|
+
spinner.stop()
|
|
79
|
+
|
|
80
|
+
// loop through any conflicted files
|
|
81
|
+
for (const conflictedFile of conflictedFiles) {
|
|
82
|
+
logger.info('')
|
|
83
|
+
logger.info(`✖ conflict [${conflictedFile.filepath}]`)
|
|
84
|
+
console.log(conflictedFile.diffAnsi)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
logger.info(`Review and edit the ${pluralize('file', conflictedFiles.length)} as needed, then confirm your version with [dotenvx-ops sync --force]`)
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
spinner.stop()
|
|
91
|
+
if (error.message) {
|
|
92
|
+
logger.error(error.message)
|
|
93
|
+
} else {
|
|
94
|
+
logger.error(error)
|
|
95
|
+
}
|
|
96
|
+
if (error.help) {
|
|
97
|
+
logger.help(error.help)
|
|
98
|
+
}
|
|
99
|
+
if (error.stack) {
|
|
100
|
+
logger.debug(error.stack)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
67
104
|
process.exit(1)
|
|
68
105
|
}
|
|
69
106
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { http } = require('../../lib/helpers/http')
|
|
2
|
+
const buildApiError = require('../../lib/helpers/buildApiError')
|
|
3
|
+
|
|
4
|
+
class GetSynchronization {
|
|
5
|
+
constructor (hostname, token, synchronizationId) {
|
|
6
|
+
this.hostname = hostname || 'https://ops.dotenvx.com'
|
|
7
|
+
this.token = token
|
|
8
|
+
this.synchronizationId = synchronizationId
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async run () {
|
|
12
|
+
const token = this.token
|
|
13
|
+
const synchronizationId = this.synchronizationId
|
|
14
|
+
const url = `${this.hostname}/api/synchronization/${synchronizationId}`
|
|
15
|
+
|
|
16
|
+
const resp = await http(url, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${token}`,
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const json = await resp.body.json()
|
|
25
|
+
|
|
26
|
+
if (resp.statusCode >= 400) {
|
|
27
|
+
throw buildApiError(resp.statusCode, json)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return json
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = GetSynchronization
|
|
@@ -2,10 +2,12 @@ function buildApiError (statusCode, json) {
|
|
|
2
2
|
const code = json.error.code || statusCode.toString()
|
|
3
3
|
const message = `[${code}] ${json.error.message}`
|
|
4
4
|
const help = `[${code}] ${json.error.help || JSON.stringify(json)}`
|
|
5
|
+
const meta = json.error.meta
|
|
5
6
|
|
|
6
7
|
const error = new Error(message)
|
|
7
8
|
error.code = code
|
|
8
9
|
error.help = help
|
|
10
|
+
error.meta = meta
|
|
9
11
|
|
|
10
12
|
return error
|
|
11
13
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const Session = require('./../../db/session')
|
|
2
|
+
|
|
3
|
+
// api calls
|
|
4
|
+
const GetSynchronization = require('./../api/getSynchronization')
|
|
5
|
+
|
|
6
|
+
class SyncConflict {
|
|
7
|
+
constructor (hostname, synchronizationId) {
|
|
8
|
+
this.hostname = hostname
|
|
9
|
+
this.synchronizationId = synchronizationId
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run () {
|
|
13
|
+
const sesh = new Session()
|
|
14
|
+
const token = sesh.token()
|
|
15
|
+
const synchronizationId = this.synchronizationId
|
|
16
|
+
|
|
17
|
+
const data = await new GetSynchronization(this.hostname, token, synchronizationId).run()
|
|
18
|
+
|
|
19
|
+
const conflictedFiles = []
|
|
20
|
+
for (const file of data.files) {
|
|
21
|
+
if (file.status === 'conflicted') {
|
|
22
|
+
conflictedFiles.push({
|
|
23
|
+
filepath: file.filepath,
|
|
24
|
+
diffAnsi: file.diff_ansi
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
id: data.id,
|
|
31
|
+
conflictedFiles
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = SyncConflict
|