@@ -84,8 +84,6 @@ export interface ApiKeyMetadata {
8484 updated ?: string ;
8585 /** Whether this is the currently active key */
8686 isActive : boolean ;
87- /** Optional per-key environment overrides (extensible for future vars) */
88- env ?: Record < string , string > ;
8987 /** API key value (only present when not using Keychain storage) */
9088 apiKey ?: string ;
9189 /** Encrypted API key (Windows DPAPI) */
@@ -612,15 +610,13 @@ export class KeyManager {
612610 * @param name - User-friendly name for the key
613611 * @param apiKey - The Iterable API key value
614612 * @param baseUrl - Iterable API base URL
615- * @param envOverrides - Environment variable overrides. If undefined, keeps existing env (update) or no env (add). If provided (even empty {}), replaces/clears env.
616613 * @param idOrName - If provided, updates the existing key with this ID or name
617614 * @returns The ID of the saved key
618615 */
619616 private async saveKey (
620617 name : string ,
621618 apiKey : string ,
622619 baseUrl : string ,
623- envOverrides ?: Record < string , string > ,
624620 idOrName ?: string
625621 ) : Promise < string > {
626622 if ( ! this . store ) {
@@ -673,7 +669,6 @@ export class KeyManager {
673669 name,
674670 baseUrl,
675671 updated : new Date ( ) . toISOString ( ) ,
676- ...( envOverrides !== undefined ? { env : envOverrides } : { } ) ,
677672 } ;
678673 } else {
679674 metadata = {
@@ -682,7 +677,6 @@ export class KeyManager {
682677 baseUrl,
683678 created : new Date ( ) . toISOString ( ) ,
684679 isActive : this . store . keys . length === 0 ,
685- ...( envOverrides !== undefined ? { env : envOverrides } : { } ) ,
686680 } ;
687681 }
688682
@@ -758,42 +752,34 @@ export class KeyManager {
758752 * @param name - User-friendly name for the key (must be unique)
759753 * @param apiKey - 32-character lowercase hexadecimal Iterable API key
760754 * @param baseUrl - Iterable API base URL (must be HTTPS)
761- * @param envOverrides - Optional environment variable overrides for this key
762755 * @returns The unique ID generated for this key
763756 * @throws {Error } If the key name already exists, validation fails, or storage fails
764757 */
765- async addKey (
766- name : string ,
767- apiKey : string ,
768- baseUrl : string ,
769- envOverrides ?: Record < string , string >
770- ) : Promise < string > {
758+ async addKey ( name : string , apiKey : string , baseUrl : string ) : Promise < string > {
771759 await this . ensureStore ( ) ;
772- return this . saveKey ( name , apiKey , baseUrl , envOverrides ) ;
760+ return this . saveKey ( name , apiKey , baseUrl ) ;
773761 }
774762
775763 /**
776764 * Update an existing API key
777765 *
778- * Updates all properties of an existing key including name, API key value, base URL, and environment overrides .
766+ * Updates all properties of an existing key including name, API key value, and base URL .
779767 *
780768 * @param idOrName - The unique ID or name of the key to update
781769 * @param name - New name for the key (must be unique unless unchanged)
782770 * @param apiKey - New API key value (can be the same as existing)
783771 * @param baseUrl - New Iterable API base URL
784- * @param envOverrides - New environment variable overrides (undefined = keep existing, {} = clear)
785772 * @returns The ID of the updated key
786773 * @throws {Error } If the key is not found, name conflict, validation fails, or storage fails
787774 */
788775 async updateKey (
789776 idOrName : string ,
790777 name : string ,
791778 apiKey : string ,
792- baseUrl : string ,
793- envOverrides ?: Record < string , string >
779+ baseUrl : string
794780 ) : Promise < string > {
795781 await this . ensureStore ( ) ;
796- return this . saveKey ( name , apiKey , baseUrl , envOverrides , idOrName ) ;
782+ return this . saveKey ( name , apiKey , baseUrl , idOrName ) ;
797783 }
798784
799785 /**
@@ -891,12 +877,13 @@ export class KeyManager {
891877 { cause : error }
892878 ) ;
893879 }
894- } else if ( keyMeta . apiKey ) {
895- // Fallback for legacy keys stored in plaintext on Windows
896- return keyMeta . apiKey ;
897880 } else {
898- logger . error ( "Key not found in metadata" , { id : keyMeta . id } ) ;
899- throw new Error ( `Key not found in storage for ID ${ keyMeta . id } ` ) ;
881+ logger . error ( "Key not found in encrypted storage" , {
882+ id : keyMeta . id ,
883+ } ) ;
884+ throw new Error (
885+ `Key "${ keyMeta . name } " is not encrypted. Run "${ COMMAND_NAME } keys update ${ keyMeta . name } " to re-enter it securely.`
886+ ) ;
900887 }
901888
902889 default :
@@ -1113,8 +1100,6 @@ export class KeyManager {
11131100 case StorageMethod . DPAPI :
11141101 if ( keyMeta . encryptedApiKey ) {
11151102 storedKey = await this . decryptWindows ( keyMeta . encryptedApiKey ) ;
1116- } else if ( keyMeta . apiKey ) {
1117- storedKey = keyMeta . apiKey ;
11181103 } else {
11191104 continue ;
11201105 }
@@ -1148,8 +1133,5 @@ let keyManagerInstance: KeyManager | null = null;
11481133 * Get the singleton KeyManager instance
11491134 */
11501135export function getKeyManager ( ) : KeyManager {
1151- if ( ! keyManagerInstance ) {
1152- keyManagerInstance = new KeyManager ( ) ;
1153- }
1154- return keyManagerInstance ;
1136+ return ( keyManagerInstance ??= new KeyManager ( ) ) ;
11551137}
0 commit comments