@dotenvx/dotenvx-vlt 0.49.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +652 -0
  2. package/LICENSE +71 -0
  3. package/README.md +11 -0
  4. package/package.json +77 -0
  5. package/src/cli/actions/armor/down.js +37 -0
  6. package/src/cli/actions/armor/move.js +42 -0
  7. package/src/cli/actions/armor/pull.js +37 -0
  8. package/src/cli/actions/armor/push.js +37 -0
  9. package/src/cli/actions/armor/rotate.js +25 -0
  10. package/src/cli/actions/armor/up.js +37 -0
  11. package/src/cli/actions/backup.js +93 -0
  12. package/src/cli/actions/gateway/start.js +17 -0
  13. package/src/cli/actions/get.js +34 -0
  14. package/src/cli/actions/keypair.js +59 -0
  15. package/src/cli/actions/login.js +110 -0
  16. package/src/cli/actions/logout.js +36 -0
  17. package/src/cli/actions/observe.js +36 -0
  18. package/src/cli/actions/open.js +37 -0
  19. package/src/cli/actions/rotate/github/connect.js +84 -0
  20. package/src/cli/actions/rotate/npm/connect.js +84 -0
  21. package/src/cli/actions/rotate/openai/connect.js +84 -0
  22. package/src/cli/actions/rotate.js +44 -0
  23. package/src/cli/actions/set.js +34 -0
  24. package/src/cli/actions/settings/device.js +24 -0
  25. package/src/cli/actions/settings/hostname.js +20 -0
  26. package/src/cli/actions/settings/off.js +17 -0
  27. package/src/cli/actions/settings/on.js +17 -0
  28. package/src/cli/actions/settings/path.js +21 -0
  29. package/src/cli/actions/settings/token.js +24 -0
  30. package/src/cli/actions/settings/username.js +22 -0
  31. package/src/cli/actions/status.js +13 -0
  32. package/src/cli/actions/sync.js +104 -0
  33. package/src/cli/commands/armor.js +73 -0
  34. package/src/cli/commands/gateway.js +16 -0
  35. package/src/cli/commands/rotate/github.js +26 -0
  36. package/src/cli/commands/rotate/npm.js +26 -0
  37. package/src/cli/commands/rotate/openai.js +26 -0
  38. package/src/cli/commands/rotate.js +32 -0
  39. package/src/cli/commands/settings.js +60 -0
  40. package/src/cli/dotenvx-ops.js +163 -0
  41. package/src/cli/postinstall.js +16 -0
  42. package/src/db/device.js +73 -0
  43. package/src/db/session.js +193 -0
  44. package/src/lib/api/getAccount.js +32 -0
  45. package/src/lib/api/getSynchronization.js +34 -0
  46. package/src/lib/api/getVersion.js +24 -0
  47. package/src/lib/api/postArmorDown.js +48 -0
  48. package/src/lib/api/postArmorMove.js +48 -0
  49. package/src/lib/api/postArmorPull.js +48 -0
  50. package/src/lib/api/postArmorPush.js +48 -0
  51. package/src/lib/api/postArmorUp.js +51 -0
  52. package/src/lib/api/postBackup.js +68 -0
  53. package/src/lib/api/postGet.js +37 -0
  54. package/src/lib/api/postKeypair.js +60 -0
  55. package/src/lib/api/postLogout.js +34 -0
  56. package/src/lib/api/postOauthDeviceCode.js +45 -0
  57. package/src/lib/api/postOauthToken.js +38 -0
  58. package/src/lib/api/postObserve.js +62 -0
  59. package/src/lib/api/postRotate.js +39 -0
  60. package/src/lib/api/postRotateConnect.js +54 -0
  61. package/src/lib/api/postSet.js +43 -0
  62. package/src/lib/api/postSync.js +68 -0
  63. package/src/lib/helpers/armoredKeyDisplay.js +10 -0
  64. package/src/lib/helpers/buildApiError.js +16 -0
  65. package/src/lib/helpers/buildOauthError.js +13 -0
  66. package/src/lib/helpers/canonicalEnvFilename.js +13 -0
  67. package/src/lib/helpers/clipboardy/fallbacks/linux/xsel +0 -0
  68. package/src/lib/helpers/clipboardy/fallbacks/windows/clipboard_i686.exe +0 -0
  69. package/src/lib/helpers/clipboardy/fallbacks/windows/clipboard_x86_64.exe +0 -0
  70. package/src/lib/helpers/clipboardy/linux.js +57 -0
  71. package/src/lib/helpers/clipboardy/macos.js +14 -0
  72. package/src/lib/helpers/clipboardy/termux.js +41 -0
  73. package/src/lib/helpers/clipboardy/windows.js +16 -0
  74. package/src/lib/helpers/clipboardy.js +51 -0
  75. package/src/lib/helpers/confirm.js +17 -0
  76. package/src/lib/helpers/createSpinner.js +101 -0
  77. package/src/lib/helpers/createSpinner2.js +24 -0
  78. package/src/lib/helpers/decryptValue.js +10 -0
  79. package/src/lib/helpers/dotenvxProjectId.js +36 -0
  80. package/src/lib/helpers/encryptValue.js +9 -0
  81. package/src/lib/helpers/errors.js +30 -0
  82. package/src/lib/helpers/formatCode.js +11 -0
  83. package/src/lib/helpers/gitBranch.js +13 -0
  84. package/src/lib/helpers/gitUrl.js +13 -0
  85. package/src/lib/helpers/http.js +17 -0
  86. package/src/lib/helpers/jsonToEnv.js +7 -0
  87. package/src/lib/helpers/keyNamesForEnvFile.js +43 -0
  88. package/src/lib/helpers/keypairMetadata.js +88 -0
  89. package/src/lib/helpers/likelyUpdateCommand.js +33 -0
  90. package/src/lib/helpers/localKeypair.js +12 -0
  91. package/src/lib/helpers/mask.js +12 -0
  92. package/src/lib/helpers/normalizePath.js +5 -0
  93. package/src/lib/helpers/normalizeToken.js +5 -0
  94. package/src/lib/helpers/openUrl.js +7 -0
  95. package/src/lib/helpers/packageJson.js +3 -0
  96. package/src/lib/helpers/playwrightConnect.js +29 -0
  97. package/src/lib/helpers/pluralize.js +10 -0
  98. package/src/lib/helpers/prompts.js +68 -0
  99. package/src/lib/helpers/removeEnvKey.js +50 -0
  100. package/src/lib/helpers/safeRealpath.js +13 -0
  101. package/src/lib/helpers/sha256File.js +9 -0
  102. package/src/lib/helpers/smartMask.js +11 -0
  103. package/src/lib/helpers/truncate.js +10 -0
  104. package/src/lib/helpers/upsertEnvKey.js +61 -0
  105. package/src/lib/main.d.ts +152 -0
  106. package/src/lib/main.js +114 -0
  107. package/src/lib/services/armorDown.js +77 -0
  108. package/src/lib/services/armorMove.js +54 -0
  109. package/src/lib/services/armorPull.js +77 -0
  110. package/src/lib/services/armorPush.js +82 -0
  111. package/src/lib/services/armorUp.js +79 -0
  112. package/src/lib/services/backup.js +105 -0
  113. package/src/lib/services/gatewayStart.js +132 -0
  114. package/src/lib/services/keypair.js +59 -0
  115. package/src/lib/services/loggedIn.js +24 -0
  116. package/src/lib/services/login.js +28 -0
  117. package/src/lib/services/loginPoll.js +43 -0
  118. package/src/lib/services/logout.js +28 -0
  119. package/src/lib/services/rotate.js +28 -0
  120. package/src/lib/services/rotateGithubConnect.js +56 -0
  121. package/src/lib/services/rotateNpmConnect.js +56 -0
  122. package/src/lib/services/rotateOpenaiConnect.js +60 -0
  123. package/src/lib/services/status.js +11 -0
  124. package/src/lib/services/sync.js +70 -0
  125. package/src/lib/services/syncConflict.js +36 -0
@@ -0,0 +1,193 @@
1
+ const Conf = require('conf')
2
+ const dotenv = require('dotenv')
3
+ const si = require('systeminformation')
4
+ const semver = require('semver')
5
+ const { logger } = require('@dotenvx/dotenvx')
6
+
7
+ const Device = require('./device')
8
+ const jsonToEnv = require('./../lib/helpers/jsonToEnv')
9
+ const likelyUpdateCommand = require('./../lib/helpers/likelyUpdateCommand')
10
+ const packageJson = require('./../lib/helpers/packageJson')
11
+ const GetVersion = require('./../lib/api/getVersion')
12
+
13
+ const HOURS_24 = 60 * 60 * 24 * 1000 // 24hrs in ms
14
+
15
+ class Session {
16
+ constructor () {
17
+ this.store = new Conf({
18
+ cwd: process.env.DOTENVX_CONFIG || undefined,
19
+ projectName: 'dotenvx',
20
+ configName: '.env',
21
+ projectSuffix: '',
22
+ fileExtension: '',
23
+ serialize: function (json) {
24
+ return jsonToEnv(json)
25
+ },
26
+ // Convert .env format to an object
27
+ deserialize: function (env) {
28
+ return dotenv.parse(env)
29
+ }
30
+ })
31
+ }
32
+
33
+ status () {
34
+ // if logged in
35
+ if (this.username() && this.token() && this.on()) {
36
+ return 'on'
37
+ }
38
+
39
+ return 'off'
40
+ }
41
+
42
+ //
43
+ // Get
44
+ //
45
+ hostname () {
46
+ return this.store.get('DOTENVX_OPS_HOSTNAME') || 'https://ops.dotenvx.com'
47
+ }
48
+
49
+ username () {
50
+ return this.store.get('DOTENVX_OPS_USERNAME') || undefined
51
+ }
52
+
53
+ token () {
54
+ return this.store.get('DOTENVX_OPS_TOKEN') || undefined
55
+ }
56
+
57
+ devicePublicKey () {
58
+ return new Device().publicKey()
59
+ }
60
+
61
+ path () {
62
+ return this.store.path
63
+ }
64
+
65
+ on () {
66
+ return (this.store.get('DOTENVX_OPS_ON') || 'true') === 'true'
67
+ }
68
+
69
+ off () {
70
+ return (this.store.get('DOTENVX_OPS_ON') || 'true') === 'false'
71
+ }
72
+
73
+ async systemInformation () {
74
+ const system = await si.system()
75
+ const osInfo = await si.osInfo()
76
+
77
+ return {
78
+ system_uuid: system.uuid,
79
+ os_platform: osInfo.platform,
80
+ os_arch: osInfo.arch
81
+ }
82
+ }
83
+
84
+ //
85
+ // Notify Update
86
+ //
87
+ async notifyUpdate () {
88
+ try {
89
+ logger.debug('checking if update available')
90
+
91
+ const lastCheck = Number(this.store.get('DOTENVX_OPS_VERSION_LAST_CHECK') || 0)
92
+ const now = Date.now()
93
+
94
+ // 24 hours have passed
95
+ if ((lastCheck + HOURS_24) < now) {
96
+ const local = packageJson.version
97
+ let remote = local // in case of http fetch error
98
+
99
+ try {
100
+ logger.debug('fetching latest available version')
101
+ const VERSION = await new GetVersion().run()
102
+ logger.debug(`latest version: ${VERSION}`)
103
+
104
+ remote = VERSION
105
+ this.store.set('DOTENVX_OPS_VERSION', VERSION) // remote version
106
+ } catch (err) {
107
+ // noop
108
+ logger.debug(err.message)
109
+ }
110
+
111
+ this.store.set('DOTENVX_OPS_VERSION_LAST_CHECK', now) // record check
112
+
113
+ if (semver.gt(remote, local)) {
114
+ const diff = semver.diff(local, remote)
115
+ console.error(`⛆ update available (${diff}) [${likelyUpdateCommand()}]`)
116
+ }
117
+ }
118
+ } catch (err) {
119
+ // noop
120
+ logger.debug(err.message)
121
+ }
122
+ }
123
+
124
+ //
125
+ // Set/Delete
126
+ //
127
+ login (hostname, id, username, accessToken) {
128
+ if (!hostname) {
129
+ throw new Error('DOTENVX_OPS_HOSTNAME not set. Run [dotenvx-ops login]')
130
+ }
131
+
132
+ if (!id) {
133
+ throw new Error('DOTENVX_OPS_USER not set. Run [dotenvx-ops login]')
134
+ }
135
+
136
+ if (!username) {
137
+ throw new Error('DOTENVX_OPS_USERNAME not set. Run [dotenvx-ops login]')
138
+ }
139
+
140
+ if (!accessToken) {
141
+ throw new Error('DOTENVX_OPS_TOKEN not set. Run [dotenvx-ops login]')
142
+ }
143
+
144
+ this.store.set('DOTENVX_OPS_USER', id)
145
+ this.store.set('DOTENVX_OPS_USERNAME', username)
146
+ this.store.set('DOTENVX_OPS_TOKEN', accessToken)
147
+ this.store.set('DOTENVX_OPS_HOSTNAME', hostname)
148
+ this.store.set('DOTENVX_OPS_ON', 'true')
149
+
150
+ return accessToken
151
+ }
152
+
153
+ logout (hostname, id, accessToken) {
154
+ if (!hostname) {
155
+ throw new Error('DOTENVX_OPS_HOSTNAME not set. Run [dotenvx-ops login]')
156
+ }
157
+
158
+ if (!id) {
159
+ throw new Error('DOTENVX_OPS_USER not set. Run [dotenvx-ops login]')
160
+ }
161
+
162
+ if (!accessToken) {
163
+ throw new Error('DOTENVX_OPS_TOKEN not set. Run [dotenvx-ops login]')
164
+ }
165
+
166
+ this.store.delete('DOTENVX_OPS_USER')
167
+ this.store.delete('DOTENVX_OPS_USERNAME')
168
+ this.store.delete('DOTENVX_OPS_TOKEN')
169
+ this.store.delete('DOTENVX_OPS_HOSTNAME')
170
+ this.store.delete('DOTENVX_OPS_ON')
171
+ this.store.delete('DOTENVX_OPS_VERSION')
172
+ this.store.delete('DOTENVX_OPS_VERSION_LAST_CHECK')
173
+ return true
174
+ }
175
+
176
+ //
177
+ // on
178
+ //
179
+ turnOn () {
180
+ this.store.set('DOTENVX_OPS_ON', 'true')
181
+ return 'true'
182
+ }
183
+
184
+ //
185
+ // off
186
+ //
187
+ turnOff () {
188
+ this.store.set('DOTENVX_OPS_ON', 'false')
189
+ return 'false'
190
+ }
191
+ }
192
+
193
+ module.exports = Session
@@ -0,0 +1,32 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+
4
+ class GetAccount {
5
+ constructor (hostname, token) {
6
+ this.hostname = hostname || 'https://ops.dotenvx.com'
7
+ this.token = token
8
+ }
9
+
10
+ async run () {
11
+ const token = this.token
12
+ const url = `${this.hostname}/api/account`
13
+
14
+ const resp = await http(url, {
15
+ method: 'GET',
16
+ headers: {
17
+ Authorization: `Bearer ${token}`,
18
+ 'Content-Type': 'application/json'
19
+ }
20
+ })
21
+
22
+ const json = await resp.body.json()
23
+
24
+ if (resp.statusCode >= 400) {
25
+ throw buildApiError(resp.statusCode, json)
26
+ }
27
+
28
+ return json
29
+ }
30
+ }
31
+
32
+ module.exports = GetAccount
@@ -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
@@ -0,0 +1,24 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+
3
+ class GetVersion {
4
+ constructor () {
5
+ this.hostname = 'https://dotenvx.sh'
6
+ }
7
+
8
+ async run () {
9
+ const url = `${this.hostname}/ops/VERSION`
10
+
11
+ const resp = await http(url, { method: 'GET' })
12
+ const VERSION = await resp.body.text()
13
+
14
+ if (resp.statusCode >= 400) {
15
+ const error = new Error('[VERSION_FETCH_FAILED] version fetch failed')
16
+ error.code = 'VERSION_FETCH_FAILED'
17
+ throw error
18
+ }
19
+
20
+ return VERSION
21
+ }
22
+ }
23
+
24
+ module.exports = GetVersion
@@ -0,0 +1,48 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+ const packageJson = require('../../lib/helpers/packageJson')
4
+ const normalizeToken = require('../../lib/helpers/normalizeToken')
5
+
6
+ class PostArmorDown {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team) {
8
+ this.hostname = hostname || 'https://ops.dotenvx.com'
9
+ this.token = token
10
+ this.devicePublicKey = devicePublicKey
11
+ this.publicKey = publicKey
12
+ this.team = team
13
+ }
14
+
15
+ async run () {
16
+ const token = normalizeToken(this.token)
17
+ const devicePublicKey = this.devicePublicKey
18
+ const publicKey = this.publicKey
19
+ const team = this.team
20
+ const url = `${this.hostname}/api/armor/down`
21
+
22
+ const body = {
23
+ device_public_key: devicePublicKey,
24
+ cli_version: packageJson.version,
25
+ public_key: publicKey,
26
+ team
27
+ }
28
+
29
+ const resp = await http(url, {
30
+ method: 'POST',
31
+ headers: {
32
+ Authorization: `Bearer ${token}`,
33
+ 'Content-Type': 'application/json'
34
+ },
35
+ body: JSON.stringify(body)
36
+ })
37
+
38
+ const json = await resp.body.json()
39
+
40
+ if (resp.statusCode >= 400) {
41
+ throw buildApiError(resp.statusCode, json)
42
+ }
43
+
44
+ return json
45
+ }
46
+ }
47
+
48
+ module.exports = PostArmorDown
@@ -0,0 +1,48 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+ const packageJson = require('../../lib/helpers/packageJson')
4
+ const normalizeToken = require('../../lib/helpers/normalizeToken')
5
+
6
+ class PostArmorMove {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team) {
8
+ this.hostname = hostname || 'https://ops.dotenvx.com'
9
+ this.token = token
10
+ this.devicePublicKey = devicePublicKey
11
+ this.publicKey = publicKey
12
+ this.team = team
13
+ }
14
+
15
+ async run () {
16
+ const token = normalizeToken(this.token)
17
+ const devicePublicKey = this.devicePublicKey
18
+ const publicKey = this.publicKey
19
+ const team = this.team
20
+ const url = `${this.hostname}/api/armor/move`
21
+
22
+ const body = {
23
+ device_public_key: devicePublicKey,
24
+ cli_version: packageJson.version,
25
+ public_key: publicKey,
26
+ team
27
+ }
28
+
29
+ const resp = await http(url, {
30
+ method: 'POST',
31
+ headers: {
32
+ Authorization: `Bearer ${token}`,
33
+ 'Content-Type': 'application/json'
34
+ },
35
+ body: JSON.stringify(body)
36
+ })
37
+
38
+ const json = await resp.body.json()
39
+
40
+ if (resp.statusCode >= 400) {
41
+ throw buildApiError(resp.statusCode, json)
42
+ }
43
+
44
+ return json
45
+ }
46
+ }
47
+
48
+ module.exports = PostArmorMove
@@ -0,0 +1,48 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+ const packageJson = require('../../lib/helpers/packageJson')
4
+ const normalizeToken = require('../../lib/helpers/normalizeToken')
5
+
6
+ class PostArmorPull {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team) {
8
+ this.hostname = hostname || 'https://ops.dotenvx.com'
9
+ this.token = token
10
+ this.devicePublicKey = devicePublicKey
11
+ this.publicKey = publicKey
12
+ this.team = team
13
+ }
14
+
15
+ async run () {
16
+ const token = normalizeToken(this.token)
17
+ const devicePublicKey = this.devicePublicKey
18
+ const publicKey = this.publicKey
19
+ const team = this.team
20
+ const url = `${this.hostname}/api/armor/pull`
21
+
22
+ const body = {
23
+ device_public_key: devicePublicKey,
24
+ cli_version: packageJson.version,
25
+ public_key: publicKey,
26
+ team
27
+ }
28
+
29
+ const resp = await http(url, {
30
+ method: 'POST',
31
+ headers: {
32
+ Authorization: `Bearer ${token}`,
33
+ 'Content-Type': 'application/json'
34
+ },
35
+ body: JSON.stringify(body)
36
+ })
37
+
38
+ const json = await resp.body.json()
39
+
40
+ if (resp.statusCode >= 400) {
41
+ throw buildApiError(resp.statusCode, json)
42
+ }
43
+
44
+ return json
45
+ }
46
+ }
47
+
48
+ module.exports = PostArmorPull
@@ -0,0 +1,48 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+ const packageJson = require('../../lib/helpers/packageJson')
4
+ const normalizeToken = require('../../lib/helpers/normalizeToken')
5
+
6
+ class PostArmorPush {
7
+ constructor (hostname, token, devicePublicKey, privateKey, team) {
8
+ this.hostname = hostname || 'https://ops.dotenvx.com'
9
+ this.token = token
10
+ this.devicePublicKey = devicePublicKey
11
+ this.privateKey = privateKey
12
+ this.team = team
13
+ }
14
+
15
+ async run () {
16
+ const token = normalizeToken(this.token)
17
+ const devicePublicKey = this.devicePublicKey
18
+ const privateKey = this.privateKey
19
+ const team = this.team
20
+ const url = `${this.hostname}/api/armor/push`
21
+
22
+ const body = {
23
+ device_public_key: devicePublicKey,
24
+ cli_version: packageJson.version,
25
+ private_key: privateKey,
26
+ team
27
+ }
28
+
29
+ const resp = await http(url, {
30
+ method: 'POST',
31
+ headers: {
32
+ Authorization: `Bearer ${token}`,
33
+ 'Content-Type': 'application/json'
34
+ },
35
+ body: JSON.stringify(body)
36
+ })
37
+
38
+ const json = await resp.body.json()
39
+
40
+ if (resp.statusCode >= 400) {
41
+ throw buildApiError(resp.statusCode, json)
42
+ }
43
+
44
+ return json
45
+ }
46
+ }
47
+
48
+ module.exports = PostArmorPush
@@ -0,0 +1,51 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+ const packageJson = require('../../lib/helpers/packageJson')
4
+ const normalizeToken = require('../../lib/helpers/normalizeToken')
5
+
6
+ class PostArmorUp {
7
+ constructor (hostname, token, devicePublicKey, publicKey, privateKey, team) {
8
+ this.hostname = hostname || 'https://ops.dotenvx.com'
9
+ this.token = token
10
+ this.devicePublicKey = devicePublicKey
11
+ this.publicKey = publicKey
12
+ this.privateKey = privateKey
13
+ this.team = team
14
+ }
15
+
16
+ async run () {
17
+ const token = normalizeToken(this.token)
18
+ const devicePublicKey = this.devicePublicKey
19
+ const publicKey = this.publicKey
20
+ const privateKey = this.privateKey
21
+ const team = this.team
22
+ const url = `${this.hostname}/api/armor/up`
23
+
24
+ const body = {
25
+ device_public_key: devicePublicKey,
26
+ cli_version: packageJson.version,
27
+ public_key: publicKey,
28
+ private_key: privateKey,
29
+ team
30
+ }
31
+
32
+ const resp = await http(url, {
33
+ method: 'POST',
34
+ headers: {
35
+ Authorization: `Bearer ${token}`,
36
+ 'Content-Type': 'application/json'
37
+ },
38
+ body: JSON.stringify(body)
39
+ })
40
+
41
+ const json = await resp.body.json()
42
+
43
+ if (resp.statusCode >= 400) {
44
+ throw buildApiError(resp.statusCode, json)
45
+ }
46
+
47
+ return json
48
+ }
49
+ }
50
+
51
+ module.exports = PostArmorUp
@@ -0,0 +1,68 @@
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 = null, org = null, 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.org = org
13
+ this.pwd = pwd
14
+ this.gitUrl = gitUrl
15
+ this.gitBranch = gitBranch
16
+ this.systemUuid = systemUuid
17
+ this.osPlatform = osPlatform
18
+ this.osArch = osArch
19
+ }
20
+
21
+ async run () {
22
+ const token = this.token
23
+ const devicePublicKey = this.devicePublicKey
24
+ const url = `${this.hostname}/api/backup`
25
+ const encoded = this.encoded
26
+ const dotenvxProjectId = this.dotenvxProjectId
27
+ const org = this.org
28
+ const backedupAt = new Date().toISOString()
29
+ const pwd = this.pwd
30
+ const gitUrl = this.gitUrl
31
+ const gitBranch = this.gitBranch
32
+ const systemUuid = this.systemUuid
33
+ const osPlatform = this.osPlatform
34
+ const osArch = this.osArch
35
+
36
+ const resp = await http(url, {
37
+ method: 'POST',
38
+ headers: {
39
+ Authorization: `Bearer ${token}`,
40
+ 'Content-Type': 'application/json'
41
+ },
42
+ body: JSON.stringify({
43
+ device_public_key: devicePublicKey,
44
+ encoded,
45
+ dotenvx_project_id: dotenvxProjectId,
46
+ org,
47
+ backedup_at: backedupAt,
48
+ pwd,
49
+ git_url: gitUrl,
50
+ git_branch: gitBranch,
51
+ system_uuid: systemUuid,
52
+ os_platform: osPlatform,
53
+ os_arch: osArch,
54
+ cli_version: packageJson.version
55
+ })
56
+ })
57
+
58
+ const json = await resp.body.json()
59
+
60
+ if (resp.statusCode >= 400) {
61
+ throw buildApiError(resp.statusCode, json)
62
+ }
63
+
64
+ return json
65
+ }
66
+ }
67
+
68
+ module.exports = PostBackup
@@ -0,0 +1,37 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+
4
+ class PostGet {
5
+ constructor (hostname, token, uri) {
6
+ this.hostname = hostname || 'https://ops.dotenvx.com'
7
+ this.token = token
8
+ this.uri = uri
9
+ }
10
+
11
+ async run () {
12
+ const token = this.token
13
+ const uri = this.uri
14
+ const url = `${this.hostname}/api/get`
15
+
16
+ const resp = await http(url, {
17
+ method: 'POST',
18
+ headers: {
19
+ Authorization: `Bearer ${token}`,
20
+ 'Content-Type': 'application/json'
21
+ },
22
+ body: JSON.stringify({
23
+ uri
24
+ })
25
+ })
26
+
27
+ if (resp.statusCode >= 400) {
28
+ const json = await resp.body.json()
29
+ throw buildApiError(resp.statusCode, json)
30
+ }
31
+
32
+ const text = await resp.body.text()
33
+ return text
34
+ }
35
+ }
36
+
37
+ module.exports = PostGet
@@ -0,0 +1,60 @@
1
+ const { http } = require('../../lib/helpers/http')
2
+ const buildApiError = require('../../lib/helpers/buildApiError')
3
+ const packageJson = require('../../lib/helpers/packageJson')
4
+ const normalizeToken = require('../../lib/helpers/normalizeToken')
5
+
6
+ class PostKeypair {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team, metadata) {
8
+ this.hostname = hostname || 'https://ops.dotenvx.com'
9
+ this.token = token
10
+ this.devicePublicKey = devicePublicKey
11
+ this.publicKey = publicKey
12
+ this.team = team
13
+ this.metadata = metadata
14
+ }
15
+
16
+ async run () {
17
+ const token = normalizeToken(this.token)
18
+ const devicePublicKey = this.devicePublicKey
19
+ const publicKey = this.publicKey
20
+ const team = this.team
21
+ const metadata = this.metadata
22
+ const url = `${this.hostname}/api/keypair`
23
+
24
+ const body = {
25
+ device_public_key: devicePublicKey,
26
+ cli_version: packageJson.version
27
+ }
28
+
29
+ if (publicKey) {
30
+ body.public_key = publicKey
31
+ }
32
+
33
+ if (team) {
34
+ body.team = team
35
+ }
36
+
37
+ if (metadata && Object.keys(metadata).length > 0) {
38
+ body.metadata = metadata
39
+ }
40
+
41
+ const resp = await http(url, {
42
+ method: 'POST',
43
+ headers: {
44
+ Authorization: `Bearer ${token}`,
45
+ 'Content-Type': 'application/json'
46
+ },
47
+ body: JSON.stringify(body)
48
+ })
49
+
50
+ const json = await resp.body.json()
51
+
52
+ if (resp.statusCode >= 400) {
53
+ throw buildApiError(resp.statusCode, json)
54
+ }
55
+
56
+ return json
57
+ }
58
+ }
59
+
60
+ module.exports = PostKeypair