@theholocron/kyber 5.0.0-alpha.352 → 5.0.0-alpha.353
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/secrets.d.mts +15 -0
- package/dist/secrets.mjs +22 -3
- package/package.json +6 -6
package/dist/secrets.d.mts
CHANGED
|
@@ -278,6 +278,21 @@ export declare function createKeyring(options: KeyringOptions): Keyring;
|
|
|
278
278
|
* text is written; it is a parameter so a test can make the write fail.
|
|
279
279
|
*/
|
|
280
280
|
export declare function createPrivateFile(path: string, text: string, write?: (fd: number, text: string) => unknown): FileIdentity;
|
|
281
|
+
/**
|
|
282
|
+
* Finds a plain, non-secret value (an account id, a dataset, a project slug) through the same chain the token
|
|
283
|
+
* resolvers use, without the flag and the keyring: the variables of `env` (the process environment when none is
|
|
284
|
+
* given), then the variables the `credentials` providers returned (see {@link setCredentials}). A name is tried in the
|
|
285
|
+
* order given in each source. An empty string counts as unset. `undefined` when no source has one.
|
|
286
|
+
*
|
|
287
|
+
* @param names - The variable names to try, the tool's own before the vendor's.
|
|
288
|
+
* @param env - The environment to read. Default `process.env`; a test passes its own.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const accountId = options.accountId ?? resolveValue(["CLOUDFLARE_ACCOUNT_ID"], options.env);
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
export declare function resolveValue(names: readonly string[], env?: Record<string, string | undefined>): string | undefined;
|
|
281
296
|
/**
|
|
282
297
|
* Overwrite the file `identity` names with zeros, close it, and remove it from `path`, so the tokens it held are not
|
|
283
298
|
* left in a deleted-but-recoverable file.
|
package/dist/secrets.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { createRequire } from "node:module";
|
|
|
5
5
|
import { basename, dirname, join } from "node:path";
|
|
6
6
|
import { execFileSync } from "node:child_process";
|
|
7
7
|
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, openSync, readFileSync, renameSync, unlinkSync, writeSync } from "node:fs";
|
|
8
|
+
import { createEnvLookup } from "@theholocron/env-utils/lookup";
|
|
8
9
|
import { randomBytes } from "node:crypto";
|
|
9
10
|
import { parse } from "dotenv";
|
|
10
11
|
// src/secrets/auth-error/auth-error.ts
|
|
@@ -227,9 +228,9 @@ function dotenvLine(name, value) {
|
|
|
227
228
|
* as unset, so a blank `TOKEN=` line does not hide the next name.
|
|
228
229
|
*/
|
|
229
230
|
function firstEnv(env, ...names) {
|
|
230
|
-
const
|
|
231
|
+
const lookup = createEnvLookup(env);
|
|
231
232
|
for (const name of names) {
|
|
232
|
-
const value =
|
|
233
|
+
const value = lookup.get(name);
|
|
233
234
|
if (value) return value;
|
|
234
235
|
}
|
|
235
236
|
}
|
|
@@ -450,4 +451,22 @@ function createResolveToken(config) {
|
|
|
450
451
|
return token;
|
|
451
452
|
};
|
|
452
453
|
}
|
|
453
|
-
|
|
454
|
+
// src/secrets/resolve-value/resolve-value.ts
|
|
455
|
+
/**
|
|
456
|
+
* Finds a plain, non-secret value (an account id, a dataset, a project slug) through the same chain the token
|
|
457
|
+
* resolvers use, without the flag and the keyring: the variables of `env` (the process environment when none is
|
|
458
|
+
* given), then the variables the `credentials` providers returned (see {@link setCredentials}). A name is tried in the
|
|
459
|
+
* order given in each source. An empty string counts as unset. `undefined` when no source has one.
|
|
460
|
+
*
|
|
461
|
+
* @param names - The variable names to try, the tool's own before the vendor's.
|
|
462
|
+
* @param env - The environment to read. Default `process.env`; a test passes its own.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* const accountId = options.accountId ?? resolveValue(["CLOUDFLARE_ACCOUNT_ID"], options.env);
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
function resolveValue(names, env) {
|
|
470
|
+
return firstEnv(env, ...names) ?? getCredential(...names);
|
|
471
|
+
}
|
|
472
|
+
export { AuthError, DOTENV_FILE, TokenParseError, clearCredentials, copyToClipboard, createFeatureResolver, createKeyring, createPrivateFile, createResolveToken, dotenvLine, finishCredentialsFile, getCredential, hasCredentials, isGitIgnored, parseTokenArgs, readDotenvFile, resolveValue, setCredentials, shredFile, writeCredentialsFile };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/kyber",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.353",
|
|
4
4
|
"description": "The reusable parts of a command-line tool: terminal output, prompts, the interactive menu, the update notifier, safe handling of tokens, a test harness and the global flags.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -105,12 +105,12 @@
|
|
|
105
105
|
"typescript": "^5.9.3",
|
|
106
106
|
"vitest": "^5.0.5",
|
|
107
107
|
"yargs": "^18.1.0",
|
|
108
|
+
"@theholocron/datapad": "5.0.0-alpha.353",
|
|
109
|
+
"@theholocron/observability": "0.7.0-alpha.1",
|
|
108
110
|
"@theholocron/eslint-config": "^8.9.0-alpha.8",
|
|
109
|
-
"@theholocron/datapad": "5.0.0-alpha.352",
|
|
110
|
-
"@theholocron/tsconfig": "^8.9.0-alpha.8",
|
|
111
111
|
"@theholocron/tsdown-config": "^8.9.0-alpha.8",
|
|
112
112
|
"@theholocron/vitest-config": "^8.9.0-alpha.8",
|
|
113
|
-
"@theholocron/
|
|
113
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.8"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
116
|
"@inquirer/prompts": "^8.0.0",
|
|
@@ -121,8 +121,8 @@
|
|
|
121
121
|
"dotenv": "^17.0.0",
|
|
122
122
|
"ora": "^9.0.0",
|
|
123
123
|
"yargs": "^18.0.0",
|
|
124
|
-
"@theholocron/
|
|
125
|
-
"@theholocron/
|
|
124
|
+
"@theholocron/datapad": "^5.0.0-alpha.353",
|
|
125
|
+
"@theholocron/observability": "^0.7.0-alpha.1"
|
|
126
126
|
},
|
|
127
127
|
"peerDependenciesMeta": {
|
|
128
128
|
"@inquirer/prompts": {
|