@neon/env 1.5.0 → 1.5.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/dist/cli.js +17 -9
- package/dist/cli.js.map +1 -1
- package/dist/env.js +45 -17
- package/dist/env.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -44,9 +44,9 @@ import { homedir } from "node:os";
|
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
46
|
async function fetchEnvReusingSecrets(config, options) {
|
|
47
|
-
const { env: source = process.env, keys: requestedKeys, revokeSuperseded = true, ...fetchOptions } = options;
|
|
47
|
+
const { env: source = process.env, keys: requestedKeys, revokeSuperseded = true, resolvedBranch, ...fetchOptions } = options;
|
|
48
48
|
const api = options.api ?? createApiFromOptions(options);
|
|
49
|
-
const { branch, desired } = await resolveBranchPolicy(config, options, api);
|
|
49
|
+
const { branch, desired } = await resolveBranchPolicy(config, options, api, resolvedBranch);
|
|
50
50
|
const allPolicyKeys = policyEnvKeys(desired);
|
|
51
51
|
const requested = requestedKeys ? new Set(requestedKeys) : null;
|
|
52
52
|
const selectedPolicyKeys = requested === null ? allPolicyKeys : [...allPolicyKeys.filter((key) => requested.has(key)), ...[...requested].filter(isFunctionBaseUrlKey).sort()];
|
|
@@ -59,12 +59,16 @@ async function fetchEnvReusingSecrets(config, options) {
|
|
|
59
59
|
aiGateway: gatewayCredentialSelected
|
|
60
60
|
}).filter((key) => selected.has(key));
|
|
61
61
|
if (secretKeys.length === 0) {
|
|
62
|
-
const fetched = await fetchEnvKeysState(config, fetchOptions, requested === null ? null : selectedPolicyKeys
|
|
62
|
+
const fetched = await fetchEnvKeysState(config, fetchOptions, requested === null ? null : selectedPolicyKeys, {
|
|
63
|
+
branch,
|
|
64
|
+
desired
|
|
65
|
+
});
|
|
63
66
|
return {
|
|
64
67
|
vars: preferPersisted(toEntries(fetched.env), source),
|
|
65
68
|
credential: {
|
|
66
69
|
issued: false,
|
|
67
70
|
keys: [],
|
|
71
|
+
fresh: [],
|
|
68
72
|
revoked: [],
|
|
69
73
|
superseded: []
|
|
70
74
|
},
|
|
@@ -93,10 +97,12 @@ async function fetchEnvReusingSecrets(config, options) {
|
|
|
93
97
|
const fetchKeys = requested === null ? null : selectedPolicyKeys.filter((key) => !keptSecretKeys.includes(key));
|
|
94
98
|
const fetched = await fetchEnvKeysState(config, {
|
|
95
99
|
...fetchOptions,
|
|
96
|
-
branchId: branch.id,
|
|
97
100
|
api,
|
|
98
101
|
...keptSecretKeys.length > 0 && requested === null ? { omitKeys: keptSecretKeys } : {}
|
|
99
|
-
}, fetchKeys
|
|
102
|
+
}, fetchKeys, {
|
|
103
|
+
branch,
|
|
104
|
+
desired
|
|
105
|
+
});
|
|
100
106
|
const vars = preferPersisted(toEntries(fetched.env), source);
|
|
101
107
|
const unavailable = fetched.functionUrlsUnavailable ? { functionUrlsUnavailable: true } : {};
|
|
102
108
|
for (const key of keptSecretKeys) {
|
|
@@ -108,6 +114,7 @@ async function fetchEnvReusingSecrets(config, options) {
|
|
|
108
114
|
credential: {
|
|
109
115
|
issued: false,
|
|
110
116
|
keys: secretKeys,
|
|
117
|
+
fresh: [],
|
|
111
118
|
revoked: [],
|
|
112
119
|
superseded: []
|
|
113
120
|
},
|
|
@@ -121,6 +128,7 @@ async function fetchEnvReusingSecrets(config, options) {
|
|
|
121
128
|
credential: {
|
|
122
129
|
issued: true,
|
|
123
130
|
keys: secretKeys,
|
|
131
|
+
fresh: secretKeys.filter((key) => !keptSecretKeys.includes(key)),
|
|
124
132
|
revoked: revokeSuperseded ? [...ours] : [],
|
|
125
133
|
superseded: revokeSuperseded ? [] : [...ours]
|
|
126
134
|
},
|
|
@@ -450,7 +458,7 @@ const inspectProfiles = (dir) => {
|
|
|
450
458
|
*
|
|
451
459
|
* A malformed file is reported through `onWarn` and treated as absent, because for a *read* the
|
|
452
460
|
* worst case is a named profile turning up missing, which is recoverable — whereas throwing
|
|
453
|
-
* would lock the user out of `neon
|
|
461
|
+
* would lock the user out of `neon login` itself. Writing is the opposite: see
|
|
454
462
|
* {@link upsertProfile}, which refuses rather than rebuilding a file it cannot read.
|
|
455
463
|
*/
|
|
456
464
|
const readProfiles = (dir, onWarn = () => {}) => {
|
|
@@ -690,7 +698,7 @@ var KeyringUnavailableError = class extends Error {
|
|
|
690
698
|
};
|
|
691
699
|
var KeyringUnreadableError = class extends Error {
|
|
692
700
|
constructor(profile) {
|
|
693
|
-
const replace = `\`neon
|
|
701
|
+
const replace = `\`neon login --profile ${profile}\``;
|
|
694
702
|
super(`Could not read the OS keyring item for profile "${profile}". Unlock the keyring and retry, or run ${replace}. To reset the profile: \`neon profile remove ${profile} --yes\`.`);
|
|
695
703
|
this.name = "KeyringUnreadableError";
|
|
696
704
|
}
|
|
@@ -993,7 +1001,7 @@ function readStoredCredential(selection, env) {
|
|
|
993
1001
|
if (credential.kind === "api_key") return credential.apiKey;
|
|
994
1002
|
const token = loaded.credentials.access_token;
|
|
995
1003
|
if (typeof token === "string" && token.trim() !== "") return token.trim();
|
|
996
|
-
throw new Error(`Profile "${profile}" holds a browser sign-in with no usable token at ${credentialLabel(at)}. Sign in again with \`neon
|
|
1004
|
+
throw new Error(`Profile "${profile}" holds a browser sign-in with no usable token at ${credentialLabel(at)}. Sign in again with \`neon login --profile ${profile}\`.`);
|
|
997
1005
|
}
|
|
998
1006
|
//#endregion
|
|
999
1007
|
//#region src/lib/cli/resolve-context.ts
|
|
@@ -1282,7 +1290,7 @@ function handleError(err) {
|
|
|
1282
1290
|
"No Neon API key. `neon-env` looks for one in this order:",
|
|
1283
1291
|
" - the `--api-key` flag",
|
|
1284
1292
|
" - the `NEON_API_KEY` environment variable",
|
|
1285
|
-
" - `credentials.json` in `NEONCTL_CONFIG_DIR` (else `~/.config/neonctl`) — run `neon
|
|
1293
|
+
" - `credentials.json` in `NEONCTL_CONFIG_DIR` (else `~/.config/neonctl`) — run `neon login` to create it"
|
|
1286
1294
|
].join("\n"), EXIT_CODE_BY_PLATFORM_ERROR_CODE[ErrorCode.MissingApiKey] ?? 1);
|
|
1287
1295
|
if (err instanceof PlatformError) {
|
|
1288
1296
|
const exitCode = EXIT_CODE_BY_PLATFORM_ERROR_CODE[err.code];
|