15 lines
src/config/clientRegistry.ts
Builds the client config map that RateLimiterMiddleware reads at startup.
// Client registry — maps API keys to their rate-limit quota and subscription tier.import type { ClientConfig } from "../middleware/rateLimiter";// Parameters: none — reads CLIENT_CONFIG_JSON env var or falls back to defaults.// Returns: Map from API key string to ClientConfig with quota, plan, and tier.export function buildClientRegistry(): Map<string, ClientConfig> { const raw = process.env.CLIENT_CONFIG_JSON; if (!raw) { return new Map([ ["key-dev", { quota: 10, plan: "developer", tier: 0 }],]);
}
const entries = JSON.parse(raw) as Array<{ key: string } & ClientConfig>; return new Map(entries.map(({ key, ...cfg }) => [key, cfg]));}