@luxury-presence/nestjs-plunk
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Description

Plunk module for Nest based on the plunk api.

Installation

$ npm i --save @luxury-presence/nestjs-plunk @nestjs/axios rxjs

Usage

Import PlunkModule:

@Module({
  imports: [PlunkModule.register({
    apiKey: 'PLUNK_API_KEY',
  })],
  providers: [...],
})
export class SearchModule {}

Inject PlunkService:

@Injectable()
export class SearchService {
  constructor(private readonly plunkService: PlunkService) {}

  async findByAddress(address: string): Promise<Address> {
      return this.plunkService.findAddresses(address);
  }

  async findByParcelId(parcelId: string): Promise<Valuation> {
      return this.plunkService.getHomeValuationByParcelId(parcelId);
  }
}

Async options

Quite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case, use registerAsync() method, that provides a couple of various ways to deal with async data.

1. Use factory

PlunkModule.registerAsync({
  useFactory: () => ({
    apiKey: 'PLUNK_API_KEY',
  })
});

Obviously, our factory behaves like every other one (might be async and is able to inject dependencies through inject).

PlunkModule.registerAsync({
  imports: [ConfigModule],
  useFactory: async (configService: ConfigService) => ({
    apiKey: configService.get('PLUNK_API_KEY'),
  }),
  inject: [ConfigService],
}),

2. Use class

PlunkModule.registerAsync({
  useClass: PlunkConfigService
});

Above construction will instantiate PlunkConfigService inside PlunkModule and will leverage it to create options object.

class PlunkConfigService implements PlunkModuleOptionsFactory {
  createPlunkModuleOptions(): PlunkModuleOptions {
    return {
       apiKey: 'PLUNK_API_KEY',
    };
  }
}

3. Use existing

PlunkModule.registerAsync({
  imports: [ConfigModule],
  useExisting: ConfigService,
}),

It works the same as useClass with one critical difference - PlunkModule will lookup imported modules to reuse already created ConfigService, instead of instantiating it on its own.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @luxury-presence/nestjs-plunk

Weekly Downloads

115

Version

3.0.0

License

MIT

Unpacked Size

30.6 kB

Total Files

38

Last publish

Collaborators

  • dallinlp
  • gauntc
  • nscarafia
  • spencermmelo
  • elisabethgross568
  • ryanresurreccion
  • rfonseca.luxurypresence
  • antopisciolp
  • mflores17
  • vinay-lp
  • eramirez0633lux
  • bcanepa-luxurypresence
  • acarlislelp
  • galgordo
  • ghardt
  • kelios
  • aandraslp
  • luxmedina
  • janlp
  • bradfordh
  • trobertslp
  • dougngo
  • wheitor
  • erikchau
  • viktorqa
  • xueli-lp
  • augustoalegon
  • mikebsvitla
  • taraslp
  • nazariy
  • nkashtan
  • paulchamberlain
  • jwolterslp
  • freire71
  • ojizero
  • ceallaighbrian
  • nfeigenlp
  • antopiscio
  • joebalanciolp
  • nwolfflp
  • dimasc_io
  • alex_bychkov
  • minkathalp
  • dsaldanolp
  • paulomatosj
  • qwrobins
  • carcaz
  • gabycruz
  • leocorrealp
  • danielfrank
  • rifflock
  • ulysses-odysseus
  • michaellauritsch
  • dhutton
  • jacksonwolff
  • kyletnguyen
  • sergey-at-lp
  • edwardyeh
  • timoteo
  • thenickot2
  • luxurypresenceci
  • emersonlopxs
  • kevinvoduy
  • polosergio
  • azorkin
  • pedro-surf
  • andersoonluan