0.0.3 • Published 2 years ago

@platohq/nestjs-clearbit v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@platohq/nestjs-clearbit

The NestJS module based on the official Clearbit package

How to install

npm install @platohq/nestjs-clearbit

or

yarn add @platohq/nestjs-clearbit

How to use

Register the module

import { ClearbitModule } from '@platohq/nestjs-clearbit';

@Module({
  imports: [
    ClearbitModule.register({
      apiKey: 'YOUR_WRITE_KEY',
    }),
  ],
})
export class AppModule {}

Inject the service

import { ClearbitService } from '@platohq/nestjs-clearbit';

@Injectable()
export class AppService {
  constructor(private readonly clearbitService: ClearbitService) {}

  track() {
    this.clearbitService.track('MY_EVENT');
  }
}

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.

Use factory

ClearbitModule.registerAsync({
  useFactory: () => ({
    apiKey: 'YOUR_WRITE_KEY',
  }),
});

Use class

ClearbitModule.registerAsync({
  useClass: ClearbitConfigService,
});

Above construction will instantiate ClearbitConfigService inside ClearbitModule and will leverage it to create options object.

class ClearbitConfigService implements ClearbitOptionsFactory {
  createClearbitOptions(): ClearbitModuleOptions {
    return {
      apiKey: 'YOUR_WRITE_KEY',
    };
  }
}

Use existing

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

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago