UNPKG

@decaf-ts/utils

Version:

module management utils for decaf-ts

122 lines (121 loc) 3.84 kB
import { LoggingConfig } from "@decaf-ts/logging"; import { Command } from "../command.d.mts"; import { DefaultCommandValues } from "../constants.d.mts"; /** * @description Default secret definitions used by the credentials command. * @summary Maps the well-known secret names to their env-var, keychain * service/account, and legacy plaintext-file defaults. Every field can be * overridden at runtime via flags so custom secrets are fully supported. * @const DEFAULT_SECRETS * @memberOf module:utils */ export declare const DEFAULT_SECRETS: Record<string, { env: string; service: string; account: string; legacyFile: string; }>; type SecretSpec = { env: string; service: string; account: string; legacyFile: string; }; declare const options: { action: { type: string; short: string; default: string; }; name: { type: string; short: string; default: string; }; value: { type: string; short: string; default: undefined; }; envVar: { type: string; default: undefined; }; service: { type: string; default: undefined; }; account: { type: string; default: undefined; }; legacyFile: { type: string; default: undefined; }; rm: { type: string; short: string; default: boolean; }; }; /** * @description Resolves a secret using the same resolution order as CredentialsCommand. * @summary Tries environment variable → OS keychain → legacy plaintext file, returning * the first hit. Throws if no source provides a value. * @param {string} name - Secret name (npm, github, confluence, or custom). * @param {Partial<SecretSpec>} [overrides] - Optional overrides for env-var, service, account, or legacyFile. * @returns {string} The resolved secret value. * @function resolveSecret * @memberOf module:utils */ export declare function resolveSecret(name: string, overrides?: Partial<SecretSpec>): string; /** * @description Checks whether a secret can be resolved without throwing. * @summary Returns true if any source (env var, keychain, legacy file) provides a value. * @param {string} name - Secret name. * @param {Partial<SecretSpec>} [overrides] - Optional overrides. * @returns {boolean} Whether the secret is available. * @function hasSecret * @memberOf module:utils */ export declare function hasSecret(name: string, overrides?: Partial<SecretSpec>): boolean; /** * @description Command-line tool for managing secrets via the OS keychain. * @summary Provides a secure alternative to plaintext token files by resolving * secrets from environment variables, the OS keychain (macOS Keychain, Linux * libsecret/`keyring`), or — as a deprecated fallback — legacy plaintext files. * Supports `get`, `store`, `setup`, and `git-helper` actions. * * @class CredentialsCommand * @extends {Command} * * @example * ```sh * # Resolve the npm token (prints to stdout) * credentials --action get --name npm * * # Store a custom secret in the keychain * credentials --action store --name my-api --service "my-app:api" --account "default" --value "secret123" * * # Interactive one-time enrollment * credentials --action setup * * # Configure the OS-native git credential helper * credentials --action git-helper * ``` */ export declare class CredentialsCommand extends Command<typeof options, void> { constructor(); private resolveSpec; protected help(): void; private doGet; private doStore; private doSetup; private deleteLegacyFiles; private configureGitHelper; protected run(answers: LoggingConfig & typeof DefaultCommandValues & { [k in keyof typeof options]: unknown; }): Promise<void>; } export {};