@koalarx/nest 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/core/errors/bad-request.error.d.ts +3 -2
  2. package/core/errors/bad-request.error.js +4 -3
  3. package/core/errors/conflict.error.d.ts +3 -2
  4. package/core/errors/conflict.error.js +4 -3
  5. package/core/errors/error.base.d.ts +4 -0
  6. package/core/errors/error.base.js +11 -0
  7. package/core/errors/no-content.error.d.ts +3 -2
  8. package/core/errors/no-content.error.js +4 -3
  9. package/core/errors/not-allowed.error.d.ts +3 -2
  10. package/core/errors/not-allowed.error.js +4 -3
  11. package/core/errors/resource-not-found.error.d.ts +3 -2
  12. package/core/errors/resource-not-found.error.js +4 -3
  13. package/core/errors/user-already-exist.error.d.ts +3 -2
  14. package/core/errors/user-already-exist.error.js +4 -3
  15. package/core/errors/wrong-credentials.error.d.ts +3 -2
  16. package/core/errors/wrong-credentials.error.js +4 -3
  17. package/core/health-check/health-check.controller.d.ts +5 -0
  18. package/core/health-check/health-check.controller.js +27 -0
  19. package/core/health-check/health-check.module.d.ts +2 -0
  20. package/core/health-check/health-check.module.js +18 -0
  21. package/core/koala-app.js +1 -0
  22. package/core/koala-nest.module.d.ts +1 -0
  23. package/core/koala-nest.module.js +3 -0
  24. package/filters/domain-errors.filter.js +1 -0
  25. package/filters/global-exception.filter.js +3 -0
  26. package/package.json +1 -1
  27. package/tsconfig.lib.tsbuildinfo +1 -1
  28. package/core/backgroud-services/cron-service/cron-job.handler.spec.d.ts +0 -8
  29. package/core/backgroud-services/cron-service/cron-job.handler.spec.js +0 -33
  30. package/core/backgroud-services/event-service/event-queue.spec.d.ts +0 -1
  31. package/core/backgroud-services/event-service/event-queue.spec.js +0 -34
  32. package/core/database/entity.decorator.spec.d.ts +0 -17
  33. package/core/database/entity.decorator.spec.js +0 -102
  34. package/core/request-overflow/request-result.spec.d.ts +0 -1
  35. package/core/request-overflow/request-result.spec.js +0 -21
  36. package/core/utils/list.spec.d.ts +0 -1
  37. package/core/utils/list.spec.js +0 -60
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class BadRequestError extends Error implements UseCaseError {
3
- constructor(message?: string);
3
+ export declare class BadRequestError extends ErrorBase implements UseCaseError {
4
+ constructor(message?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BadRequestError = void 0;
4
- class BadRequestError extends Error {
5
- constructor(message) {
6
- super(message ?? 'Bad Request');
4
+ const error_base_1 = require("./error.base");
5
+ class BadRequestError extends error_base_1.ErrorBase {
6
+ constructor(message, data) {
7
+ super(message ?? 'Bad Request', data);
7
8
  }
8
9
  }
9
10
  exports.BadRequestError = BadRequestError;
@@ -1,3 +1,4 @@
1
- export declare class ConflictError extends Error {
2
- constructor(identifier: string);
1
+ import { ErrorBase } from './error.base';
2
+ export declare class ConflictError extends ErrorBase {
3
+ constructor(identifier: string, data?: any);
3
4
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConflictError = void 0;
4
- class ConflictError extends Error {
5
- constructor(identifier) {
6
- super(`O registro ${identifier} já existe.`);
4
+ const error_base_1 = require("./error.base");
5
+ class ConflictError extends error_base_1.ErrorBase {
6
+ constructor(identifier, data) {
7
+ super(`O registro ${identifier} já existe.`, data);
7
8
  }
8
9
  }
9
10
  exports.ConflictError = ConflictError;
@@ -0,0 +1,4 @@
1
+ export declare abstract class ErrorBase extends Error {
2
+ readonly data?: any;
3
+ constructor(message: string, data?: any);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorBase = void 0;
4
+ class ErrorBase extends Error {
5
+ data;
6
+ constructor(message, data) {
7
+ super(message);
8
+ this.data = data;
9
+ }
10
+ }
11
+ exports.ErrorBase = ErrorBase;
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class NoContentError extends Error implements UseCaseError {
3
- constructor(message?: string);
3
+ export declare class NoContentError extends ErrorBase implements UseCaseError {
4
+ constructor(message?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NoContentError = void 0;
4
- class NoContentError extends Error {
5
- constructor(message) {
6
- super(message ?? 'No Content');
4
+ const error_base_1 = require("./error.base");
5
+ class NoContentError extends error_base_1.ErrorBase {
6
+ constructor(message, data) {
7
+ super(message ?? 'No Content', data);
7
8
  }
8
9
  }
9
10
  exports.NoContentError = NoContentError;
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class NotAllowedError extends Error implements UseCaseError {
3
- constructor(message?: string);
3
+ export declare class NotAllowedError extends ErrorBase implements UseCaseError {
4
+ constructor(message?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NotAllowedError = void 0;
4
- class NotAllowedError extends Error {
5
- constructor(message) {
6
- super(message ?? 'Você não tem permissão para utilizar esse recurso.');
4
+ const error_base_1 = require("./error.base");
5
+ class NotAllowedError extends error_base_1.ErrorBase {
6
+ constructor(message, data) {
7
+ super(message ?? 'Você não tem permissão para utilizar esse recurso.', data);
7
8
  }
8
9
  }
9
10
  exports.NotAllowedError = NotAllowedError;
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class ResourceNotFoundError extends Error implements UseCaseError {
3
- constructor(name?: string);
3
+ export declare class ResourceNotFoundError extends ErrorBase implements UseCaseError {
4
+ constructor(name?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResourceNotFoundError = void 0;
4
- class ResourceNotFoundError extends Error {
5
- constructor(name = 'Recurso') {
6
- super(`${name} não encontrado(a).`);
4
+ const error_base_1 = require("./error.base");
5
+ class ResourceNotFoundError extends error_base_1.ErrorBase {
6
+ constructor(name = 'Recurso', data) {
7
+ super(`${name} não encontrado(a).`, data);
7
8
  }
8
9
  }
9
10
  exports.ResourceNotFoundError = ResourceNotFoundError;
@@ -1,3 +1,4 @@
1
- export declare class UserAlreadyExist extends Error {
2
- constructor(identifier: string);
1
+ import { ErrorBase } from './error.base';
2
+ export declare class UserAlreadyExist extends ErrorBase {
3
+ constructor(identifier: string, data?: any);
3
4
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserAlreadyExist = void 0;
4
- class UserAlreadyExist extends Error {
5
- constructor(identifier) {
6
- super(`User ${identifier} already exists`);
4
+ const error_base_1 = require("./error.base");
5
+ class UserAlreadyExist extends error_base_1.ErrorBase {
6
+ constructor(identifier, data) {
7
+ super(`User ${identifier} already exists`, data);
7
8
  }
8
9
  }
9
10
  exports.UserAlreadyExist = UserAlreadyExist;
@@ -1,3 +1,4 @@
1
- export declare class WrongCredentialsError extends Error {
2
- constructor();
1
+ import { ErrorBase } from './error.base';
2
+ export declare class WrongCredentialsError extends ErrorBase {
3
+ constructor(data?: any);
3
4
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WrongCredentialsError = void 0;
4
- class WrongCredentialsError extends Error {
5
- constructor() {
6
- super('Credentials are not valid');
4
+ const error_base_1 = require("./error.base");
5
+ class WrongCredentialsError extends error_base_1.ErrorBase {
6
+ constructor(data) {
7
+ super('Credentials are not valid', data);
7
8
  }
8
9
  }
9
10
  exports.WrongCredentialsError = WrongCredentialsError;
@@ -0,0 +1,5 @@
1
+ export declare class HealthCheckController {
2
+ healthCheck(): {
3
+ status: string;
4
+ };
5
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HealthCheckController = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ let HealthCheckController = exports.HealthCheckController = class HealthCheckController {
15
+ healthCheck() {
16
+ return { status: 'ok' };
17
+ }
18
+ };
19
+ __decorate([
20
+ (0, common_1.Get)(),
21
+ __metadata("design:type", Function),
22
+ __metadata("design:paramtypes", []),
23
+ __metadata("design:returntype", void 0)
24
+ ], HealthCheckController.prototype, "healthCheck", null);
25
+ exports.HealthCheckController = HealthCheckController = __decorate([
26
+ (0, common_1.Controller)('health')
27
+ ], HealthCheckController);
@@ -0,0 +1,2 @@
1
+ export declare class HealthCheckModule {
2
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HealthCheckModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const health_check_controller_1 = require("./health-check.controller");
12
+ let HealthCheckModule = exports.HealthCheckModule = class HealthCheckModule {
13
+ };
14
+ exports.HealthCheckModule = HealthCheckModule = __decorate([
15
+ (0, common_1.Module)({
16
+ controllers: [health_check_controller_1.HealthCheckController],
17
+ })
18
+ ], HealthCheckModule);
package/core/koala-app.js CHANGED
@@ -234,6 +234,7 @@ class KoalaApp {
234
234
  if (this._apiReferenceEndpoint) {
235
235
  consola.info('API Reference:', `http://localhost:${port}${this._apiReferenceEndpoint}`);
236
236
  }
237
+ consola.info('Health Check:', `http://localhost:${port}/health`);
237
238
  consola.info('Internal Host:', `http://localhost:${port}`);
238
239
  if (this._ngrokUrl) {
239
240
  consola.info('External Host:', this._ngrokUrl);
@@ -7,6 +7,7 @@ interface KoalaNestModuleConfig {
7
7
  logging?: Provider<ILoggingService>;
8
8
  env?: ZodType;
9
9
  controllers?: Type<any>[];
10
+ healthCheck?: Type<any>;
10
11
  cronJobs?: Type<CronJobHandlerBase>[];
11
12
  eventJobs?: Type<EventHandlerBase<any>>[];
12
13
  }
@@ -19,9 +19,11 @@ const iredis_service_1 = require("../services/redis/iredis.service");
19
19
  const redis_service_1 = require("../services/redis/redis.service");
20
20
  const ired_lock_service_1 = require("../services/redlock/ired-lock.service");
21
21
  const red_lock_service_1 = require("../services/redlock/red-lock.service");
22
+ const health_check_module_1 = require("./health-check/health-check.module");
22
23
  let KoalaNestModule = exports.KoalaNestModule = KoalaNestModule_1 = class KoalaNestModule {
23
24
  static register(config) {
24
25
  const controllers = config?.controllers ?? [];
26
+ const healthCheck = config?.healthCheck ?? health_check_module_1.HealthCheckModule;
25
27
  const cronJobsProviders = config?.cronJobs ?? [];
26
28
  const eventJobsProviders = config?.eventJobs ?? [];
27
29
  const loggingServiceClass = config?.logging ?? logging_service_1.LoggingService;
@@ -33,6 +35,7 @@ let KoalaNestModule = exports.KoalaNestModule = KoalaNestModule_1 = class KoalaN
33
35
  isGlobal: true,
34
36
  }),
35
37
  env_module_1.EnvModule,
38
+ healthCheck,
36
39
  ...controllers,
37
40
  ],
38
41
  providers: [
@@ -59,6 +59,7 @@ let DomainErrorsFilter = exports.DomainErrorsFilter = class DomainErrorsFilter e
59
59
  const mappedException = {
60
60
  statusCode: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
61
61
  message: exception.message,
62
+ data: exception.data,
62
63
  };
63
64
  switch (exception.constructor) {
64
65
  case user_already_exist_error_1.UserAlreadyExist:
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.GlobalExceptionsFilter = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const core_1 = require("@nestjs/core");
15
+ const node_http_1 = require("node:http");
15
16
  const koala_global_vars_1 = require("../core/koala-global-vars");
16
17
  const env_config_1 = require("../core/utils/env.config");
17
18
  const filter_request_params_1 = require("../core/utils/filter-request-params");
@@ -26,6 +27,7 @@ let GlobalExceptionsFilter = exports.GlobalExceptionsFilter = class GlobalExcept
26
27
  }
27
28
  catch(exception, host) {
28
29
  const filterRequestParams = filter_request_params_1.FilterRequestParams.get(host);
30
+ const request = host.getArgs().find((arg) => arg instanceof node_http_1.IncomingMessage) ?? null;
29
31
  const statusCode = exception instanceof common_1.HttpException
30
32
  ? exception.getStatus()
31
33
  : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
@@ -39,6 +41,7 @@ let GlobalExceptionsFilter = exports.GlobalExceptionsFilter = class GlobalExcept
39
41
  this.httpAdapter.reply(filterRequestParams.response, responseBody, statusCode);
40
42
  if (!exception.message?.includes('Cannot GET /socket.io') &&
41
43
  !exception.message?.includes('Cannot GET /favicon.ico') &&
44
+ !['/'].includes(request?.url ?? '') &&
42
45
  statusCode !== common_1.HttpStatus.UNAUTHORIZED) {
43
46
  if (!env_config_1.EnvConfig.isEnvTest) {
44
47
  this.loggingService
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",