Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@s3pweb/nestjs-common

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@s3pweb/nestjs-common

A NestJS guard to authorise only the given IP(s)

unpublished
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

npm (scoped)

S3PWeb - NestJS common libs

A repo containing all the common utilities for our NestJS projects:

  • A NestJS guard to authorise only the given IP(s)
  • A logging service implementing the LoggerService interface and using the @s3pweb/s3pweb-logger
  • A MetricsInterface to be used in the logging service

Install

npm i @s3pweb/nestjs-common

Usage

IP Whitelist

On a controller to protect all routes:

@Controller('v1/cats')
@IpWhitelist('0.0.0.0', '::1')
@UseGuards(IpWhitelistGuard)
export class CatsController {}

Directly on a route (with the guard on the controller):

@Post()
@IpWhitelist('192.168.1.1')
async createCat() {}

Logging Service

To use the LoggingModule, add it to the imports of the AppModule, and then:

@Injectable()
export class Service {
  private readonly log: any;

  constructor(
    logger: LoggingService,
  ) {
    this.log = logger.getLogger(Service.name);
  }
}

To be able ton inject it correctly, you need a metrics module exporting a service implementing the MetricsInterface:

@Global()
@Module({
  providers: [
    {
      provide: METRICS_SERVICE,
      useClass: PromService,
    },
  ],
  controllers: [PromController],
  exports: [
    {
      provide: METRICS_SERVICE,
      useClass: PromService,
    },
  ],
})
export class PromModule {
  // -- Empty
}

To use the PromService in a Controller or a Service, you can inject it in a constructor with:

@Inject(METRICS_SERVICE) private readonly metricsService: PromService,

Metrics Interface

This interface enables you to implements the required functions for the LoggingService.

FAQs

Package last updated on 15 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts