@dotenvx/dotenvx 2.38.2 → 3.0.0-beta.2
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/README.md +197 -3314
- package/bin/dotenvx.cjs +34 -0
- package/config.cjs +1 -0
- package/config.d.ts +1 -0
- package/config.mjs +2 -0
- package/index.cjs +141 -0
- package/index.d.ts +66 -0
- package/index.mjs +3 -0
- package/lib/cli.cjs +43 -0
- package/lib/native-package.cjs +21 -0
- package/lib/platforms.cjs +18 -0
- package/{src/lib/helpers/redactOutput.js → lib/redactOutput.cjs} +2 -48
- package/lib/redaction.cjs +64 -0
- package/lib/validateOptions.cjs +57 -0
- package/native.cjs +23 -0
- package/package.json +57 -65
- package/CHANGELOG.md +0 -2733
- package/src/cli/actions/armor/down.js +0 -38
- package/src/cli/actions/armor/invite.js +0 -21
- package/src/cli/actions/armor/move.js +0 -43
- package/src/cli/actions/armor/open.js +0 -28
- package/src/cli/actions/armor/pull.js +0 -38
- package/src/cli/actions/armor/push.js +0 -38
- package/src/cli/actions/armor/status.js +0 -7
- package/src/cli/actions/armor/up.js +0 -38
- package/src/cli/actions/check.js +0 -78
- package/src/cli/actions/curl.js +0 -71
- package/src/cli/actions/decrypt.js +0 -119
- package/src/cli/actions/del.js +0 -54
- package/src/cli/actions/doctor.js +0 -22
- package/src/cli/actions/encrypt.js +0 -104
- package/src/cli/actions/ext/genexample.js +0 -36
- package/src/cli/actions/ext/gitignore.js +0 -106
- package/src/cli/actions/ext/prebuild.js +0 -7
- package/src/cli/actions/ext/precommit.js +0 -38
- package/src/cli/actions/ext/scan.js +0 -33
- package/src/cli/actions/feedback.js +0 -42
- package/src/cli/actions/get.js +0 -128
- package/src/cli/actions/init.js +0 -67
- package/src/cli/actions/keychain/down.js +0 -30
- package/src/cli/actions/keychain/pull.js +0 -30
- package/src/cli/actions/keychain/push.js +0 -30
- package/src/cli/actions/keychain/up.js +0 -30
- package/src/cli/actions/keypair.js +0 -84
- package/src/cli/actions/login.js +0 -64
- package/src/cli/actions/logout.js +0 -37
- package/src/cli/actions/ls.js +0 -76
- package/src/cli/actions/policy.js +0 -14
- package/src/cli/actions/primitivesCheck.js +0 -32
- package/src/cli/actions/primitivesProfile.js +0 -15
- package/src/cli/actions/primitivesRedact.js +0 -19
- package/src/cli/actions/protect.js +0 -75
- package/src/cli/actions/protectDocker.js +0 -30
- package/src/cli/actions/protectProcess.js +0 -126
- package/src/cli/actions/protectStdin.js +0 -80
- package/src/cli/actions/run.js +0 -203
- package/src/cli/actions/set.js +0 -103
- package/src/cli/actions/settings/device.js +0 -23
- package/src/cli/actions/settings/hostname.js +0 -20
- package/src/cli/actions/settings/off.js +0 -14
- package/src/cli/actions/settings/on.js +0 -14
- package/src/cli/actions/settings/path.js +0 -20
- package/src/cli/actions/settings/token.js +0 -23
- package/src/cli/actions/settings/username.js +0 -20
- package/src/cli/actions/update.js +0 -15
- package/src/cli/commandAction.js +0 -16
- package/src/cli/commands/armor.js +0 -129
- package/src/cli/commands/custody.js +0 -45
- package/src/cli/commands/ext.js +0 -88
- package/src/cli/commands/fileOptions.js +0 -22
- package/src/cli/commands/native.js +0 -54
- package/src/cli/commands/primitives.js +0 -73
- package/src/cli/commands/settings.js +0 -63
- package/src/cli/dotenvx.js +0 -443
- package/src/cli/help.js +0 -179
- package/src/db/device.js +0 -67
- package/src/db/session.js +0 -330
- package/src/lib/api/getAccount.js +0 -32
- package/src/lib/api/getConnectionResources.js +0 -21
- package/src/lib/api/getTeamConnections.js +0 -27
- package/src/lib/api/getTeamServices.js +0 -23
- package/src/lib/api/getTeams.js +0 -28
- package/src/lib/api/postArmorDown.js +0 -48
- package/src/lib/api/postArmorMove.js +0 -48
- package/src/lib/api/postArmorPull.js +0 -48
- package/src/lib/api/postArmorPush.js +0 -48
- package/src/lib/api/postArmorUp.js +0 -53
- package/src/lib/api/postConnectionKeypair.js +0 -23
- package/src/lib/api/postFeedback.js +0 -31
- package/src/lib/api/postLogout.js +0 -34
- package/src/lib/api/postOauthDeviceCode.js +0 -38
- package/src/lib/api/postOauthToken.js +0 -35
- package/src/lib/api/postTeamInvitation.js +0 -28
- package/src/lib/api/teamConnectionSetup.js +0 -31
- package/src/lib/config.d.ts +0 -1
- package/src/lib/config.js +0 -1
- package/src/lib/conventions/environment.js +0 -27
- package/src/lib/conventions/filepaths.js +0 -9
- package/src/lib/conventions/keynames.js +0 -38
- package/src/lib/custodians/index.js +0 -75
- package/src/lib/custodians/local/bitwarden.js +0 -165
- package/src/lib/custodians/local/file.js +0 -18
- package/src/lib/custodians/local/native/backend.js +0 -56
- package/src/lib/custodians/local/native/index.js +0 -28
- package/src/lib/custodians/local/native/store.js +0 -24
- package/src/lib/custodians/local/onepassword.js +0 -149
- package/src/lib/custodians/managed/armor/index.js +0 -14
- package/src/lib/custodians/managed/armor/store.js +0 -48
- package/src/lib/custodians/resolveLocalKey.js +0 -67
- package/src/lib/decryptors/armor/index.js +0 -23
- package/src/lib/decryptors/decryptor-worker.js +0 -6
- package/src/lib/decryptors/index.js +0 -69
- package/src/lib/envfile/discovery/discoverEnvFiles.js +0 -29
- package/src/lib/envfile/discovery/extractEnvKeys.js +0 -173
- package/src/lib/envfile/discovery/scanSource.js +0 -79
- package/src/lib/envfile/parsing/formatEnvfileSyntaxError.js +0 -24
- package/src/lib/envfile/parsing/readEnvfile.js +0 -43
- package/src/lib/envfile/parsing/resolveEnvfilePath.js +0 -5
- package/src/lib/envfile/rendering/normalizeEnvfile.js +0 -53
- package/src/lib/envfile/rendering/previewEnvfile.js +0 -43
- package/src/lib/envfile/rendering/renderEnvfile.js +0 -30
- package/src/lib/envfile/validation/diagnosticLocation.js +0 -29
- package/src/lib/envfile/validation/protectEnvfile.js +0 -40
- package/src/lib/envfile/validation/validateEnvfile.js +0 -14
- package/src/lib/events/backends/armor.js +0 -31
- package/src/lib/events/background.js +0 -59
- package/src/lib/events/catalog.js +0 -14
- package/src/lib/events/cli.js +0 -40
- package/src/lib/events/delivery.js +0 -89
- package/src/lib/events/index.js +0 -73
- package/src/lib/events/metadata.js +0 -25
- package/src/lib/events/sdk.js +0 -44
- package/src/lib/events/worker.js +0 -29
- package/src/lib/events/workerEnvironment.js +0 -14
- package/src/lib/helpers/armoredKeyDisplay.js +0 -10
- package/src/lib/helpers/arrayToTree.js +0 -27
- package/src/lib/helpers/buildApiError.js +0 -19
- package/src/lib/helpers/buildCommandEnvs.js +0 -40
- package/src/lib/helpers/buildConfigEnvs.js +0 -13
- package/src/lib/helpers/buildEnvs.js +0 -24
- package/src/lib/helpers/buildOauthError.js +0 -14
- package/src/lib/helpers/canonicalEnvFilename.js +0 -13
- package/src/lib/helpers/catchAndLog.js +0 -16
- package/src/lib/helpers/checklist.js +0 -50
- package/src/lib/helpers/chomp.js +0 -5
- package/src/lib/helpers/colorDepth.js +0 -23
- package/src/lib/helpers/conventions.js +0 -28
- package/src/lib/helpers/createElapsedStatus.js +0 -17
- package/src/lib/helpers/createProtectSpinner.js +0 -13
- package/src/lib/helpers/createSpinner.js +0 -40
- package/src/lib/helpers/cryptography/decryptKeyValue.js +0 -50
- package/src/lib/helpers/cryptography/index.js +0 -7
- package/src/lib/helpers/cryptography/isDotenvPublicKey.js +0 -7
- package/src/lib/helpers/cryptography/isPlainKey.js +0 -7
- package/src/lib/helpers/cryptography/mutateKeysSrc.js +0 -22
- package/src/lib/helpers/cryptography/mutateSrc.js +0 -24
- package/src/lib/helpers/custodySelect.js +0 -25
- package/src/lib/helpers/decryptDeviceValue.js +0 -7
- package/src/lib/helpers/detectEncoding.js +0 -22
- package/src/lib/helpers/detectEncodingSync.js +0 -22
- package/src/lib/helpers/dotenvOptionPaths.js +0 -25
- package/src/lib/helpers/dotenvPrivateKeyNames.js +0 -7
- package/src/lib/helpers/enclavedHint.js +0 -11
- package/src/lib/helpers/encryptDeviceValue.js +0 -7
- package/src/lib/helpers/envResolution/determine.js +0 -49
- package/src/lib/helpers/envResolution/index.js +0 -8
- package/src/lib/helpers/errors.js +0 -374
- package/src/lib/helpers/escape.js +0 -6
- package/src/lib/helpers/execute.js +0 -12
- package/src/lib/helpers/executeCommand.js +0 -208
- package/src/lib/helpers/executeDynamic.js +0 -86
- package/src/lib/helpers/executeExtension.js +0 -39
- package/src/lib/helpers/filterKeys.js +0 -15
- package/src/lib/helpers/findEnvFiles.js +0 -25
- package/src/lib/helpers/formatCode.js +0 -11
- package/src/lib/helpers/fsx.js +0 -110
- package/src/lib/helpers/guessPrivateKeyFilename.js +0 -15
- package/src/lib/helpers/hasPlaintextSecrets.js +0 -7
- package/src/lib/helpers/http.js +0 -14
- package/src/lib/helpers/installPrecommitHook.js +0 -82
- package/src/lib/helpers/installProtectFilter.js +0 -57
- package/src/lib/helpers/installProtectIgnore.js +0 -27
- package/src/lib/helpers/isPublicKey.js +0 -3
- package/src/lib/helpers/isTeamRequiredError.js +0 -10
- package/src/lib/helpers/jsonToEnv.js +0 -7
- package/src/lib/helpers/keypairMetadata.js +0 -90
- package/src/lib/helpers/kits/sample.js +0 -5
- package/src/lib/helpers/linuxSecretService.js +0 -52
- package/src/lib/helpers/listenForOpenKey.js +0 -46
- package/src/lib/helpers/logProtectedFiles.js +0 -9
- package/src/lib/helpers/logSetSummary.js +0 -21
- package/src/lib/helpers/macosKeychain.js +0 -52
- package/src/lib/helpers/mask.js +0 -22
- package/src/lib/helpers/maskEnvSrc.js +0 -15
- package/src/lib/helpers/maskProcessedEnvs.js +0 -29
- package/src/lib/helpers/matchesStoredKey.js +0 -5
- package/src/lib/helpers/nativeStoreError.js +0 -10
- package/src/lib/helpers/normalizeDotenvConfigConvention.js +0 -13
- package/src/lib/helpers/normalizeDotenvConfigIgnore.js +0 -18
- package/src/lib/helpers/normalizeDotenvConfigPath.js +0 -14
- package/src/lib/helpers/normalizeDotenvConfigQuiet.js +0 -13
- package/src/lib/helpers/normalizeToken.js +0 -5
- package/src/lib/helpers/openUrl.js +0 -7
- package/src/lib/helpers/packageJson.js +0 -3
- package/src/lib/helpers/parseWithDecryptor.js +0 -115
- package/src/lib/helpers/plaintextKeys.js +0 -9
- package/src/lib/helpers/precommitEnvPatterns.js +0 -1
- package/src/lib/helpers/prependPublicKey.js +0 -17
- package/src/lib/helpers/preserveShebang.js +0 -16
- package/src/lib/helpers/prompts.js +0 -169
- package/src/lib/helpers/protectSettings.js +0 -64
- package/src/lib/helpers/ptyCommand.js +0 -27
- package/src/lib/helpers/readEnvKey.js +0 -32
- package/src/lib/helpers/redact.js +0 -9
- package/src/lib/helpers/redactProcessOutput.js +0 -58
- package/src/lib/helpers/redactedValues.js +0 -29
- package/src/lib/helpers/removeDynamicHelpSection.js +0 -21
- package/src/lib/helpers/removeEnvKey.js +0 -51
- package/src/lib/helpers/removeLegacyProtectFilter.js +0 -43
- package/src/lib/helpers/removeOptionsHelpParts.js +0 -59
- package/src/lib/helpers/resolveBitwardenPassword.js +0 -165
- package/src/lib/helpers/resolveDirectoryFilepath.js +0 -16
- package/src/lib/helpers/resolveEnvKeysFile.js +0 -11
- package/src/lib/helpers/resolveHome.js +0 -12
- package/src/lib/helpers/resolveOnePassword.js +0 -82
- package/src/lib/helpers/sanitizeCommandForMetadata.js +0 -64
- package/src/lib/helpers/selectConnection.js +0 -51
- package/src/lib/helpers/selectConnectionResource.js +0 -41
- package/src/lib/helpers/selectEnvfileEnvs.js +0 -29
- package/src/lib/helpers/selectKeyStorage.js +0 -140
- package/src/lib/helpers/statusReporter.js +0 -8
- package/src/lib/helpers/storeKeyStorage.js +0 -39
- package/src/lib/helpers/teamChoicesFromMeta.js +0 -8
- package/src/lib/helpers/truncate.js +0 -10
- package/src/lib/helpers/uninstallPrecommitHook.js +0 -67
- package/src/lib/helpers/upsertEnvKey.js +0 -62
- package/src/lib/helpers/windowsCredentialManager.js +0 -166
- package/src/lib/main.d.ts +0 -509
- package/src/lib/main.js +0 -468
- package/src/lib/providers/index.js +0 -86
- package/src/lib/providers/native/index.js +0 -2
- package/src/lib/resolvers/envs.js +0 -416
- package/src/lib/resolvers/get.js +0 -87
- package/src/lib/resolvers/keypair.js +0 -135
- package/src/lib/resolvers/ls.js +0 -69
- package/src/lib/services/armorDown.js +0 -73
- package/src/lib/services/armorInvite.js +0 -36
- package/src/lib/services/armorMove.js +0 -55
- package/src/lib/services/armorOpen.js +0 -26
- package/src/lib/services/armorPull.js +0 -73
- package/src/lib/services/armorPush.js +0 -66
- package/src/lib/services/armorUp.js +0 -71
- package/src/lib/services/custodyTransfer.js +0 -50
- package/src/lib/services/doctor.js +0 -93
- package/src/lib/services/genexample.js +0 -112
- package/src/lib/services/init.js +0 -83
- package/src/lib/services/keychainDown.js +0 -60
- package/src/lib/services/keychainPull.js +0 -46
- package/src/lib/services/keychainPush.js +0 -51
- package/src/lib/services/keychainUp.js +0 -72
- package/src/lib/services/login.js +0 -51
- package/src/lib/services/logout.js +0 -26
- package/src/lib/services/prebuild.js +0 -91
- package/src/lib/services/precommit.js +0 -144
- package/src/lib/services/validate.js +0 -57
- package/src/lib/transforms/decrypt.js +0 -98
- package/src/lib/transforms/del.js +0 -58
- package/src/lib/transforms/encrypt.js +0 -164
- package/src/lib/transforms/set.js +0 -144
- package/src/shared/colors.js +0 -67
- package/src/shared/logger.js +0 -148
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
// Best-effort static syntax extraction, independent of traversal and filesystem I/O.
|
|
2
|
-
// Deliberately does not evaluate expressions or follow runtime-computed key names.
|
|
3
|
-
const identifier = '[A-Za-z_][A-Za-z0-9_]*'
|
|
4
|
-
const literal = `(['"\x60])(${identifier})\\1`
|
|
5
|
-
const member = '\\s*(?:\\?\\.|\\.)\\s*'
|
|
6
|
-
const envMember = `(?:${member}env|\\s*(?:\\?\\.\\s*)?\\[\\s*(?:'env'|"env")\\s*\\])`
|
|
7
|
-
const jsEnv = `(?:process${envMember}|import${member}meta${envMember})`
|
|
8
|
-
const boundary = '(?<![\\w$.])'
|
|
9
|
-
|
|
10
|
-
function escapeRegex (value) {
|
|
11
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Match braces without counting braces inside quoted defaults or comments.
|
|
15
|
-
function openingBraces (source) {
|
|
16
|
-
const openings = new Map()
|
|
17
|
-
const stack = []
|
|
18
|
-
let quote
|
|
19
|
-
for (let i = 0; i < source.length; i++) {
|
|
20
|
-
const char = source[i]
|
|
21
|
-
if (quote) {
|
|
22
|
-
if (char === '\\') i++
|
|
23
|
-
else if (char === quote) quote = undefined
|
|
24
|
-
} else if ('\'"`'.includes(char)) quote = char
|
|
25
|
-
else if (source.startsWith('//', i)) {
|
|
26
|
-
const end = source.indexOf('\n', i + 2)
|
|
27
|
-
i = end === -1 ? source.length : end
|
|
28
|
-
} else if (source.startsWith('/*', i)) {
|
|
29
|
-
const end = source.indexOf('*/', i + 2)
|
|
30
|
-
i = end === -1 ? source.length : end + 1
|
|
31
|
-
} else if (char === '{') stack.push(i)
|
|
32
|
-
else if (char === '}') openings.set(i, stack.pop())
|
|
33
|
-
}
|
|
34
|
-
return openings
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Split destructuring properties without treating commas in defaults or nested
|
|
38
|
-
// patterns as new properties. This also lets us ignore rest and computed names.
|
|
39
|
-
function properties (body) {
|
|
40
|
-
const parts = []
|
|
41
|
-
let start = 0
|
|
42
|
-
let depth = 0
|
|
43
|
-
let quote
|
|
44
|
-
for (let i = 0; i < body.length; i++) {
|
|
45
|
-
const char = body[i]
|
|
46
|
-
if (quote) {
|
|
47
|
-
if (char === '\\') i++
|
|
48
|
-
else if (char === quote) quote = undefined
|
|
49
|
-
} else if ('\'"`'.includes(char)) quote = char
|
|
50
|
-
else if ('([{'.includes(char)) depth++
|
|
51
|
-
else if (')]}'.includes(char)) depth--
|
|
52
|
-
else if (char === ',' && depth === 0) {
|
|
53
|
-
parts.push(body.slice(start, i))
|
|
54
|
-
start = i + 1
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
parts.push(body.slice(start))
|
|
58
|
-
return parts
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
module.exports = function extractEnvKeys (content, language) {
|
|
62
|
-
// Preserve line breaks for import detection. Full parsing of every language is
|
|
63
|
-
// intentionally outside this helper; inline comments/strings can still match.
|
|
64
|
-
const source = content.split('\n').map(line => {
|
|
65
|
-
const text = line.trimStart()
|
|
66
|
-
if (['python', 'ruby', 'php'].includes(language) && text.startsWith('#')) return ''
|
|
67
|
-
if (!['python', 'ruby'].includes(language) && /^(\/\/|\/\*|\*(?:\s|\/|$))/.test(text)) return ''
|
|
68
|
-
return line
|
|
69
|
-
}).join('\n')
|
|
70
|
-
const keys = new Set()
|
|
71
|
-
function collect (pattern, group = 2, input = source) {
|
|
72
|
-
for (const match of input.matchAll(new RegExp(pattern, 'g'))) keys.add(match[group])
|
|
73
|
-
}
|
|
74
|
-
function call (base) {
|
|
75
|
-
collect(`${boundary}(?:${base})\\s*\\(\\s*${literal}\\s*(?=[,)])`)
|
|
76
|
-
}
|
|
77
|
-
function bracket (base) {
|
|
78
|
-
collect(`${boundary}(?:${base})\\s*\\[\\s*${literal}\\s*\\]`)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (language === 'js') {
|
|
82
|
-
const bases = [{ base: jsEnv, start: 0 }]
|
|
83
|
-
// Only immutable, direct bindings: no evaluation or guessed dynamic aliases.
|
|
84
|
-
const binding = /\bconst\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g
|
|
85
|
-
for (const match of source.matchAll(binding)) {
|
|
86
|
-
const value = match[2].trim()
|
|
87
|
-
if (!bases.some(({ base }) => new RegExp(`^(?:${base})$`).test(value))) continue
|
|
88
|
-
bases.push({ base: escapeRegex(match[1]), start: match.index + match[0].length })
|
|
89
|
-
}
|
|
90
|
-
for (const { base, start } of bases) {
|
|
91
|
-
const input = source.slice(start)
|
|
92
|
-
collect(`${boundary}(?:${base})${member}(${identifier})\\b`, 1, input)
|
|
93
|
-
collect(`${boundary}(?:${base})\\s*(?:\\?\\.\\s*)?\\[\\s*${literal}\\s*\\]`, 2, input)
|
|
94
|
-
const openings = openingBraces(input)
|
|
95
|
-
for (const match of input.matchAll(new RegExp(`}\\s*=\\s*(?:${base})(?![\\w$]|\\s*(?:\\?\\.|\\.|\\[))`, 'g'))) {
|
|
96
|
-
const opening = openings.get(match.index)
|
|
97
|
-
if (opening === undefined) continue
|
|
98
|
-
for (const property of properties(input.slice(opening + 1, match.index))) {
|
|
99
|
-
const key = property.trim().match(new RegExp(`^(?:(${identifier})|['"](${identifier})['"]|\\[\\s*['"](${identifier})['"]\\s*\\])\\s*(?=[:,=]|$)`))
|
|
100
|
-
if (key) keys.add(key[1] || key[2] || key[3])
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
} else if (language === 'python') {
|
|
105
|
-
const modules = new Set(['os'])
|
|
106
|
-
const getters = new Set()
|
|
107
|
-
const environs = new Set()
|
|
108
|
-
for (const match of source.matchAll(/^\s*import\s+([^\n;]+)/gm)) {
|
|
109
|
-
for (const item of match[1].split(',')) {
|
|
110
|
-
const imported = item.trim().match(/^os(?:\s+as\s+([A-Za-z_]\w*))?\s*(?:#.*)?$/)
|
|
111
|
-
if (imported) modules.add(imported[1] || 'os')
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
for (const match of source.matchAll(/^\s*from\s+os\s+import\s+(?:\(([^)]*)\)|([^\n;]+))/gm)) {
|
|
115
|
-
for (const item of (match[1] || match[2]).split(',')) {
|
|
116
|
-
const imported = item.replace(/#[^\n]*/g, '').trim().match(/^(getenv|environ)(?:\s+as\s+([A-Za-z_]\w*))?$/)
|
|
117
|
-
if (!imported) continue
|
|
118
|
-
const aliases = imported[1] === 'getenv' ? getters : environs
|
|
119
|
-
aliases.add(imported[2] || imported[1])
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (const name of modules) {
|
|
123
|
-
call(`${escapeRegex(name)}\\s*\\.\\s*getenv`)
|
|
124
|
-
environs.add(`${name}.environ`)
|
|
125
|
-
}
|
|
126
|
-
for (const name of getters) call(escapeRegex(name))
|
|
127
|
-
for (const name of environs) {
|
|
128
|
-
const base = name.split('.').map(escapeRegex).join('\\s*\\.\\s*')
|
|
129
|
-
bracket(base)
|
|
130
|
-
call(`${base}\\s*\\.\\s*get`)
|
|
131
|
-
}
|
|
132
|
-
} else if (language === 'go') {
|
|
133
|
-
call('os\\s*\\.\\s*(?:Getenv|LookupEnv)')
|
|
134
|
-
for (const match of source.matchAll(/\bimport\s+(?:\(([^)]*)\)|([^\n;]+))/g)) {
|
|
135
|
-
for (const imported of (match[1] || match[2]).matchAll(/(?:^|[;\n])\s*([A-Za-z_]\w*|\.)\s+["`]os["`]\s*(?=$|[;\n]|\/\/)/g)) {
|
|
136
|
-
const alias = imported[1]
|
|
137
|
-
if (alias === '_') continue
|
|
138
|
-
call(alias === '.' ? '(?:Getenv|LookupEnv)' : `${escapeRegex(alias)}\\s*\\.\\s*(?:Getenv|LookupEnv)`)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
} else if (language === 'ruby') {
|
|
142
|
-
bracket('ENV')
|
|
143
|
-
call('ENV\\s*\\.\\s*fetch')
|
|
144
|
-
collect(`${boundary}ENV\\s*\\.\\s*fetch\\s+${literal}\\s*(?=,|$|[;\\r\\n])`)
|
|
145
|
-
} else if (language === 'php') {
|
|
146
|
-
call('getenv')
|
|
147
|
-
bracket('\\$_(?:ENV|SERVER)')
|
|
148
|
-
} else if (language === 'rust') {
|
|
149
|
-
call('(?:std\\s*::\\s*)?env\\s*::\\s*(?:var|var_os)')
|
|
150
|
-
// Expand Rust use trees, including grouped and renamed imports.
|
|
151
|
-
function imports (tree, prefix = '') {
|
|
152
|
-
for (const item of properties(tree)) {
|
|
153
|
-
const value = item.trim()
|
|
154
|
-
const group = value.indexOf('{')
|
|
155
|
-
if (group !== -1 && value.endsWith('}')) {
|
|
156
|
-
imports(value.slice(group + 1, -1), prefix + value.slice(0, group))
|
|
157
|
-
continue
|
|
158
|
-
}
|
|
159
|
-
const [original, alias] = (prefix + value).split(/\s+as\s+/)
|
|
160
|
-
const path = original.replace(/\s/g, '').replace(/::self$/, '')
|
|
161
|
-
if (alias === '_') continue
|
|
162
|
-
if (path === 'std::env') call(`${escapeRegex(alias || 'env')}\\s*::\\s*(?:var|var_os)`)
|
|
163
|
-
if (/^std::env::(?:var|var_os)$/.test(path)) call(escapeRegex(alias || path.split('::').pop()))
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
for (const match of source.matchAll(/\buse\s+([^;]+);/g)) imports(match[1])
|
|
167
|
-
} else if (language === 'java') {
|
|
168
|
-
call('(?:java\\s*\\.\\s*lang\\s*\\.\\s*)?System\\s*\\.\\s*getenv')
|
|
169
|
-
} else if (language === 'csharp') {
|
|
170
|
-
call('(?:System\\s*\\.\\s*)?Environment\\s*\\.\\s*GetEnvironmentVariable')
|
|
171
|
-
}
|
|
172
|
-
return [...keys].sort()
|
|
173
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs/promises')
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
const { ignore } = require('@dotenvx/tooling')
|
|
4
|
-
const extractEnvKeys = require('./extractEnvKeys')
|
|
5
|
-
|
|
6
|
-
const ignoredDirectories = new Set(['.git', 'node_modules', 'dist', 'build', '.next', 'vendor', '.venv', 'coverage', '__pycache__'])
|
|
7
|
-
const projectMarkers = new Set(['package.json', 'Envfile', '.env.schema'])
|
|
8
|
-
const languages = {
|
|
9
|
-
js: 'js',
|
|
10
|
-
mjs: 'js',
|
|
11
|
-
cjs: 'js',
|
|
12
|
-
jsx: 'js',
|
|
13
|
-
ts: 'js',
|
|
14
|
-
mts: 'js',
|
|
15
|
-
cts: 'js',
|
|
16
|
-
tsx: 'js',
|
|
17
|
-
vue: 'js',
|
|
18
|
-
svelte: 'js',
|
|
19
|
-
astro: 'js',
|
|
20
|
-
py: 'python',
|
|
21
|
-
go: 'go',
|
|
22
|
-
rb: 'ruby',
|
|
23
|
-
php: 'php',
|
|
24
|
-
rs: 'rust',
|
|
25
|
-
java: 'java',
|
|
26
|
-
cs: 'csharp'
|
|
27
|
-
}
|
|
28
|
-
module.exports = async function scanSource ({ directory = process.cwd(), onFile = () => {} } = {}) {
|
|
29
|
-
const root = path.resolve(directory)
|
|
30
|
-
const keys = new Set()
|
|
31
|
-
let scannedFiles = 0
|
|
32
|
-
const files = []
|
|
33
|
-
|
|
34
|
-
async function walk (directory, parents) {
|
|
35
|
-
const entries = (await fs.readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))
|
|
36
|
-
if (directory !== root && entries.some(entry => entry.isFile() && projectMarkers.has(entry.name))) return
|
|
37
|
-
const rules = [...parents]
|
|
38
|
-
if (entries.some(entry => entry.name === '.gitignore' && entry.isFile())) {
|
|
39
|
-
rules.push({ directory, matcher: ignore().add(await fs.readFile(path.join(directory, '.gitignore'), 'utf8')) })
|
|
40
|
-
}
|
|
41
|
-
for (const entry of entries) {
|
|
42
|
-
if (entry.name.startsWith('.env') || entry.isSymbolicLink()) continue
|
|
43
|
-
if (entry.isDirectory() && ignoredDirectories.has(entry.name)) continue
|
|
44
|
-
const filename = path.join(directory, entry.name)
|
|
45
|
-
let ignored = false
|
|
46
|
-
for (const rule of rules) {
|
|
47
|
-
const relative = path.relative(rule.directory, filename).split(path.sep).join('/') + (entry.isDirectory() ? '/' : '')
|
|
48
|
-
const result = rule.matcher.test(relative)
|
|
49
|
-
if (result.ignored) ignored = true
|
|
50
|
-
else if (result.unignored) ignored = false
|
|
51
|
-
}
|
|
52
|
-
if (ignored) continue
|
|
53
|
-
if (entry.isDirectory()) {
|
|
54
|
-
await walk(filename, rules)
|
|
55
|
-
} else if (entry.isFile()) {
|
|
56
|
-
const language = languages[path.extname(entry.name).slice(1).toLowerCase()]
|
|
57
|
-
if (language) files.push({ filename, language })
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
await walk(root, [])
|
|
63
|
-
let nextFile = 0
|
|
64
|
-
async function worker () {
|
|
65
|
-
while (nextFile < files.length) {
|
|
66
|
-
const { filename, language } = files[nextFile++]
|
|
67
|
-
if ((await fs.stat(filename)).size > 1024 * 1024) continue
|
|
68
|
-
const content = await fs.readFile(filename, 'utf8')
|
|
69
|
-
if (content.includes('\0')) continue
|
|
70
|
-
onFile(path.relative(root, filename))
|
|
71
|
-
scannedFiles++
|
|
72
|
-
for (const key of extractEnvKeys(content, language)) {
|
|
73
|
-
if (!/^DOTENV_(?:PUBLIC|PRIVATE)_KEY(?:_|$)/.test(key)) keys.add(key)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
await Promise.all(Array.from({ length: Math.min(50, files.length) }, worker))
|
|
78
|
-
return { keys: [...keys].sort(), scannedFiles }
|
|
79
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const path = require('node:path')
|
|
2
|
-
|
|
3
|
-
module.exports = function formatEnvfileSyntaxError (error, src, filepath) {
|
|
4
|
-
const location = error.location?.start
|
|
5
|
-
if (!location) return error.message
|
|
6
|
-
|
|
7
|
-
const filename = path.relative(process.cwd(), filepath) || path.basename(filepath)
|
|
8
|
-
const line = src.split(/\r\n|\n|\r/)[location.line - 1] || ''
|
|
9
|
-
let message = error.message
|
|
10
|
-
if (error.expected) {
|
|
11
|
-
const remaining = src.slice(location.offset)
|
|
12
|
-
const token = remaining.match(/^(?:"[^"\r\n]*"|'[^'\r\n]*'|[A-Za-z0-9_]+|[^\r\n])/u)?.[0]
|
|
13
|
-
const displayToken = token && /^["']/.test(token) ? token : JSON.stringify(token)
|
|
14
|
-
message = token ? `Unexpected ${displayToken}` : 'Unexpected end of input'
|
|
15
|
-
const expected = [...new Set(error.expected.flatMap(item => {
|
|
16
|
-
if (item.type === 'other') return [item.description]
|
|
17
|
-
if (item.type === 'literal' && item.text.trim() && item.text !== '#') return [JSON.stringify(item.text)]
|
|
18
|
-
return []
|
|
19
|
-
}))]
|
|
20
|
-
if (expected.length > 0 && expected.length <= 3) message += `; expected ${expected.join(' or ')}`
|
|
21
|
-
}
|
|
22
|
-
const prefix = `${location.line} | `
|
|
23
|
-
return `${filename}:${location.line}:${location.column}: ${message}\n${prefix}${line}\n${' '.repeat(prefix.length)}${line.slice(0, location.column - 1).replace(/[^\t]/g, ' ')}^`
|
|
24
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs')
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
const { policy } = require('@dotenvx/primitives')
|
|
4
|
-
const resolveEnvfilePath = require('./resolveEnvfilePath')
|
|
5
|
-
const formatEnvfileSyntaxError = require('./formatEnvfileSyntaxError')
|
|
6
|
-
|
|
7
|
-
function readSource (filepath = resolveEnvfilePath()) {
|
|
8
|
-
try {
|
|
9
|
-
return { source: fs.readFileSync(filepath, 'utf8'), filepath, exists: true }
|
|
10
|
-
} catch (error) {
|
|
11
|
-
if (error.code !== 'ENOENT') throw error
|
|
12
|
-
if (fs.lstatSync(filepath, { throwIfNoEntry: false })) throw new Error(`Cannot read Envfile: ${filepath}`)
|
|
13
|
-
return { filepath, exists: false }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function readEnvfile (filepath, files = ['.env']) {
|
|
18
|
-
const document = readSource(filepath)
|
|
19
|
-
if (!document.exists) return { keys: {}, exists: false }
|
|
20
|
-
// File paths arrive relative to the caller; file blocks are relative to Envfile.
|
|
21
|
-
const selected = files.flatMap(file => {
|
|
22
|
-
const absolute = path.resolve(file)
|
|
23
|
-
return [path.relative(path.dirname(document.filepath), absolute), absolute]
|
|
24
|
-
}).join(',')
|
|
25
|
-
try {
|
|
26
|
-
return { ...policy(document.source, selected), exists: true }
|
|
27
|
-
} catch (error) {
|
|
28
|
-
formatError(error, document)
|
|
29
|
-
throw error
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = readEnvfile
|
|
34
|
-
module.exports.source = readSource
|
|
35
|
-
|
|
36
|
-
function formatError (error, document) {
|
|
37
|
-
if (error.location) {
|
|
38
|
-
error.message = `[${error.code}] ${formatEnvfileSyntaxError(error.cause || error, document.source, document.filepath)}`
|
|
39
|
-
error.messageWithHelp = error.message
|
|
40
|
-
}
|
|
41
|
-
return error
|
|
42
|
-
}
|
|
43
|
-
module.exports.formatError = formatError
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// Pure final pass over independently inferred file rules. Never mutates inputs.
|
|
2
|
-
module.exports = function normalizeEnvfile ({ files, codeDeclarations = [] }) {
|
|
3
|
-
const hasNamedEnvironment = files.some(file => !['.env', '.env.example'].includes(file.filename))
|
|
4
|
-
const rootFiles = []
|
|
5
|
-
const environments = []
|
|
6
|
-
for (const file of files) {
|
|
7
|
-
if ((file.filename === '.env.example' || (file.filename === '.env' && !hasNamedEnvironment))) rootFiles.push(file)
|
|
8
|
-
else environments.push(file)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const encrypted = true
|
|
12
|
-
const root = new Map()
|
|
13
|
-
for (const file of rootFiles) {
|
|
14
|
-
for (const item of file.declarations) {
|
|
15
|
-
const previous = root.get(item.name)
|
|
16
|
-
root.set(item.name, { ...item, encrypted: Boolean(previous?.encrypted || item.encrypted) })
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (environments.length > 1) {
|
|
21
|
-
for (const item of environments[0].declarations) {
|
|
22
|
-
const matches = environments.map(file => file.declarations.find(other => other.name === item.name))
|
|
23
|
-
if (!root.has(item.name) && matches.every(other => other && other.type === item.type && other.optional === item.optional)) {
|
|
24
|
-
// Keep encryption differences in their file scopes, not the shared declaration.
|
|
25
|
-
root.set(item.name, { ...item, encrypted: matches.some(other => other.encrypted !== false) })
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const blocks = environments.map(file => {
|
|
31
|
-
const declarations = file.declarations.flatMap(item => {
|
|
32
|
-
const inherited = root.get(item.name)
|
|
33
|
-
const defaults = inherited || { encrypted: true }
|
|
34
|
-
const overrides = Object.fromEntries(Object.entries(item).filter(([key, value]) => key !== 'name' && value !== defaults[key]))
|
|
35
|
-
return inherited && !Object.keys(overrides).length ? [] : [{ name: item.name, ...overrides }]
|
|
36
|
-
})
|
|
37
|
-
return { filename: file.filename, declarations }
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
const names = new Set(files.flatMap(file => file.declarations.map(item => item.name)))
|
|
41
|
-
const code = []
|
|
42
|
-
for (const item of codeDeclarations) {
|
|
43
|
-
if (names.has(item.name)) continue
|
|
44
|
-
names.add(item.name)
|
|
45
|
-
code.push({ ...item, optional: true })
|
|
46
|
-
}
|
|
47
|
-
const declarations = [...root.values()].map(item => {
|
|
48
|
-
const result = { ...item }
|
|
49
|
-
if (result.encrypted === encrypted) delete result.encrypted
|
|
50
|
-
return result
|
|
51
|
-
})
|
|
52
|
-
return { declarations, files: blocks, codeDeclarations: code }
|
|
53
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const { encrypted } = require('@dotenvx/primitives')
|
|
2
|
-
const diagnosticLocations = require('../validation/diagnosticLocation')
|
|
3
|
-
const { getColor } = require('../../../shared/colors')
|
|
4
|
-
|
|
5
|
-
function displayValue (value) {
|
|
6
|
-
const hasControl = Array.from(value).some(char => char.charCodeAt(0) < 32)
|
|
7
|
-
if (value && !hasControl && !/[\s#"'`\\\x7f-\x9f]/.test(value)) return value
|
|
8
|
-
return JSON.stringify(value).replace(/[\x7f-\x9f\u2028\u2029]/g, char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Show final resolved values once, not source contents or unrelated shell variables.
|
|
12
|
-
module.exports = function previewEnvfile (processedEnvs, schema, checked, diagnostics = []) {
|
|
13
|
-
const keys = new Set((processedEnvs || []).flatMap(row => [...Object.keys(row.parsed || {}), ...Object.keys(row.injected || {}), ...Object.keys(row.existed || {})]))
|
|
14
|
-
for (const key of Object.keys(schema.keys)) keys.add(key)
|
|
15
|
-
const location = diagnosticLocations(processedEnvs || [], 'process.env', { environmentLabel: 'process.env' })
|
|
16
|
-
const rows = []
|
|
17
|
-
const errors = new Map()
|
|
18
|
-
for (const diagnostic of diagnostics) {
|
|
19
|
-
keys.add(diagnostic.key)
|
|
20
|
-
const message = diagnostic.rule ? `!${diagnostic.rule}` : `! ${diagnostic.message}`
|
|
21
|
-
errors.set(diagnostic.key, [...new Set([...(errors.get(diagnostic.key) || []), message])])
|
|
22
|
-
}
|
|
23
|
-
for (const key of keys) {
|
|
24
|
-
const missing = checked[key] === undefined
|
|
25
|
-
if (/^DOTENV_(?:PUBLIC|PRIVATE)_KEY/.test(key) || (missing && !errors.has(key))) continue
|
|
26
|
-
const value = String(checked[key])
|
|
27
|
-
const display = missing ? '[MISSING]' : displayValue(encrypted(value) ? '[REDACTED]' : value)
|
|
28
|
-
const source = missing ? '' : displayValue(location(key))
|
|
29
|
-
const error = errors.has(key) ? errors.get(key).join(', ') : ''
|
|
30
|
-
const unspecced = !Object.hasOwn(schema.keys, key)
|
|
31
|
-
const status = [unspecced ? '!declared' : '', error].filter(Boolean).join(', ')
|
|
32
|
-
rows.push({ assignment: `${key}=${display}`, comment: [source, status].filter(Boolean).join(' '), error, unspecced })
|
|
33
|
-
}
|
|
34
|
-
const width = Math.max(0, ...rows.map(row => row.assignment.length))
|
|
35
|
-
return rows.map(({ assignment, comment, error, unspecced }) => {
|
|
36
|
-
const line = `${assignment.padEnd(width)} # ${comment}`
|
|
37
|
-
return error
|
|
38
|
-
? getColor('red', process.stdout)(`☠ ${line}`)
|
|
39
|
-
: unspecced
|
|
40
|
-
? getColor('orangered', process.stdout)(`⚠ ${line}`)
|
|
41
|
-
: `${getColor('green', process.stdout)('✔')} ${getColor('gray', process.stdout)(line)}`
|
|
42
|
-
}).join('\n')
|
|
43
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
function declaration (item) {
|
|
2
|
-
let line = `env "${item.name}"`
|
|
3
|
-
if (item.type) line += `, type: "${item.type}"`
|
|
4
|
-
if (item.encrypted !== undefined) line += `, encrypted: ${item.encrypted}`
|
|
5
|
-
if (item.redacted !== undefined) line += `, redacted: ${item.redacted}`
|
|
6
|
-
if (item.optional !== undefined) line += `, optional: ${item.optional}`
|
|
7
|
-
return line
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function renderFile (file) {
|
|
11
|
-
const quote = file.filename.includes('"') ? "'" : '"'
|
|
12
|
-
if (file.filename.includes(quote) || /[\r\n\0*?[\]{}]/.test(file.filename)) {
|
|
13
|
-
throw new Error(`Unsupported Envfile filename: ${file.filename}`)
|
|
14
|
-
}
|
|
15
|
-
const lines = [`file ${quote}${file.filename}${quote} do`]
|
|
16
|
-
lines.push(...file.declarations.map(item => ` ${declaration(item)}`), 'end')
|
|
17
|
-
return lines.join('\n')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = function renderEnvfile (document) {
|
|
21
|
-
const sections = ['strict true']
|
|
22
|
-
if (document.declarations.length) sections.push(document.declarations.map(declaration).join('\n'))
|
|
23
|
-
for (const file of document.files) {
|
|
24
|
-
sections.push(renderFile(file))
|
|
25
|
-
}
|
|
26
|
-
if (document.codeDeclarations.length) {
|
|
27
|
-
sections.push('# additionally found in code\n' + document.codeDeclarations.map(declaration).join('\n'))
|
|
28
|
-
}
|
|
29
|
-
return '# Envfile (safe to commit)\n# ------------------------\n\n' + sections.join('\n\n') + '\n'
|
|
30
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const path = require('node:path')
|
|
2
|
-
|
|
3
|
-
// Match the assignment grammar used by primitives.scan, including multiline values.
|
|
4
|
-
function assignmentLines (src) {
|
|
5
|
-
const text = (src || '').toString().replace(/\r\n?/g, '\n')
|
|
6
|
-
const assignment = /^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#(.*))?$/mg
|
|
7
|
-
const result = new Map()
|
|
8
|
-
for (const match of text.matchAll(assignment)) {
|
|
9
|
-
const start = match.index + match[0].search(/\S/)
|
|
10
|
-
result.set(match[1], text.slice(0, start).split('\n').length)
|
|
11
|
-
}
|
|
12
|
-
return result
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = function diagnosticLocations (processedEnvs, fallback, { environmentLabel } = {}) {
|
|
16
|
-
const locations = new Map()
|
|
17
|
-
for (const row of processedEnvs) {
|
|
18
|
-
const filename = row.type === 'envFile' ? path.relative(process.cwd(), path.resolve(row.filepath)) : (environmentLabel || '--env')
|
|
19
|
-
const lines = assignmentLines(row.src || row.string)
|
|
20
|
-
for (const key of Object.keys(row.injected || {})) {
|
|
21
|
-
const line = row.type === 'envFile' || !environmentLabel ? lines.get(key) : undefined
|
|
22
|
-
locations.set(key, line ? `${filename}:${line}` : filename)
|
|
23
|
-
}
|
|
24
|
-
for (const key of Object.keys(row.existed || {})) {
|
|
25
|
-
if (!locations.has(key)) locations.set(key, environmentLabel || 'shell environment')
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return key => locations.get(key) || fallback
|
|
29
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const fs = require('node:fs')
|
|
2
|
-
const path = require('node:path')
|
|
3
|
-
const { execFileSync } = require('node:child_process')
|
|
4
|
-
const readEnvfile = require('../parsing/readEnvfile')
|
|
5
|
-
const resolveEnvfilePath = require('../parsing/resolveEnvfilePath')
|
|
6
|
-
const plaintextKeys = require('../../helpers/plaintextKeys')
|
|
7
|
-
|
|
8
|
-
function readPolicy (policyPath, file) {
|
|
9
|
-
const schema = readEnvfile(policyPath, [file])
|
|
10
|
-
if (!schema.exists) {
|
|
11
|
-
// A dangling policy symlink is a broken policy, not an absent policy.
|
|
12
|
-
if (fs.lstatSync(policyPath, { throwIfNoEntry: false })) throw new Error(`Cannot read Envfile: ${policyPath}`)
|
|
13
|
-
return null
|
|
14
|
-
}
|
|
15
|
-
return schema
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Inspect Git's incoming blob, never the working-tree env values or shell overrides.
|
|
19
|
-
module.exports = function protectEnvfile (filepath, content) {
|
|
20
|
-
const file = path.resolve(filepath)
|
|
21
|
-
const directory = path.dirname(file)
|
|
22
|
-
let schema = readPolicy(resolveEnvfilePath(directory), file)
|
|
23
|
-
if (!schema) {
|
|
24
|
-
let root
|
|
25
|
-
try {
|
|
26
|
-
root = execFileSync('git', ['rev-parse', '--show-toplevel'], {
|
|
27
|
-
cwd: directory,
|
|
28
|
-
encoding: 'utf8',
|
|
29
|
-
stdio: ['ignore', 'pipe', 'ignore']
|
|
30
|
-
}).trim()
|
|
31
|
-
} catch {
|
|
32
|
-
// Outside a Git working tree, only an adjacent policy can apply.
|
|
33
|
-
return null
|
|
34
|
-
}
|
|
35
|
-
if (path.resolve(root) !== directory) schema = readPolicy(resolveEnvfilePath(root), file)
|
|
36
|
-
}
|
|
37
|
-
if (!schema) return null
|
|
38
|
-
|
|
39
|
-
return plaintextKeys(content).filter(key => /^DOTENV_PRIVATE_KEY(?:_|$)/.test(key) || (schema.keys[key]?.fs.encrypted ?? true))
|
|
40
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const { check } = require('@dotenvx/primitives')
|
|
2
|
-
const Errors = require('../../helpers/errors')
|
|
3
|
-
|
|
4
|
-
module.exports = function validateEnvfile (policy, env) {
|
|
5
|
-
if (!policy.exists) return { checked: {}, errors: [] }
|
|
6
|
-
return check(policy, env)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports.error = function validationError (diagnostics) {
|
|
10
|
-
if (!diagnostics.length) return
|
|
11
|
-
const error = new Errors({ message: diagnostics.map(item => item.message).join('; ') }).invalidEnv()
|
|
12
|
-
error.diagnostics = diagnostics
|
|
13
|
-
return error
|
|
14
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const Session = require('../../../db/session')
|
|
2
|
-
const { http } = require('../../helpers/http')
|
|
3
|
-
|
|
4
|
-
// Radar ingests client-reported activity at POST /api/events.
|
|
5
|
-
// Authentication is captured before `run` loads application environment values.
|
|
6
|
-
module.exports = function armor (options = {}) {
|
|
7
|
-
if (process.env.DOTENVX_NO_ARMOR === 'true' || options.armor === false || options.noArmor === true) return
|
|
8
|
-
const session = new Session()
|
|
9
|
-
if (!options.token && (!session.on() || !session.username())) return
|
|
10
|
-
const token = options.token || session.token()
|
|
11
|
-
if (!token) return
|
|
12
|
-
const hostname = session.hostname()
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
id: 'armor',
|
|
16
|
-
async send (events, { signal }) {
|
|
17
|
-
const response = await http(`${hostname}/api/events`, {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
signal,
|
|
20
|
-
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
21
|
-
body: JSON.stringify({ events })
|
|
22
|
-
})
|
|
23
|
-
// No response data belongs in console output (including errors).
|
|
24
|
-
// Undici can emit an asynchronous AbortError when its body is destroyed,
|
|
25
|
-
// even after the request promise resolves. Handle it before cleanup.
|
|
26
|
-
response.body.on('error', () => {})
|
|
27
|
-
response.body.destroy()
|
|
28
|
-
if (response.statusCode >= 400) throw new Error('Event delivery failed')
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
const { spawn } = require('child_process')
|
|
2
|
-
const Session = require('../../db/session')
|
|
3
|
-
const workerEnvironment = require('./workerEnvironment')
|
|
4
|
-
|
|
5
|
-
// CLI delivery owns no network handles. Credentials are read by the worker.
|
|
6
|
-
module.exports = function createBackground (options = {}) {
|
|
7
|
-
if (process.env.DOTENVX_NO_ARMOR === 'true' || options.armor === false || options.noArmor === true) return
|
|
8
|
-
const session = new Session()
|
|
9
|
-
if (!options.token && (!session.on() || !session.username())) return
|
|
10
|
-
// Capture before run loads application environment values.
|
|
11
|
-
const env = workerEnvironment()
|
|
12
|
-
// pkg otherwise treats the first child argument as a JavaScript entrypoint.
|
|
13
|
-
// Relaunch the embedded CLI so _deliver-events remains a command.
|
|
14
|
-
if (process.pkg) env.PKG_EXECPATH = ''
|
|
15
|
-
const cwd = process.cwd()
|
|
16
|
-
const args = process.pkg ? [] : [process.argv[1]]
|
|
17
|
-
const token = options.token
|
|
18
|
-
let queue = []
|
|
19
|
-
let closing
|
|
20
|
-
|
|
21
|
-
function flush () {
|
|
22
|
-
if (!queue.length) return Promise.resolve()
|
|
23
|
-
const events = queue
|
|
24
|
-
queue = []
|
|
25
|
-
return new Promise(resolve => {
|
|
26
|
-
let child
|
|
27
|
-
let timer
|
|
28
|
-
const done = () => { clearTimeout(timer); resolve() }
|
|
29
|
-
try {
|
|
30
|
-
child = spawn(process.execPath, [...args, '_deliver-events'], {
|
|
31
|
-
cwd, env, detached: true, windowsHide: true, stdio: ['pipe', 'ignore', 'ignore']
|
|
32
|
-
})
|
|
33
|
-
child.on('error', done)
|
|
34
|
-
child.stdin.on('error', done)
|
|
35
|
-
child.unref()
|
|
36
|
-
child.stdin.unref()
|
|
37
|
-
// Only wait for the local pipe write, never worker startup or HTTP.
|
|
38
|
-
timer = setTimeout(() => { child.stdin.destroy(); done() }, 25)
|
|
39
|
-
child.stdin.end(JSON.stringify({ options: { token }, events }), done)
|
|
40
|
-
} catch { done() }
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
write (event, terminal = false) {
|
|
46
|
-
if (closing) return
|
|
47
|
-
if (queue.length >= 256) {
|
|
48
|
-
if (terminal) queue.pop()
|
|
49
|
-
else return
|
|
50
|
-
}
|
|
51
|
-
queue.push(event)
|
|
52
|
-
},
|
|
53
|
-
flush,
|
|
54
|
-
close () {
|
|
55
|
-
if (!closing) closing = flush()
|
|
56
|
-
return closing
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// Register public operations here. Internal helpers keep the caller's recorder.
|
|
2
|
-
module.exports = {
|
|
3
|
-
'cli/run': {},
|
|
4
|
-
'cli/get': { keyArgument: true },
|
|
5
|
-
'cli/set': { keyArgument: true },
|
|
6
|
-
'cli/del': { keyArgument: true },
|
|
7
|
-
'cli/encrypt': {},
|
|
8
|
-
'cli/decrypt': {},
|
|
9
|
-
'cli/keypair': { keyArgument: true },
|
|
10
|
-
'cli/protect': {},
|
|
11
|
-
'sdk/config': {},
|
|
12
|
-
'sdk/get': { keyArgument: true },
|
|
13
|
-
'sdk/set': { keyArgument: true }
|
|
14
|
-
}
|