learning_ai_common_plat/services/platform-service/src/lib/cosmos.ts
saravanakumardb1 e1ab956ac3 feat(services): add platform-service (auth, audit, flags, notifications, blob)
- Copied as-is from learning_voice_ai_agent/services/platform-service
- 55 tests passing (vitest)
- Fastify 5 + Cosmos DB + jose + bcryptjs + Zod
- Modules: auth, audit, flags, notifications, blob, ratelimit
- Port 4003
2026-02-12 11:39:00 -08:00

25 lines
659 B
TypeScript

/**
* Shared Cosmos DB client for the Platform Service.
*/
import { CosmosClient, Container } from "@azure/cosmos";
let client: CosmosClient | null = null;
function getClient(): CosmosClient {
if (!client) {
const endpoint = process.env.COSMOS_ENDPOINT;
const key = process.env.COSMOS_KEY;
if (!endpoint || !key) {
throw new Error("COSMOS_ENDPOINT and COSMOS_KEY must be set");
}
client = new CosmosClient({ endpoint, key });
}
return client;
}
export function getContainer(name: string): Container {
const database = process.env.COSMOS_DATABASE || "lysnrai";
return getClient().database(database).container(name);
}