From 40d577dd30bd3d383847e0234139febd78861641 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Sun, 2 Aug 2026 21:05:32 +0530 Subject: [PATCH] fix: code quality and safety improvements --- src/router/apiKeyManager.ts | 4 ++-- src/router/modelRouter.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/router/apiKeyManager.ts b/src/router/apiKeyManager.ts index 12e5d23..e906490 100644 --- a/src/router/apiKeyManager.ts +++ b/src/router/apiKeyManager.ts @@ -10,10 +10,10 @@ export class ApiKeyManager { * Register an API key for a provider */ public registerKey(provider: string, apiKey: string): void { - if (!provider || typeof provider !== 'string' || provider.trim() === '') { + if (!provider || typeof provider !== 'string' || provider.trim().length === 0) { throw new Error('TokenFirewall: Provider must be a non-empty string'); } - if (!apiKey || typeof apiKey !== 'string' || apiKey.trim() === '') { + if (!apiKey || typeof apiKey !== 'string' || apiKey.trim().length === 0) { throw new Error(`TokenFirewall: Invalid API key for provider "${provider}"`); } this.keys.set(provider.toLowerCase(), apiKey); diff --git a/src/router/modelRouter.ts b/src/router/modelRouter.ts index 4b6f8ea..de6a573 100644 --- a/src/router/modelRouter.ts +++ b/src/router/modelRouter.ts @@ -64,7 +64,7 @@ export class ModelRouter { // Validate each fallback model name for (const fallbackModel of fallbacks) { - if (typeof fallbackModel !== 'string' || fallbackModel.trim() === '') { + if (typeof fallbackModel !== 'string' || fallbackModel.trim().length === 0) { throw new Error( `TokenFirewall Router: fallbackMap for "${model}" contains invalid model name (empty or whitespace)` );