@dotenvx/dotenvx 1.71.3 → 1.73.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 (72) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +3 -3
  3. package/package.json +8 -4
  4. package/src/cli/actions/armor/down.js +37 -0
  5. package/src/cli/actions/armor/move.js +42 -0
  6. package/src/cli/actions/armor/pull.js +37 -0
  7. package/src/cli/actions/armor/push.js +37 -0
  8. package/src/cli/actions/armor/up.js +37 -0
  9. package/src/cli/actions/decrypt.js +1 -1
  10. package/src/cli/actions/encrypt.js +1 -1
  11. package/src/cli/actions/login.js +63 -0
  12. package/src/cli/actions/logout.js +36 -0
  13. package/src/cli/actions/normalizeArmorOptions.js +1 -2
  14. package/src/cli/actions/set.js +1 -1
  15. package/src/cli/commands/armor.js +72 -0
  16. package/src/cli/dotenvx.js +17 -19
  17. package/src/db/device.js +73 -0
  18. package/src/db/session.js +187 -4
  19. package/src/lib/api/getAccount.js +32 -0
  20. package/src/lib/api/postArmorDown.js +48 -0
  21. package/src/lib/api/postArmorMove.js +48 -0
  22. package/src/lib/api/postArmorPull.js +48 -0
  23. package/src/lib/api/postArmorPush.js +48 -0
  24. package/src/lib/api/postArmorUp.js +51 -0
  25. package/src/lib/api/postKeypair.js +60 -0
  26. package/src/lib/api/postLogout.js +34 -0
  27. package/src/lib/api/postOauthDeviceCode.js +38 -0
  28. package/src/lib/api/postOauthToken.js +35 -0
  29. package/src/lib/helpers/armoredKeyDisplay.js +10 -0
  30. package/src/lib/helpers/buildApiError.js +16 -0
  31. package/src/lib/helpers/buildOauthError.js +14 -0
  32. package/src/lib/helpers/createSpinner.js +1 -1
  33. package/src/lib/helpers/cryptography/armorKeypair.js +32 -11
  34. package/src/lib/helpers/cryptography/armorKeypairSync.js +48 -7
  35. package/src/lib/helpers/cryptography/provision.js +2 -2
  36. package/src/lib/helpers/cryptography/provisionSync.js +2 -2
  37. package/src/lib/helpers/decryptDeviceValue.js +10 -0
  38. package/src/lib/helpers/encryptDeviceValue.js +9 -0
  39. package/src/lib/helpers/formatCode.js +11 -0
  40. package/src/lib/helpers/http.js +7 -0
  41. package/src/lib/helpers/jsonToEnv.js +7 -0
  42. package/src/lib/helpers/keyResolution/index.js +1 -1
  43. package/src/lib/helpers/keyResolution/{keyNames.js → keyNamesForEnvFile.js} +2 -2
  44. package/src/lib/helpers/keyResolution/keyValues.js +2 -2
  45. package/src/lib/helpers/keyResolution/keyValuesSync.js +2 -2
  46. package/src/lib/helpers/keypairMetadata.js +77 -0
  47. package/src/lib/helpers/listenForOpenKey.js +46 -0
  48. package/src/lib/helpers/normalizeToken.js +5 -0
  49. package/src/lib/helpers/openUrl.js +7 -0
  50. package/src/lib/helpers/readEnvKey.js +31 -0
  51. package/src/lib/helpers/removeEnvKey.js +50 -0
  52. package/src/lib/helpers/sanitizeCommandForMetadata.js +64 -0
  53. package/src/lib/helpers/teamChoicesFromMeta.js +8 -0
  54. package/src/lib/helpers/upsertEnvKey.js +61 -0
  55. package/src/lib/main.d.ts +0 -24
  56. package/src/lib/main.js +1 -1
  57. package/src/lib/services/armorDown.js +71 -0
  58. package/src/lib/services/armorKeypair.js +156 -0
  59. package/src/lib/services/armorMove.js +54 -0
  60. package/src/lib/services/armorPull.js +71 -0
  61. package/src/lib/services/armorPush.js +76 -0
  62. package/src/lib/services/armorUp.js +73 -0
  63. package/src/lib/services/decrypt.js +2 -2
  64. package/src/lib/services/encrypt.js +2 -2
  65. package/src/lib/services/keypair.js +5 -7
  66. package/src/lib/services/login.js +26 -0
  67. package/src/lib/services/loginPoll.js +35 -0
  68. package/src/lib/services/logout.js +26 -0
  69. package/src/lib/services/rotate.js +2 -2
  70. package/src/lib/services/run.js +3 -3
  71. package/src/lib/services/sets.js +3 -3
  72. package/src/lib/extensions/armor.js +0 -204
@@ -0,0 +1,73 @@
1
+ const Conf = require('conf')
2
+ const { PrivateKey } = require('eciesjs')
3
+
4
+ const encryptDeviceValue = require('./../lib/helpers/encryptDeviceValue')
5
+ const decryptDeviceValue = require('./../lib/helpers/decryptDeviceValue')
6
+
7
+ class Device {
8
+ constructor () {
9
+ this.store = new Conf({
10
+ cwd: process.env.DOTENVX_CONFIG || undefined,
11
+ projectName: 'dotenvx',
12
+ configName: '.device-key',
13
+ projectSuffix: '',
14
+ fileExtension: '',
15
+ encryptionKey: 'dotenvxpro dotenvxpro dotenvxpro' // backwards compatible
16
+ })
17
+ }
18
+
19
+ touch () {
20
+ const _privateKey = this.privateKey()
21
+ const _publicKey = this.publicKey()
22
+
23
+ return {
24
+ privateKey: _privateKey,
25
+ publicKey: _publicKey
26
+ }
27
+ }
28
+
29
+ configPath () {
30
+ return this.store.path
31
+ }
32
+
33
+ privateKey () {
34
+ const currentPrivateKey = this.store.get('private_key/1')
35
+ if (currentPrivateKey && currentPrivateKey.length > 0) {
36
+ this.store.set('private_key/1', currentPrivateKey)
37
+
38
+ return currentPrivateKey
39
+ }
40
+
41
+ // generate privateKey for the first time
42
+ const kp = new PrivateKey()
43
+ const _privateKey = kp.secret.toString('hex')
44
+
45
+ this.store.set('private_key/1', _privateKey)
46
+
47
+ return _privateKey
48
+ }
49
+
50
+ publicKey () {
51
+ // must have private key to try and get public key
52
+ const privateKeyHex = this.privateKey()
53
+ if (!privateKeyHex || privateKeyHex.length < 1) {
54
+ return ''
55
+ }
56
+
57
+ // create keyPair object from hex string
58
+ const _privateKey = new PrivateKey(Buffer.from(privateKeyHex, 'hex'))
59
+
60
+ // compute publicKey from privateKey
61
+ return _privateKey.publicKey.toHex()
62
+ }
63
+
64
+ encrypt (value) {
65
+ return encryptDeviceValue(value, this.publicKey())
66
+ }
67
+
68
+ decrypt (value) {
69
+ return decryptDeviceValue(value, this.privateKey())
70
+ }
71
+ }
72
+
73
+ module.exports = Device
package/src/db/session.js CHANGED
@@ -1,25 +1,208 @@
1
- const Armor = require('./../lib/extensions/armor')
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const Conf = require('conf')
4
+ const dotenv = require('dotenv')
5
+ const envPaths = require('env-paths')
6
+
7
+ const jsonToEnv = require('./../lib/helpers/jsonToEnv')
2
8
  const { logger } = require('./../shared/logger')
3
9
 
10
+ const ARMOR = {
11
+ HOSTNAME: 'DOTENVX_ARMOR_HOSTNAME',
12
+ USER: 'DOTENVX_ARMOR_USER',
13
+ USERNAME: 'DOTENVX_ARMOR_USERNAME',
14
+ TOKEN: 'DOTENVX_ARMOR_TOKEN',
15
+ VERSION: 'DOTENVX_ARMOR_VERSION',
16
+ VERSION_LAST_CHECK: 'DOTENVX_ARMOR_VERSION_LAST_CHECK'
17
+ }
18
+
4
19
  class Session {
5
20
  constructor () {
6
- this.armor = new Armor()
21
+ this._store = null
22
+ }
23
+
24
+ _configPath () {
25
+ const cwd = process.env.DOTENVX_CONFIG || this._defaultConfigCwd()
26
+ return path.resolve(cwd, '.env')
27
+ }
28
+
29
+ _defaultConfigCwd () {
30
+ return envPaths('dotenvx', { suffix: '' }).config
31
+ }
32
+
33
+ _configExists () {
34
+ return fs.existsSync(this._configPath())
35
+ }
36
+
37
+ _newStore () {
38
+ return new Conf({
39
+ cwd: process.env.DOTENVX_CONFIG || undefined,
40
+ projectName: 'dotenvx',
41
+ configName: '.env',
42
+ projectSuffix: '',
43
+ fileExtension: '',
44
+ serialize: function (json) {
45
+ return jsonToEnv(json)
46
+ },
47
+ // Convert .env format to an object
48
+ deserialize: function (env) {
49
+ return dotenv.parse(env)
50
+ }
51
+ })
52
+ }
53
+
54
+ createStore () {
55
+ if (!this._store) this._store = this._newStore()
56
+ return this._store
57
+ }
58
+
59
+ openStore () {
60
+ if (!this._store && !this._configExists()) {
61
+ return null
62
+ }
63
+
64
+ if (!this._store) this._store = this._newStore()
65
+ return this._store
66
+ }
67
+
68
+ get store () {
69
+ return this.openStore()
70
+ }
71
+
72
+ status () {
73
+ // if logged in
74
+ if (this.username() && this.token()) {
75
+ return 'on'
76
+ }
77
+
78
+ return 'off'
79
+ }
80
+
81
+ //
82
+ // Get
83
+ //
84
+ readSetting (key) {
85
+ const store = this.openStore()
86
+ if (!store) return undefined
87
+
88
+ return store.get(ARMOR[key])
89
+ }
90
+
91
+ hostname () {
92
+ return this.readSetting('HOSTNAME') || 'https://armor.dotenvx.com'
93
+ }
94
+
95
+ username () {
96
+ return this.readSetting('USERNAME') || undefined
97
+ }
98
+
99
+ token () {
100
+ return this.readSetting('TOKEN') || undefined
101
+ }
102
+
103
+ devicePublicKey () {
104
+ const Device = require('./device')
105
+ return new Device().publicKey()
106
+ }
107
+
108
+ path () {
109
+ return this._store ? this._store.path : this._configPath()
110
+ }
111
+
112
+ async systemInformation () {
113
+ const si = require('systeminformation')
114
+ const system = await si.system()
115
+ const osInfo = await si.osInfo()
116
+
117
+ return {
118
+ system_uuid: system.uuid,
119
+ os_platform: osInfo.platform,
120
+ os_arch: osInfo.arch
121
+ }
122
+ }
123
+
124
+ async notifyUpdate () {
125
+ // native login keeps this lightweight; sidecar commands still handle full update messaging
7
126
  }
8
127
 
9
128
  //
10
129
  // armor status helpers
11
130
  //
12
131
  async noArmor () {
13
- const status = await this.armor.status()
132
+ if (process.env.DOTENVX_NO_ARMOR === 'true') {
133
+ logger.debug('armor: off')
134
+ return true
135
+ }
136
+
137
+ const status = this.status()
14
138
  logger.debug(`armor: ${status}`)
15
139
  return status === 'off'
16
140
  }
17
141
 
18
142
  noArmorSync () {
19
- const status = this.armor.statusSync()
143
+ if (process.env.DOTENVX_NO_ARMOR === 'true') {
144
+ logger.debug('armor: off')
145
+ return true
146
+ }
147
+
148
+ const status = this.status()
20
149
  logger.debug(`armor: ${status}`)
21
150
  return status === 'off'
22
151
  }
152
+
153
+ //
154
+ // Set/Delete
155
+ //
156
+ login (hostname, id, username, accessToken) {
157
+ if (!hostname) {
158
+ throw new Error('DOTENVX_ARMOR_HOSTNAME not set. Run [dotenvx login]')
159
+ }
160
+
161
+ if (!id) {
162
+ throw new Error('DOTENVX_ARMOR_USER not set. Run [dotenvx login]')
163
+ }
164
+
165
+ if (!username) {
166
+ throw new Error('DOTENVX_ARMOR_USERNAME not set. Run [dotenvx login]')
167
+ }
168
+
169
+ if (!accessToken) {
170
+ throw new Error('DOTENVX_ARMOR_TOKEN not set. Run [dotenvx login]')
171
+ }
172
+
173
+ const store = this.createStore()
174
+ store.set(ARMOR.USER, id)
175
+ store.set(ARMOR.USERNAME, username)
176
+ store.set(ARMOR.TOKEN, accessToken)
177
+ store.set(ARMOR.HOSTNAME, hostname)
178
+
179
+ return accessToken
180
+ }
181
+
182
+ logout (hostname, id, accessToken) {
183
+ if (!hostname) {
184
+ throw new Error('DOTENVX_ARMOR_HOSTNAME not set. Run [dotenvx login]')
185
+ }
186
+
187
+ if (!id) {
188
+ throw new Error('DOTENVX_ARMOR_USER not set. Run [dotenvx login]')
189
+ }
190
+
191
+ if (!accessToken) {
192
+ throw new Error('DOTENVX_ARMOR_TOKEN not set. Run [dotenvx login]')
193
+ }
194
+
195
+ const store = this.openStore()
196
+ if (!store) return true
197
+
198
+ store.delete(ARMOR.USER)
199
+ store.delete(ARMOR.USERNAME)
200
+ store.delete(ARMOR.TOKEN)
201
+ store.delete(ARMOR.HOSTNAME)
202
+ store.delete(ARMOR.VERSION)
203
+ store.delete(ARMOR.VERSION_LAST_CHECK)
204
+ return true
205
+ }
23
206
  }
24
207
 
25
208
  module.exports = Session
@@ -0,0 +1,32 @@
1
+ const { http } = require('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+
4
+ class GetAccount {
5
+ constructor (hostname, token) {
6
+ this.hostname = hostname
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,48 @@
1
+ const { http } = require('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+ const packageJson = require('../helpers/packageJson')
4
+ const normalizeToken = require('../helpers/normalizeToken')
5
+
6
+ class PostArmorDown {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team) {
8
+ this.hostname = hostname
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('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+ const packageJson = require('../helpers/packageJson')
4
+ const normalizeToken = require('../helpers/normalizeToken')
5
+
6
+ class PostArmorMove {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team) {
8
+ this.hostname = hostname
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('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+ const packageJson = require('../helpers/packageJson')
4
+ const normalizeToken = require('../helpers/normalizeToken')
5
+
6
+ class PostArmorPull {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team) {
8
+ this.hostname = hostname
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('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+ const packageJson = require('../helpers/packageJson')
4
+ const normalizeToken = require('../helpers/normalizeToken')
5
+
6
+ class PostArmorPush {
7
+ constructor (hostname, token, devicePublicKey, privateKey, team) {
8
+ this.hostname = hostname
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('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+ const packageJson = require('../helpers/packageJson')
4
+ const normalizeToken = require('../helpers/normalizeToken')
5
+
6
+ class PostArmorUp {
7
+ constructor (hostname, token, devicePublicKey, publicKey, privateKey, team) {
8
+ this.hostname = hostname
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,60 @@
1
+ const { http } = require('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+ const packageJson = require('../helpers/packageJson')
4
+ const normalizeToken = require('../helpers/normalizeToken')
5
+
6
+ class PostKeypair {
7
+ constructor (hostname, token, devicePublicKey, publicKey, team, metadata, grantToken) {
8
+ this.hostname = hostname || 'https://armor.dotenvx.com'
9
+ this.token = token
10
+ this.devicePublicKey = devicePublicKey
11
+ this.publicKey = publicKey
12
+ this.team = team
13
+ this.metadata = metadata
14
+ this.grantToken = grantToken
15
+ }
16
+
17
+ async run () {
18
+ const token = normalizeToken(this.token)
19
+ const url = `${this.hostname}/api/keypair`
20
+ const body = {
21
+ device_public_key: this.devicePublicKey,
22
+ cli_version: packageJson.version
23
+ }
24
+
25
+ if (this.publicKey) {
26
+ body.public_key = this.publicKey
27
+ }
28
+
29
+ if (this.team) {
30
+ body.team = this.team
31
+ }
32
+
33
+ if (this.metadata && Object.keys(this.metadata).length > 0) {
34
+ body.metadata = this.metadata
35
+ }
36
+
37
+ if (this.grantToken) {
38
+ body.grant_token = this.grantToken
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
@@ -0,0 +1,34 @@
1
+ const { http } = require('../helpers/http')
2
+ const buildApiError = require('../helpers/buildApiError')
3
+ const normalizeToken = require('../helpers/normalizeToken')
4
+
5
+ class PostLogout {
6
+ constructor (hostname, token) {
7
+ this.hostname = hostname
8
+ this.token = token
9
+ }
10
+
11
+ async run () {
12
+ const token = normalizeToken(this.token)
13
+ const url = `${this.hostname}/api/logout`
14
+
15
+ const resp = await http(url, {
16
+ method: 'POST',
17
+ headers: {
18
+ Authorization: `Bearer ${token}`,
19
+ 'Content-Type': 'application/json'
20
+ },
21
+ body: JSON.stringify({})
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 = PostLogout
@@ -0,0 +1,38 @@
1
+ const { http } = require('../helpers/http')
2
+ const buildOauthError = require('../helpers/buildOauthError')
3
+
4
+ const OAUTH_CLIENT_ID = 'oac_dotenvxcli'
5
+
6
+ class PostOauthDeviceCode {
7
+ constructor (hostname, devicePublicKey, systemInformation, dotenvxProjectId = null) {
8
+ this.hostname = hostname
9
+ this.devicePublicKey = devicePublicKey
10
+ this.systemInformation = systemInformation
11
+ this.dotenvxProjectId = dotenvxProjectId
12
+ }
13
+
14
+ async run () {
15
+ const resp = await http(`${this.hostname}/oauth/device/code`, {
16
+ method: 'POST',
17
+ headers: {
18
+ 'Content-Type': 'application/json'
19
+ },
20
+ body: JSON.stringify({
21
+ client_id: OAUTH_CLIENT_ID,
22
+ device_public_key: this.devicePublicKey,
23
+ system_information: this.systemInformation,
24
+ dotenvx_project_id: this.dotenvxProjectId
25
+ })
26
+ })
27
+
28
+ const json = await resp.body.json()
29
+
30
+ if (resp.statusCode >= 400) {
31
+ throw buildOauthError(resp.statusCode, json)
32
+ }
33
+
34
+ return json
35
+ }
36
+ }
37
+
38
+ module.exports = PostOauthDeviceCode