This package has been deprecated

Author message:

Name change starting at V3.0.0, new package name is @neo9/n9-node-routing

n9-node-routing
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

n9-node-routing

npm version Travis Coverage

Wrapper of project routing-controllers

Easily create express app in TypeScript with Decorators

Example :

import { Acl, Body, Get, JsonController, Service, Post } from 'n9-node-routing';

@Service()
@JsonController('/foo')
export class ValidateController {
	@Acl([{ action: 'readFoo', user: '@' }])
	@Get('/details')
	public async getFoo(): Promise<object> {
		return {
			foo: 'bar',
		};
	}

	@Post('/')
	public async createFoo(@Body() body: ElementRequestCreate): Promise<any> {
		return body;
	}
}

⚠️ Some class-validator features changes between v 1.26 and 1.29 :

  • The "Custom validation decorators" require a new class instance and not only the class reference/name. Here an example.
  • The validation with schema, here is the issue opened

⚠️ BREAKING CHANGES when upgrading to n9-node-routing V2

  • Drop Node 12 support
  • Startup hooks signature change (beforeRoutingControllerLaunchHook and afterRoutingControllerLaunchHook) now an object is passed
  • Logger labels changes
  • Swagger option isEnable is renamed isEnabled with same default value as before to true
  • n9-node-routing now load the app configuration
  • /ping response is now an object : { response: 'pong' }
  • / response is now an object: { name: 'myApi' }
  • /version' response is now an object : { version: '1.2.3' }`
  • Prometheus metrics are enabled by default. To disable them use n9NodeRoutingOptions.prometheus.isEnabled: false

Features

API Documentation

Documentation available as openapi 3.0 format : /documentation.json

Swagger UI for API available at : /documentation

Starter

A starter app is available here : https://github.com/neo9/n9-node-microservice-skeleton

Some utils

  • Unified HttpClient using got

  • Cargo to group multiple small task into a bigger one, for example, multiple http calls

  • HttpCargoBuilder a simpler way to build a cargo to group HTTP calls

  • Validate configuration at startup and expose it on endpoint /conf ⚠️ To hide passord, use the transformer like one of this usage

    	@Allow()
    	@Transform(SecretTransformer.GET_TRANSFORMER())
    	secret?: string;
    
    	@Allow()
    	@Transform(SecretTransformer.GET_TRANSFORMER(SecretType.OPAQUE))
    	secretOpaque?: string;
    
    	@Allow()
    	@Transform(SecretTransformer.GET_TRANSFORMER(SecretType.OPAQUE))
    	secretOpaqueNil?: string;
    
    	@Allow()
    	@Transform(SecretTransformer.GET_TRANSFORMER(SecretType.INVISIBLE)) // default
    	secretInvisible?: string;
    
    	@Allow()
    	@Transform(SecretTransformer.GET_TRANSFORMER(SecretType.URI))
    	secretUri?: string;

Sentry

To use Sentry you only have to ask it to n9-node-routing :

  • Basic usage : define the env variable SENTRY_DSN and it will activate it with default options.
  • Fill the sentry options with at least the dsn.

Default enabled options are :

  • setting the app version in sentry release
  • set the NODE_ENV as sentry environment
  • enable tracing for ALL requests

Tests

To run all test : yarn test
To run a test containing foo : yarn test **/*foo*
To debug a test containing foo : yarn test:dev **/*foo* it will watch your files a re-run this test each time

Dev

  1. Install all dependencies and install git hooks with husky :

    yarn

  2. Run the project tests:

    yarn test

Package Sidebar

Install

npm i n9-node-routing

Weekly Downloads

22

Version

2.2.0

License

GNU

Unpacked Size

306 kB

Total Files

153

Last publish

Collaborators

  • benjd90