- 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
25 lines
659 B
TypeScript
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);
|
|
}
|