refactor(auth): share api key masking utility

This commit is contained in:
Peter Steinberger
2026-02-18 17:13:35 +00:00
parent 3138dbaf75
commit 288015a9fc
4 changed files with 30 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
import { colorize, isRich as isRichTerminal, theme } from "../../terminal/theme.js";
export { maskApiKey } from "../../utils/mask-api-key.js";
export const isRich = (opts?: { json?: boolean; plain?: boolean }) =>
Boolean(isRichTerminal() && !opts?.json && !opts?.plain);
@@ -55,14 +56,3 @@ export const truncate = (value: string, max: number) => {
}
return `${value.slice(0, max - 3)}...`;
};
export const maskApiKey = (value: string): string => {
const trimmed = value.trim();
if (!trimmed) {
return "missing";
}
if (trimmed.length <= 16) {
return trimmed;
}
return `${trimmed.slice(0, 8)}...${trimmed.slice(-8)}`;
};