2.29.0 • Published 6 years ago

@avec-platform/sdk v2.29.0

Weekly downloads
412
License
-
Repository
bitbucket
Last release
6 years ago

npm-sdk

Includes

  • CacheInterceptor - Cache get requests in redis
  • Datesubscriber - Listen to typeorm events, and adds createdAt and updateAt data in request.
  • HttpErrorFilter - Catches errors and display then in dev enviroment.
  • DataBroker - Communicates with RabbitMQ
  • LogBroker - Sends log data to elastic database via RabbitMQ

Development

  • Clone repository:

    $ git clone git@bitbucket.org:avecplatform/npm-sdk.git
    $ cd npm-sdk
  • Install dependencies:

    $ npm install

Tests

  • Run all tests:

    $ npm run test
  • Run all tests in watch mode:

    $ npm run test:watch

NPM Scripts

NameDescription
buildBuild production files to 'lib' dir
deps:checkNPX for npm-check
sort-package-jsonNPX for sort-package-json
testRun tests
test:watchRun tests in watch mode

Usage

CacheInterceptor

Is used as a Nestjs APP_INTERCEPTOR

Example:

// src/app.mdoule.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { HttpCacheInterceptor } from '@avec-platform/sdk';
import { DatabaseModule } from './config/database.module';

const cacheProvider = {
  provide: APP_INTERCEPTOR,
  useClass: HttpCacheInterceptor,
};


const providers = [];

const imports = [
  DatabaseModule.orm(),
];

if (process.env.REDIS_URL) {
  Logger.log(`Cache enabled`, 'Redis');
  imports.push(DatabaseModule.cache());
  providers.push(cacheProvider);
}

@Module({
  imports,
  providers,
  controllers: [AppController],
})
export class AppModule {}

HttpErrorFilter

Is used as a Nestjs APP_FILTER

example:

// src/app.mdoule.ts

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { DatabaseModule } from './config/database.module';
import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';
import { HttpErrorFilter } from '@avec-platform/sdk';

const imports = [
  DatabaseModule.orm(),
];
const providers = [];

const httpErrorFilter = {
  provide: APP_FILTER,
  useClass: HttpErrorFilter,
};

providers.push(httpErrorFilter);



@Module({
  imports,
  providers,
  controllers: [AppController],
})
export class AppModule {}

DatesSubscriber

Is used as a Typeorm Subscriber

Example standard Typeorm Config:

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DatesSubscriber } from '@avec-platform/sdk';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'test',
      subscribers: [DatesSubscriber],
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true,
    }),
  ],
})
export class ApplicationModule {}

Example using Database.module.ts created by Andrew for the Config Service.

export function getOrmConfig() {
  const config = new ConfigService().read();
  const mysqlConfig = parseUri(config.DATABASE_URL);

  return {
    type: mysqlConfig.scheme || 'mysql',
    host: mysqlConfig.host,
    port: mysqlConfig.port || 3306,
    username: mysqlConfig.user,
    password: mysqlConfig.password,
    database: mysqlConfig.database,
    entities: [
      `${path.join(appRootPath.path, '{src,dist}')}/**/*.entity{.ts,.js}`,
    ],
    subscribers: [DatesSubscriber],
    synchronize: false,
    timezone: 'UTC',
    dateStrings: 'TIMESTAMP',
  };
}
2.29.0

6 years ago

2.28.0

6 years ago

2.27.0

6 years ago

2.26.2

6 years ago

2.26.1

6 years ago

2.26.0

6 years ago

2.25.0

6 years ago

2.24.0

6 years ago

2.23.0

6 years ago

2.22.0

6 years ago

2.21.0

6 years ago

2.20.0

6 years ago

2.19.0

6 years ago

2.18.0

6 years ago

2.17.0

6 years ago

2.16.0

6 years ago

2.15.0

6 years ago

2.14.0

6 years ago

2.13.0

6 years ago

2.12.0

6 years ago

2.11.0

6 years ago

2.10.0

6 years ago

2.8.0

6 years ago

2.7.0

6 years ago

2.6.0

6 years ago

2.5.0

6 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.0.0

6 years ago

0.58.0

6 years ago

0.57.0

6 years ago

0.56.0

6 years ago

0.55.0

6 years ago

0.54.0

6 years ago

0.53.0

6 years ago

0.52.0

6 years ago

0.51.0

6 years ago

0.50.0

6 years ago

0.49.0

6 years ago

0.48.0

6 years ago

0.47.0

6 years ago

0.46.0

6 years ago

0.45.0

6 years ago

0.43.0

6 years ago

0.42.0

6 years ago

0.41.0

6 years ago

0.40.0

6 years ago

0.39.0

6 years ago

0.38.0

6 years ago

0.37.0

6 years ago

0.36.0

6 years ago

0.35.1

6 years ago

0.34.0

6 years ago

0.33.0

6 years ago

0.32.0

6 years ago

0.31.0

6 years ago

0.29.0

6 years ago

0.28.0

6 years ago

0.27.0

6 years ago

0.25.0

6 years ago

0.24.0

6 years ago

0.23.0

6 years ago

0.22.0

6 years ago

0.21.0

6 years ago

0.20.0

6 years ago

0.19.0

6 years ago

0.18.0

6 years ago

0.17.0

6 years ago

0.15.1

6 years ago

0.16.2

6 years ago

0.16.1

6 years ago

0.16.0

6 years ago

0.15.0

6 years ago

1.1.0

6 years ago

0.14.7

6 years ago

0.14.6

6 years ago

0.14.5

6 years ago

0.14.3

6 years ago

0.14.2

6 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.13.0

6 years ago

0.12.0

6 years ago

0.9.5

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.5

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago