@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,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
@@ -0,0 +1,11 @@
1
+ const Session = require('./../../db/session')
2
+
3
+ class Status {
4
+ run () {
5
+ const sesh = new Session()
6
+ const status = sesh.status()
7
+ return { status }
8
+ }
9
+ }
10
+
11
+ module.exports = Status
@@ -0,0 +1,70 @@
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 PostSync = require('./../api/postSync')
14
+
15
+ class Sync {
16
+ constructor (hostname, force = false) {
17
+ this.hostname = hostname
18
+ this.force = force
19
+ this.cwd = process.cwd()
20
+ }
21
+
22
+ async run () {
23
+ const sesh = new Session()
24
+ const token = sesh.token()
25
+ const devicePublicKey = sesh.devicePublicKey()
26
+
27
+ // required
28
+ // need to get all .env files here somehow
29
+ const files = this._files()
30
+ const payload = { files }
31
+ const encoded = Buffer.from(JSON.stringify(payload)).toString('base64')
32
+ const _dotenvxProjectId = dotenvxProjectId(this.cwd)
33
+
34
+ // optional
35
+ const _pwd = this.cwd
36
+ const _gitUrl = gitUrl()
37
+ const _gitBranch = gitBranch()
38
+
39
+ const system = await si.system()
40
+ const _systemUuid = system.uuid
41
+
42
+ const osInfo = await si.osInfo()
43
+ const _osPlatform = osInfo.platform
44
+ const _osArch = osInfo.arch
45
+
46
+ const data = await new PostSync(this.hostname, token, devicePublicKey, encoded, _dotenvxProjectId, _pwd, _gitUrl, _gitBranch, _systemUuid, _osPlatform, _osArch, this.force).run()
47
+
48
+ return {
49
+ id: data.id,
50
+ dotenvxProjectId: data.dotenvx_project_id,
51
+ projectUsernameName: data.project_username_name,
52
+ files: data.files
53
+ }
54
+ }
55
+
56
+ _files () {
57
+ const out = []
58
+ const filepaths = dotenvx.ls(this.cwd)
59
+
60
+ for (const fp of filepaths) {
61
+ const abs = path.join(this.cwd, fp)
62
+ const src = fs.readFileSync(abs, 'utf8')
63
+ out.push({ filepath: fp, src })
64
+ }
65
+
66
+ return out
67
+ }
68
+ }
69
+
70
+ module.exports = Sync
@@ -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