1.0.3 • Published 9 months ago

nestjs-upstash-qstash v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

NestJS Qstash Module

Description

A Qstash client for NestJS

Installation

yarn add nestjs-upstash-qstash
npm i nestjs-upstash-qstash

Configuration

Entry module:

@Module({
  imports: [
    QstashModule.register({
      token: "<QSTASH_TOKEN>";
    })
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Entry module:

@Module({
  imports: [
    QstashModule.registerAsync({
    imports: [ConfigModule.forFeature(config)],
    inject: [ConfigService],
    async useFactory(config: ConfigService) {
        const { token } = config.get<QstashClientConfig>('qstash');
        return {
          token
        };
      },
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Usage

Inject qstash client into a service:

@Injectable()
export class AppService {
  constructor(@InjectQstash() private readonly qStash: QstashClient) {}

  sayHello() {
    return this.qStash.publishJSON({
      url: 'https://api.awesomeapp.com/v1/greets',
      body: {
        name: 'John Doe',
        message: 'Lorem ipsum',
      }
    });
  }
}

In the controller...

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  public sayHello() {
    return this.appService.sayHello();
  }
}

1.0.3

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago