Files
tiennm99 3eda216dc6 feat(keys): store raw OpenRouter key and make it retrievable
Persist the raw key (migration 0002 adds openrouter_key) so users can copy it
again from the dashboard instead of a one-time-only reveal; admin console shows
the full key. Retain openrouter_key_hash for revocation. Keys remain in the
unexposed llmapikey schema (deny-all RLS, server-only direct connection).

- activate() stores the raw key; dashboard + generate-key return the full key.
- key-display warning updated (no longer shown-once).
- admin table renders the full key.
2026-06-14 14:10:46 +07:00

27 lines
668 B
JavaScript

/**
* Pure key formatting helpers. No secrets, no I/O — safe to import anywhere and
* unit-testable in isolation.
*/
/**
* Last 4 chars of a raw key, for masked display (e.g. the admin create toast).
*
* @param {string} rawKey
* @returns {string}
*/
export function last4(rawKey) {
if (typeof rawKey !== "string" || rawKey.length === 0) return "";
return rawKey.slice(-4);
}
/**
* Masked representation from a stored last-4 hint, e.g. "sk-or-v1-••••1234".
*
* @param {string | null | undefined} hint
* @returns {string}
*/
export function maskFromHint(hint) {
if (!hint) return "••••";
return `sk-or-v1-••••${hint}`;
}