0.13.0 • Published 1 year ago

@peersyst/unleash-module v0.13.0

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

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.

0.13.0

1 year ago

0.12.40

2 years ago

0.12.15

2 years ago

0.12.13

2 years ago

0.12.10

2 years ago

0.12.9

2 years ago

0.12.8

2 years ago

0.12.7

2 years ago

0.12.6

2 years ago

0.12.5

2 years ago

0.12.4

2 years ago

0.12.3

2 years ago

0.12.2

2 years ago

0.12.1

2 years ago

0.12.0

2 years ago

0.11.20

2 years ago