Injectable Logspot wrapper for NestJS
npm install --save nestjs-logspot
The simplest way to use nestjs-logspot
is to use LogspotModule.forRoot
import { Module } from '@nestjs-common';
import { LogspotModule } from 'nestjs-stripe';
@Module({
imports: [
LogspotModule.forRoot({
// Recommendation: Use env vars to store the secret key
secretKey: 'sk_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
}),
],
})
export class AppModule {}
You can then inject Logspot into any of your injectables by using a custom decorator
import { Injectable } from '@nestjs/common';
import { InjectLogspot, LogspotService } from 'nestjs-stripe';
@Injectable()
export class AppService {
constructor(@InjectLogspot() private readonly logspotService: LogspotService) {}
}
After you injected Logspot, you can use the track function to send events.
import { Injectable } from '@nestjs/common';
import { InjectLogspot, LogspotService } from 'nestjs-stripe';
@Injectable()
export class AppService {
constructor(@InjectLogspot() private readonly logspotService: LogspotService) {}
sendEvent(account) {
this.logspotService.track({
event: 'account.created',
userId: account.id,
metadata: { email: account.email },
});
}
}
Licensed under the MIT License - see the LICENSE file for details.