Frameworks
NestJS — Intégration Scell.io
Module NestJS + DI provider via @scell/sdk
Le SDK `@scell/sdk` v3.5.0 s'intègre dans NestJS via un Module dynamique exposant le client comme provider injectable. Pattern : `ScellModule.forRoot({ apiKey })` dans `AppModule`, injection `@Inject('SCELL_CLIENT')` dans les services. Compatible avec les Guards, Interceptors et Pipes NestJS. Idéal pour architectures hexagonales (port/adapter).
À retenir
- Module dynamique `ScellModule.forRoot()`
- Provider injectable via `@Inject('SCELL_CLIENT')`
- Compatible avec @nestjs/config (env vars)
- Pattern Port/Adapter pour testabilité
- Support NestJS 10 et 11
Exemple de code
import { Module, Injectable, Inject } from '@nestjs/common';
import { ScellClient } from '@scell/sdk';
@Module({
providers: [{
provide: 'SCELL_CLIENT',
useFactory: () => new ScellClient({ apiKey: process.env.SCELL_API_KEY! }),
}],
exports: ['SCELL_CLIENT'],
})
export class ScellModule {}
@Injectable()
export class InvoiceService {
constructor(@Inject('SCELL_CLIENT') private scell: ScellClient) {}
async create(amount: number) {
return this.scell.invoices.create({
format: 'factur-x',
lines: [{ description: 'Service', quantity: 1, unit_price: amount, vat_rate: 20.0 }],
});
}
}