0.0.3 • Published 12 months ago

@stargazer-studio-brasil/core v0.0.3

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
12 months ago

Stargazer Core

Welcome to the documentation of the core library of the Stargazer Studio. This library is responsible for providing central functionalities for the Stargazer Studio project, such as authentication management and server configuration. Here's everything you need to know to get started using this library.

Installation

To install this library, you can use the npm package manager. Simply type the following command in the terminal:

npm install @stargazer-studio-brasil/core

Features

Here's a list of features that this library provides:

Authentication

This library provides functionalities to manage user authentication. It supports authentication with JSON Web Tokens (JWT) and allows you to check if a user is authenticated and/or has permission to access a resource. To use the authentication feature, simply import the AuthService service:

import { AuthService } from '@stargazer-studio-brasil/core';
@Injectable()
export class MyService {
  constructor(private authService: AuthService) {}
  async myMethod() {
    // Check if user is authenticated
    const user = await this.authService.authenticate(request);
    // Check if user has permission to access a resource
    await this.authService.authorize(user, 'read', 'resource');
    // Generate a JWT token for a user
    const token = await this.authService.generateToken(user);
  }
}

Sever configuration

This library provides functionlities to configure the current server with some defaults. It creates server with Swagger, Validation Pipe, API Versioning, Helmet and Cors Enabled. To use the server feature, simply import the startServer function:

async function startApp() {
  const app = await NestFactory.create(ControllerModule);
  const port = process.env.PORT || '4000';
  const title = 'Stargazer API';
  const description = 'This is the main API from Stargazer';
  await startServer(app, port, title, description);
}
startApp();