@theholocron/kyber 5.0.0-alpha.366 → 5.0.0-alpha.368
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 -3
- package/dist/secrets.mjs +11 -3
- package/package.json +7 -7
package/dist/secrets.d.mts
CHANGED
|
@@ -289,6 +289,16 @@ export declare function createKeyring(options: KeyringOptions): Keyring;
|
|
|
289
289
|
* text is written; it is a parameter so a test can make the write fail.
|
|
290
290
|
*/
|
|
291
291
|
export declare function createPrivateFile(path: string, text: string, write?: (fd: number, text: string) => unknown): FileIdentity;
|
|
292
|
+
/** Options for `resolveValue`. */
|
|
293
|
+
interface ResolveValueOptions {
|
|
294
|
+
/**
|
|
295
|
+
* An upper-case prefix without a trailing underscore (`"HOLOCRON"`). Each name is then tried as `<prefix>_<name>`
|
|
296
|
+
* and then as the bare `<name>`, in both the environment and the `credentials` providers' variables, so a caller
|
|
297
|
+
* names the variable once instead of listing the pair. A name that already starts with `<prefix>_` is tried as it
|
|
298
|
+
* is, not prefixed twice.
|
|
299
|
+
*/
|
|
300
|
+
prefix?: string;
|
|
301
|
+
}
|
|
292
302
|
/**
|
|
293
303
|
* Finds a plain, non-secret value (an account id, a dataset, a project slug) through the same chain the token
|
|
294
304
|
* resolvers use, without the flag and the keyring: the variables of `env` (the process environment when none is
|
|
@@ -297,13 +307,15 @@ export declare function createPrivateFile(path: string, text: string, write?: (f
|
|
|
297
307
|
*
|
|
298
308
|
* @param names - The variable names to try, the tool's own before the vendor's.
|
|
299
309
|
* @param env - The environment to read. Default `process.env`; a test passes its own.
|
|
310
|
+
* @param options - `prefix` makes each name a `<prefix>_<name>` then bare `<name>` pair (see {@link ResolveValueOptions}).
|
|
300
311
|
*
|
|
301
312
|
* @example
|
|
302
313
|
* ```ts
|
|
303
|
-
*
|
|
314
|
+
* // HOLOCRON_CLOUDFLARE_ACCOUNT_ID, then CLOUDFLARE_ACCOUNT_ID
|
|
315
|
+
* const accountId = options.accountId ?? resolveValue(["CLOUDFLARE_ACCOUNT_ID"], options.env, { prefix: "HOLOCRON" });
|
|
304
316
|
* ```
|
|
305
317
|
*/
|
|
306
|
-
export declare function resolveValue(names: readonly string[], env?: Record<string, string | undefined
|
|
318
|
+
export declare function resolveValue(names: readonly string[], env?: Record<string, string | undefined>, options?: ResolveValueOptions): string | undefined;
|
|
307
319
|
/**
|
|
308
320
|
* Overwrite the file `identity` names with zeros, close it, and remove it from `path`, so the tokens it held are not
|
|
309
321
|
* left in a deleted-but-recoverable file.
|
|
@@ -320,4 +332,4 @@ export declare function resolveValue(names: readonly string[], env?: Record<stri
|
|
|
320
332
|
* `remove` is how the path is deleted; it is a parameter so a test can look at the file just before it goes.
|
|
321
333
|
*/
|
|
322
334
|
export declare function shredFile(path: string, identity: FileIdentity, remove?: (path: string) => void): ShredOutcome;
|
|
323
|
-
export type { FeatureResolverConfig, FeatureTokenResolver, FileIdentity, FinishCredentialsFileInput, GitIgnoreState, Keyring, KeyringBinding, KeyringEntry, KeyringOptions, ParsedTokenArgs, ResolveTokenConfig, ResolveTokenInput, ShredOutcome, TokenResolver };
|
|
335
|
+
export type { FeatureResolverConfig, FeatureTokenResolver, FileIdentity, FinishCredentialsFileInput, GitIgnoreState, Keyring, KeyringBinding, KeyringEntry, KeyringOptions, ParsedTokenArgs, ResolveTokenConfig, ResolveTokenInput, ResolveValueOptions, ShredOutcome, TokenResolver };
|
package/dist/secrets.mjs
CHANGED
|
@@ -460,6 +460,11 @@ function createResolveToken(config) {
|
|
|
460
460
|
};
|
|
461
461
|
}
|
|
462
462
|
// src/secrets/resolve-value/resolve-value.ts
|
|
463
|
+
/** `names` with each one preceded by its `<prefix>_` spelling; unchanged when there is no prefix. */
|
|
464
|
+
function withPrefix(names, prefix) {
|
|
465
|
+
if (!prefix) return [...names];
|
|
466
|
+
return names.flatMap((name) => name.startsWith(`${prefix}_`) ? [name] : [`${prefix}_${name}`, name]);
|
|
467
|
+
}
|
|
463
468
|
/**
|
|
464
469
|
* Finds a plain, non-secret value (an account id, a dataset, a project slug) through the same chain the token
|
|
465
470
|
* resolvers use, without the flag and the keyring: the variables of `env` (the process environment when none is
|
|
@@ -468,13 +473,16 @@ function createResolveToken(config) {
|
|
|
468
473
|
*
|
|
469
474
|
* @param names - The variable names to try, the tool's own before the vendor's.
|
|
470
475
|
* @param env - The environment to read. Default `process.env`; a test passes its own.
|
|
476
|
+
* @param options - `prefix` makes each name a `<prefix>_<name>` then bare `<name>` pair (see {@link ResolveValueOptions}).
|
|
471
477
|
*
|
|
472
478
|
* @example
|
|
473
479
|
* ```ts
|
|
474
|
-
*
|
|
480
|
+
* // HOLOCRON_CLOUDFLARE_ACCOUNT_ID, then CLOUDFLARE_ACCOUNT_ID
|
|
481
|
+
* const accountId = options.accountId ?? resolveValue(["CLOUDFLARE_ACCOUNT_ID"], options.env, { prefix: "HOLOCRON" });
|
|
475
482
|
* ```
|
|
476
483
|
*/
|
|
477
|
-
function resolveValue(names, env) {
|
|
478
|
-
|
|
484
|
+
function resolveValue(names, env, options = {}) {
|
|
485
|
+
const tried = withPrefix(names, options.prefix);
|
|
486
|
+
return firstEnv(env, ...tried) ?? getCredential(...tried);
|
|
479
487
|
}
|
|
480
488
|
export { AuthError, DOTENV_FILE, TokenParseError, clearCredentials, copyToClipboard, createFeatureResolver, createKeyring, createPrivateFile, createResolveToken, dotenvLine, findCredential, 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.368",
|
|
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",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"dist"
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@theholocron/env-utils": "^1.17.0-alpha.
|
|
88
|
+
"@theholocron/env-utils": "^1.17.0-alpha.2"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@inquirer/prompts": "^8.7.5",
|
|
@@ -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.366",
|
|
109
|
-
"@theholocron/eslint-config": "^8.9.0-alpha.11",
|
|
110
|
-
"@theholocron/tsconfig": "^8.9.0-alpha.11",
|
|
111
108
|
"@theholocron/observability": "0.7.0-alpha.2",
|
|
109
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.11",
|
|
112
110
|
"@theholocron/vitest-config": "^8.9.0-alpha.11",
|
|
113
|
-
"@theholocron/tsdown-config": "^8.9.0-alpha.11"
|
|
111
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.11",
|
|
112
|
+
"@theholocron/datapad": "5.0.0-alpha.368",
|
|
113
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.11"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
116
|
"@inquirer/prompts": "^8.0.0",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"dotenv": "^17.0.0",
|
|
122
122
|
"ora": "^9.0.0",
|
|
123
123
|
"yargs": "^18.0.0",
|
|
124
|
-
"@theholocron/datapad": "^5.0.0-alpha.
|
|
124
|
+
"@theholocron/datapad": "^5.0.0-alpha.368",
|
|
125
125
|
"@theholocron/observability": "^0.7.0-alpha.2"
|
|
126
126
|
},
|
|
127
127
|
"peerDependenciesMeta": {
|