@x2d/azure-ai-nest
v0.1.3
Published
NestJS Global Module wrapping @azure/ai-projects
Readme
@x2d/azure-ai-nest
Global NestJS module that wraps [@azure/ai-projects] so you can inject an
AIProjectsClientanywhere in your app with one line of code.
✨ Why use it?
- One‑liner registration (
forRoot/forRootAsync). - Works with connection string or endpoint + credential.
- Exposes a single, typed injection token (
AZURE_AI_CLIENT). - Fully compatible with Nest 10 (CJS) and Nest 11+ (ESM).
- Auto‑disposes the SDK on app shutdown to free sockets (handy in tests).
🚀 Installation
# choose your package manager
npm i @x2d/azure-ai-nest
@nestjs/common≥ 10 is listed as a peer dependency – it’s already in every Nest project.
⚡️ Quick start
1 – Register the module
// app.module.ts
import { Module } from '@nestjs/common';
import { AzureAiModule } from '@x2d/azure-ai-nest';
@Module({
imports: [
// ✅ Sync factory (hard‑coded)
AzureAiModule.forRoot({ connectionString: process.env.AZURE_AI_PROJECTS_CONNECTION_STRING! }),
// ✅ or Async factory (config service, secrets, etc.)
AzureAiModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (cfg: ConfigService) => ({
endpoint: cfg.get<string>('AZURE_AI_PROJECTS_CONNECTION_STRING'),
credential: undefined, // fallback to DefaultAzureCredential chain
}),
}),
],
})
export class AppModule {}2 – Inject the client anywhere
@Injectable()
export class MyService {
constructor(@Inject(AZURE_AI_CLIENT) private readonly ai: AIProjectsClient) {}
async listProjects() {
return this.ai.listProjects();
}
}📝 License
MIT © X2D
