0.13.0 • Published 1 year ago
@peersyst/unleash-module v0.13.0
Description
Nest framework TypeScript base unleash module.
Installation
$ npm install --save @peersyst/unleash-module
How to use it
Unleash module import config
- Import and register UnleashModule in AppModule
import { Module } from "@nestjs/common";
import { UnleashModule } from "@peersyst/unleash-module";
@Module({
imports: [
ConfigModule.forRoot(...),
UnleashModule.register(ConfigModule),
...
],
...
})
export class AppModule {}
- Add configService configuration variables
export default (): any => ({
unleash: {
appName: process.env.UNLEASH_APP_NAME,
url: process.env.UNLEASH_URL,
environment: process.env.UNLEASH_ENVIRONMENT,
apiToken: process.env.UNLEASH_API_TOKEN,
},
});
- Add UnleashModule in module where will be used
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { UnleashModule } from "@peersyst/unleash-module";
@Module({
imports: [
ConfigModule.forRoot(...),
UnleashModule.register(ConfigModule),
...
],
...
})
export class CatModule {}
Decorate functions you want to toggle
- Inject UnleashService in the in the classes you want to use it
import { Inject, Controller, Get, Param } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { UnleashToggle } from "@peersyst/unleash-module";
import { CatService } from "./cat.service.ts"
import { CatDto, PaginatedCatDto } from "./cat.dto.ts"
@ApiTags("cats")
@Controller("cat")
@UnleashToggle("cat-controller")
export class CatController {
constructor(
@Inject("CatService") private readonly catService: CatService,
)
@Get("")
async getAllCats(): Promise<PaginatedCatDto> {
return this.catService.getAllCats();
}
@UnleashToggle("get-cat")
@Get(":id")
async getCat(@Param("id") id: number): Promise<CatDto> {
return this.catService.getCat(id);
}
}
License
Nest is MIT licensed.