@aptana/multichannel-common 2.9.12

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 (202) hide show
  1. package/core/domain/Command.d.ts +3 -0
  2. package/core/domain/Command.js +2 -0
  3. package/core/domain/Entity.d.ts +6 -0
  4. package/core/domain/Entity.js +13 -0
  5. package/core/domain/Identifier.d.ts +5 -0
  6. package/core/domain/Identifier.js +13 -0
  7. package/core/domain/UniqueId.d.ts +4 -0
  8. package/core/domain/UniqueId.js +11 -0
  9. package/core/domain/UseCase.d.ts +3 -0
  10. package/core/domain/UseCase.js +2 -0
  11. package/core/domain/ValueObject.d.ts +4 -0
  12. package/core/domain/ValueObject.js +10 -0
  13. package/core/domain/auth/Auth.d.ts +17 -0
  14. package/core/domain/auth/Auth.js +41 -0
  15. package/core/domain/auth/Authenticable.d.ts +4 -0
  16. package/core/domain/auth/Authenticable.js +2 -0
  17. package/core/domain/auth/Guard.d.ts +20 -0
  18. package/core/domain/auth/Guard.js +2 -0
  19. package/core/domain/auth/TokenGuard.d.ts +33 -0
  20. package/core/domain/auth/TokenGuard.js +94 -0
  21. package/core/domain/auth/UserProvider.d.ts +17 -0
  22. package/core/domain/auth/UserProvider.js +2 -0
  23. package/core/domain/cache/Cache.d.ts +8 -0
  24. package/core/domain/cache/Cache.js +2 -0
  25. package/core/domain/cache/Repo.d.ts +51 -0
  26. package/core/domain/cache/Repo.js +2 -0
  27. package/core/domain/cache/Store.d.ts +26 -0
  28. package/core/domain/cache/Store.js +2 -0
  29. package/core/domain/events/Event.d.ts +8 -0
  30. package/core/domain/events/Event.js +2 -0
  31. package/core/domain/events/Listener.d.ts +4 -0
  32. package/core/domain/events/Listener.js +2 -0
  33. package/core/domain/events/Worker.d.ts +3 -0
  34. package/core/domain/events/Worker.js +2 -0
  35. package/core/domain/loaders/Loader.d.ts +4 -0
  36. package/core/domain/loaders/Loader.js +2 -0
  37. package/core/domain/loaders/Manager.d.ts +3 -0
  38. package/core/domain/loaders/Manager.js +2 -0
  39. package/core/errors/AppError.d.ts +10 -0
  40. package/core/errors/AppError.js +16 -0
  41. package/core/errors/AuthenticationTokenMissingError.d.ts +5 -0
  42. package/core/errors/AuthenticationTokenMissingError.js +11 -0
  43. package/core/errors/BadRequestError.d.ts +5 -0
  44. package/core/errors/BadRequestError.js +11 -0
  45. package/core/errors/NotAuthorizedError.d.ts +5 -0
  46. package/core/errors/NotAuthorizedError.js +11 -0
  47. package/core/errors/NotFoundError.d.ts +5 -0
  48. package/core/errors/NotFoundError.js +11 -0
  49. package/core/errors/RequestValidationError.d.ts +10 -0
  50. package/core/errors/RequestValidationError.js +47 -0
  51. package/core/errors/ValidationError.d.ts +8 -0
  52. package/core/errors/ValidationError.js +19 -0
  53. package/core/errors/WrongAuthenticationTokenError.d.ts +5 -0
  54. package/core/errors/WrongAuthenticationTokenError.js +11 -0
  55. package/core/errors/WrongCredentialsError.d.ts +5 -0
  56. package/core/errors/WrongCredentialsError.js +11 -0
  57. package/core/index.d.ts +48 -0
  58. package/core/index.js +69 -0
  59. package/core/infrastructure/Container.d.ts +1 -0
  60. package/core/infrastructure/Container.js +8 -0
  61. package/core/infrastructure/Controller.d.ts +9 -0
  62. package/core/infrastructure/Controller.js +30 -0
  63. package/core/infrastructure/DatabaseRepository.d.ts +35 -0
  64. package/core/infrastructure/DatabaseRepository.js +2 -0
  65. package/core/infrastructure/Mapper.d.ts +2 -0
  66. package/core/infrastructure/Mapper.js +6 -0
  67. package/core/infrastructure/Repo.d.ts +2 -0
  68. package/core/infrastructure/Repo.js +6 -0
  69. package/core/infrastructure/cache/Cache.d.ts +47 -0
  70. package/core/infrastructure/cache/Cache.js +101 -0
  71. package/core/infrastructure/cache/InMemoryCache.d.ts +20 -0
  72. package/core/infrastructure/cache/InMemoryCache.js +62 -0
  73. package/core/infrastructure/cache/RedisCache.d.ts +15 -0
  74. package/core/infrastructure/cache/RedisCache.js +51 -0
  75. package/core/infrastructure/cache/Repo.d.ts +25 -0
  76. package/core/infrastructure/cache/Repo.js +103 -0
  77. package/core/infrastructure/cache/stores/ArrayStore.d.ts +17 -0
  78. package/core/infrastructure/cache/stores/ArrayStore.js +65 -0
  79. package/core/infrastructure/cache/stores/FileStore.d.ts +14 -0
  80. package/core/infrastructure/cache/stores/FileStore.js +171 -0
  81. package/core/infrastructure/cache/stores/NullStore.d.ts +9 -0
  82. package/core/infrastructure/cache/stores/NullStore.js +24 -0
  83. package/core/infrastructure/cache/stores/RedisStore.d.ts +13 -0
  84. package/core/infrastructure/cache/stores/RedisStore.js +44 -0
  85. package/core/infrastructure/events/ChannelEvent.d.ts +9 -0
  86. package/core/infrastructure/events/ChannelEvent.js +37 -0
  87. package/core/infrastructure/events/Connection.d.ts +8 -0
  88. package/core/infrastructure/events/Connection.js +30 -0
  89. package/core/infrastructure/events/Event.d.ts +16 -0
  90. package/core/infrastructure/events/Event.js +42 -0
  91. package/core/infrastructure/events/Listener.d.ts +23 -0
  92. package/core/infrastructure/events/Listener.js +77 -0
  93. package/core/infrastructure/events/Worker.d.ts +9 -0
  94. package/core/infrastructure/events/Worker.js +34 -0
  95. package/core/infrastructure/events/grpc/Connection.d.ts +9 -0
  96. package/core/infrastructure/events/grpc/Connection.js +34 -0
  97. package/core/infrastructure/events/grpc/Event.d.ts +12 -0
  98. package/core/infrastructure/events/grpc/Event.js +80 -0
  99. package/core/infrastructure/events/grpc/Listener.d.ts +16 -0
  100. package/core/infrastructure/events/grpc/Listener.js +74 -0
  101. package/core/infrastructure/events/rpc/Event.d.ts +13 -0
  102. package/core/infrastructure/events/rpc/Event.js +98 -0
  103. package/core/infrastructure/events/rpc/Listener.d.ts +6 -0
  104. package/core/infrastructure/events/rpc/Listener.js +30 -0
  105. package/core/infrastructure/http/App.d.ts +15 -0
  106. package/core/infrastructure/http/App.js +73 -0
  107. package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.d.ts +2 -0
  108. package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.js +8 -0
  109. package/core/infrastructure/http/middleware/errorMiddleware.d.ts +2 -0
  110. package/core/infrastructure/http/middleware/errorMiddleware.js +18 -0
  111. package/core/infrastructure/http/middleware/loggerMiddleware.d.ts +2 -0
  112. package/core/infrastructure/http/middleware/loggerMiddleware.js +17 -0
  113. package/core/infrastructure/http/middleware/routeNotFoundMiddleware.d.ts +2 -0
  114. package/core/infrastructure/http/middleware/routeNotFoundMiddleware.js +11 -0
  115. package/core/infrastructure/http/middleware/validationMiddleware.d.ts +4 -0
  116. package/core/infrastructure/http/middleware/validationMiddleware.js +35 -0
  117. package/core/infrastructure/loaders/Loader.d.ts +8 -0
  118. package/core/infrastructure/loaders/Loader.js +14 -0
  119. package/core/infrastructure/loaders/Manager.d.ts +7 -0
  120. package/core/infrastructure/loaders/Manager.js +24 -0
  121. package/core/modules/health/errors/ConnectionNotFoundError.d.ts +4 -0
  122. package/core/modules/health/errors/ConnectionNotFoundError.js +10 -0
  123. package/core/modules/health/errors/HealthCheckError.d.ts +3 -0
  124. package/core/modules/health/errors/HealthCheckError.js +10 -0
  125. package/core/modules/health/errors/TimeoutError.d.ts +4 -0
  126. package/core/modules/health/errors/TimeoutError.js +10 -0
  127. package/core/modules/health/useCases/health/HealthController.d.ts +20 -0
  128. package/core/modules/health/useCases/health/HealthController.js +75 -0
  129. package/core/modules/health/useCases/healthCheck/HealthCheck.d.ts +8 -0
  130. package/core/modules/health/useCases/healthCheck/HealthCheck.js +37 -0
  131. package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.d.ts +8 -0
  132. package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.js +48 -0
  133. package/core/modules/health/useCases/healthCheck/HealthCheckResult.d.ts +6 -0
  134. package/core/modules/health/useCases/healthCheck/HealthCheckResult.js +2 -0
  135. package/core/modules/health/useCases/healthIndicator/HealthIndicator.d.ts +7 -0
  136. package/core/modules/health/useCases/healthIndicator/HealthIndicator.js +14 -0
  137. package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.d.ts +7 -0
  138. package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.js +2 -0
  139. package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.d.ts +21 -0
  140. package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.js +69 -0
  141. package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.d.ts +27 -0
  142. package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.js +73 -0
  143. package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.d.ts +21 -0
  144. package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.js +66 -0
  145. package/core/modules/health/utils/promise.d.ts +1 -0
  146. package/core/modules/health/utils/promise.js +12 -0
  147. package/core/modules/service/useCases/detail/DetailController.d.ts +6 -0
  148. package/core/modules/service/useCases/detail/DetailController.js +25 -0
  149. package/core/utils/Crypto.d.ts +24 -0
  150. package/core/utils/Crypto.js +93 -0
  151. package/core/utils/Hash.d.ts +6 -0
  152. package/core/utils/Hash.js +23 -0
  153. package/core/utils/cache.d.ts +1 -0
  154. package/core/utils/cache.js +16 -0
  155. package/core/utils/commands.d.ts +2 -0
  156. package/core/utils/commands.js +7 -0
  157. package/core/utils/events.d.ts +3 -0
  158. package/core/utils/events.js +11 -0
  159. package/core/utils/logger.d.ts +2 -0
  160. package/core/utils/logger.js +15 -0
  161. package/core/utils/response.d.ts +4 -0
  162. package/core/utils/response.js +11 -0
  163. package/core/utils/validator.d.ts +4 -0
  164. package/core/utils/validator.js +48 -0
  165. package/domain/BalanceMutation.d.ts +18 -0
  166. package/domain/BalanceMutation.js +8 -0
  167. package/domain/ChannelWhatsapp.d.ts +18 -0
  168. package/domain/ChannelWhatsapp.js +2 -0
  169. package/domain/MessageTemplate.d.ts +26 -0
  170. package/domain/MessageTemplate.js +12 -0
  171. package/domain/MessageTemplateCategoryUpdate.d.ts +8 -0
  172. package/domain/MessageTemplateCategoryUpdate.js +2 -0
  173. package/domain/MessageTemplateStatusUpdate.d.ts +8 -0
  174. package/domain/MessageTemplateStatusUpdate.js +2 -0
  175. package/domain/Payment.d.ts +14 -0
  176. package/domain/Payment.js +8 -0
  177. package/domain/Report.d.ts +33 -0
  178. package/domain/Report.js +15 -0
  179. package/domain/TransactionMessaging.d.ts +33 -0
  180. package/domain/TransactionMessaging.js +11 -0
  181. package/domain/TransactionMessagingStatusUpdate.d.ts +6 -0
  182. package/domain/TransactionMessagingStatusUpdate.js +2 -0
  183. package/domain/User.d.ts +25 -0
  184. package/domain/User.js +19 -0
  185. package/domain/index.d.ts +10 -0
  186. package/domain/index.js +26 -0
  187. package/index.d.ts +3 -0
  188. package/index.js +19 -0
  189. package/package.json +57 -0
  190. package/readme.md +4 -0
  191. package/shared/index.d.ts +5 -0
  192. package/shared/index.js +21 -0
  193. package/shared/plugins/axios-logger-mongo.d.ts +5 -0
  194. package/shared/plugins/axios-logger-mongo.js +113 -0
  195. package/shared/plugins/axios.d.ts +1 -0
  196. package/shared/plugins/axios.js +31 -0
  197. package/shared/plugins/cursor.d.ts +29 -0
  198. package/shared/plugins/cursor.js +231 -0
  199. package/shared/plugins/mongoose.d.ts +31 -0
  200. package/shared/plugins/mongoose.js +125 -0
  201. package/shared/resources/JsonResource.d.ts +16 -0
  202. package/shared/resources/JsonResource.js +59 -0
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.routeNotFoundMiddleware = void 0;
7
+ const NotFoundError_1 = __importDefault(require("../../../../core/errors/NotFoundError"));
8
+ function routeNotFoundMiddleware(req, res, next) {
9
+ throw new NotFoundError_1.default();
10
+ }
11
+ exports.routeNotFoundMiddleware = routeNotFoundMiddleware;
@@ -0,0 +1,4 @@
1
+ import { RequestHandler } from 'express';
2
+ export declare function validateBodyMiddleware<T>(type: any, skipMissingProperties?: boolean): RequestHandler;
3
+ export declare function validateQueryMiddleware<T>(type: any, skipMissingProperties?: boolean): RequestHandler;
4
+ export declare const validationMiddleware: typeof validateBodyMiddleware;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validationMiddleware = exports.validateQueryMiddleware = exports.validateBodyMiddleware = void 0;
4
+ const RequestValidationError_1 = require("../../../../core/errors/RequestValidationError");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const class_validator_1 = require("class-validator");
7
+ function validateBodyMiddleware(type, skipMissingProperties = false) {
8
+ return (req, res, next) => {
9
+ (0, class_validator_1.validate)((0, class_transformer_1.plainToClass)(type, req.body), { skipMissingProperties })
10
+ .then((errors) => {
11
+ if (errors.length > 0) {
12
+ next(new RequestValidationError_1.RequestValidationError(errors));
13
+ }
14
+ else {
15
+ next();
16
+ }
17
+ });
18
+ };
19
+ }
20
+ exports.validateBodyMiddleware = validateBodyMiddleware;
21
+ function validateQueryMiddleware(type, skipMissingProperties = false) {
22
+ return (req, res, next) => {
23
+ (0, class_validator_1.validate)((0, class_transformer_1.plainToClass)(type, req.query, { enableImplicitConversion: false }), { skipMissingProperties })
24
+ .then((errors) => {
25
+ if (errors.length > 0) {
26
+ next(new RequestValidationError_1.RequestValidationError(errors));
27
+ }
28
+ else {
29
+ next();
30
+ }
31
+ });
32
+ };
33
+ }
34
+ exports.validateQueryMiddleware = validateQueryMiddleware;
35
+ exports.validationMiddleware = validateBodyMiddleware;
@@ -0,0 +1,8 @@
1
+ import { Loader as LoaderContract } from "../../../core/domain/loaders/Loader";
2
+ import { Container } from '../../../core/infrastructure/Container';
3
+ export declare abstract class Loader implements LoaderContract {
4
+ protected container: typeof Container;
5
+ constructor();
6
+ load(): void;
7
+ abstract register(): void;
8
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Loader = void 0;
4
+ const Container_1 = require("../../../core/infrastructure/Container");
5
+ class Loader {
6
+ container;
7
+ constructor() {
8
+ this.container = Container_1.Container;
9
+ }
10
+ load() {
11
+ this.register();
12
+ }
13
+ }
14
+ exports.Loader = Loader;
@@ -0,0 +1,7 @@
1
+ import { Manager as LoaderManagerContract } from '../../../core/domain/loaders/Manager';
2
+ export declare class LoaderManager implements LoaderManagerContract {
3
+ protected loaders: any[];
4
+ constructor(loaders: any[]);
5
+ load(): void;
6
+ protected resolve(klass: any): any;
7
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoaderManager = void 0;
4
+ class LoaderManager {
5
+ loaders = [
6
+ //
7
+ ];
8
+ constructor(loaders) {
9
+ this.loaders.push(...loaders);
10
+ }
11
+ load() {
12
+ this.loaders.forEach((loader) => {
13
+ const instance = this.resolve(loader);
14
+ instance.load();
15
+ });
16
+ }
17
+ resolve(klass) {
18
+ if (klass instanceof Function) {
19
+ klass = new klass();
20
+ }
21
+ return klass;
22
+ }
23
+ }
24
+ exports.LoaderManager = LoaderManager;
@@ -0,0 +1,4 @@
1
+ import { HealthCheckError } from './HealthCheckError';
2
+ export declare class ConnectionNotFoundError extends HealthCheckError {
3
+ constructor();
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionNotFoundError = void 0;
4
+ const HealthCheckError_1 = require("./HealthCheckError");
5
+ class ConnectionNotFoundError extends HealthCheckError_1.HealthCheckError {
6
+ constructor() {
7
+ super('Connection provider not found in application context');
8
+ }
9
+ }
10
+ exports.ConnectionNotFoundError = ConnectionNotFoundError;
@@ -0,0 +1,3 @@
1
+ export declare class HealthCheckError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HealthCheckError = void 0;
4
+ class HealthCheckError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ Error.captureStackTrace(this, this.constructor);
8
+ }
9
+ }
10
+ exports.HealthCheckError = HealthCheckError;
@@ -0,0 +1,4 @@
1
+ import { HealthCheckError } from './HealthCheckError';
2
+ export declare class TimeoutError extends HealthCheckError {
3
+ constructor(timeout: number);
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeoutError = void 0;
4
+ const HealthCheckError_1 = require("./HealthCheckError");
5
+ class TimeoutError extends HealthCheckError_1.HealthCheckError {
6
+ constructor(timeout) {
7
+ super(`Timeout ${timeout}ms exceeded`);
8
+ }
9
+ }
10
+ exports.TimeoutError = TimeoutError;
@@ -0,0 +1,20 @@
1
+ import { Controller } from '../../../../../core/infrastructure/Controller';
2
+ import { Request, Response } from 'express';
3
+ import { HealthCheck } from '../healthCheck/HealthCheck';
4
+ import { MongooseHealthIndicator } from '../healthIndicator/database/mongooseHealthIndicator';
5
+ import { SequelizeHealthIndicator } from '../healthIndicator/database/sequelizeHealthIndicator';
6
+ import { RabbitmqHealthIndicator } from '../healthIndicator/message-broker/rabbitmqHealthIndicator';
7
+ import { HealthIndicatorFunction } from '../healthIndicator/HealthIndicator';
8
+ export default class HealthController extends Controller {
9
+ private readonly health;
10
+ protected readonly mongoose: MongooseHealthIndicator;
11
+ protected readonly rabbitmq: RabbitmqHealthIndicator;
12
+ protected readonly sequelize: SequelizeHealthIndicator;
13
+ constructor(health: HealthCheck, mongoose: MongooseHealthIndicator, rabbitmq: RabbitmqHealthIndicator, sequelize: SequelizeHealthIndicator);
14
+ registerRoutes(): void;
15
+ show(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
16
+ protected getHealthServices(): HealthIndicatorFunction[];
17
+ protected rmqPingCheck(): HealthIndicatorFunction[];
18
+ protected mongoPingCheck(): HealthIndicatorFunction[];
19
+ protected sequelizePingCheck(): HealthIndicatorFunction[];
20
+ }
@@ -0,0 +1,75 @@
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
+ const Container_1 = require("../../../../../core/infrastructure/Container");
13
+ const Controller_1 = require("../../../../../core/infrastructure/Controller");
14
+ const HealthCheck_1 = require("../healthCheck/HealthCheck");
15
+ const mongooseHealthIndicator_1 = require("../healthIndicator/database/mongooseHealthIndicator");
16
+ const sequelizeHealthIndicator_1 = require("../healthIndicator/database/sequelizeHealthIndicator");
17
+ const rabbitmqHealthIndicator_1 = require("../healthIndicator/message-broker/rabbitmqHealthIndicator");
18
+ const response_1 = require("../../../../../core/utils/response");
19
+ let HealthController = class HealthController extends Controller_1.Controller {
20
+ health;
21
+ mongoose;
22
+ rabbitmq;
23
+ sequelize;
24
+ constructor(health, mongoose, rabbitmq, sequelize) {
25
+ super();
26
+ this.health = health;
27
+ this.mongoose = mongoose;
28
+ this.rabbitmq = rabbitmq;
29
+ this.sequelize = sequelize;
30
+ }
31
+ registerRoutes() {
32
+ this.router.get('/health', this.show.bind(this));
33
+ }
34
+ async show(req, res) {
35
+ try {
36
+ const services = this.getHealthServices();
37
+ const data = await this.health.check(services);
38
+ return this.ok(res, data);
39
+ }
40
+ catch (error) {
41
+ return (0, response_1.sendSuccessResponse)(res, error, 500);
42
+ }
43
+ }
44
+ getHealthServices() {
45
+ const services = [];
46
+ const health = Container_1.Container.get('health');
47
+ if (health?.rmq) {
48
+ services.push(...this.rmqPingCheck());
49
+ }
50
+ if (health?.mongo) {
51
+ services.push(...this.mongoPingCheck());
52
+ }
53
+ if (health?.mysql) {
54
+ services.push(...this.sequelizePingCheck());
55
+ }
56
+ return services;
57
+ }
58
+ rmqPingCheck() {
59
+ return [async () => this.rabbitmq.pingCheck('rmq')];
60
+ }
61
+ mongoPingCheck() {
62
+ return [async () => this.mongoose.pingCheck('mongo')];
63
+ }
64
+ sequelizePingCheck() {
65
+ return [async () => this.sequelize.pingCheck('mysql')];
66
+ }
67
+ };
68
+ HealthController = __decorate([
69
+ (0, Container_1.Service)(),
70
+ __metadata("design:paramtypes", [HealthCheck_1.HealthCheck,
71
+ mongooseHealthIndicator_1.MongooseHealthIndicator,
72
+ rabbitmqHealthIndicator_1.RabbitmqHealthIndicator,
73
+ sequelizeHealthIndicator_1.SequelizeHealthIndicator])
74
+ ], HealthController);
75
+ exports.default = HealthController;
@@ -0,0 +1,8 @@
1
+ import { HealthIndicatorFunction } from '../healthIndicator/HealthIndicator';
2
+ import { HealthCheckExecutor } from './HealthCheckExecutor';
3
+ import { HealthCheckResult } from './HealthCheckResult';
4
+ export declare class HealthCheck {
5
+ private readonly healthCheckExecutor;
6
+ constructor(healthCheckExecutor: HealthCheckExecutor);
7
+ check(healthIndicators: HealthIndicatorFunction[]): Promise<HealthCheckResult>;
8
+ }
@@ -0,0 +1,37 @@
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.HealthCheck = void 0;
13
+ const Container_1 = require("../../../../../core/infrastructure/Container");
14
+ const HealthCheckError_1 = require("../../errors/HealthCheckError");
15
+ const HealthCheckExecutor_1 = require("./HealthCheckExecutor");
16
+ let HealthCheck = class HealthCheck {
17
+ healthCheckExecutor;
18
+ constructor(healthCheckExecutor) {
19
+ this.healthCheckExecutor = healthCheckExecutor;
20
+ //
21
+ }
22
+ async check(healthIndicators) {
23
+ const result = await this.healthCheckExecutor.execute(healthIndicators);
24
+ if (result.status === 'ok') {
25
+ return result;
26
+ }
27
+ if (result.status === 'error') {
28
+ throw result;
29
+ }
30
+ throw new HealthCheckError_1.HealthCheckError('Service Unavailable');
31
+ }
32
+ };
33
+ HealthCheck = __decorate([
34
+ (0, Container_1.Service)(),
35
+ __metadata("design:paramtypes", [HealthCheckExecutor_1.HealthCheckExecutor])
36
+ ], HealthCheck);
37
+ exports.HealthCheck = HealthCheck;
@@ -0,0 +1,8 @@
1
+ import { HealthIndicatorFunction } from '../healthIndicator/HealthIndicator';
2
+ import { HealthCheckResult } from './HealthCheckResult';
3
+ export declare class HealthCheckExecutor {
4
+ execute(healthIndicators: HealthIndicatorFunction[]): Promise<HealthCheckResult>;
5
+ private executeHealthIndicators;
6
+ private getResults;
7
+ private getSummary;
8
+ }
@@ -0,0 +1,48 @@
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.HealthCheckExecutor = void 0;
10
+ const Container_1 = require("../../../../../core/infrastructure/Container");
11
+ let HealthCheckExecutor = class HealthCheckExecutor {
12
+ async execute(healthIndicators) {
13
+ const { results, errors } = await this.executeHealthIndicators(healthIndicators);
14
+ return await this.getResults(results, errors);
15
+ }
16
+ async executeHealthIndicators(healthIndicators) {
17
+ const results = [];
18
+ const errors = [];
19
+ const result = await Promise.allSettled(healthIndicators.map(async (h) => h()));
20
+ result.forEach((res) => {
21
+ if (res.status === 'fulfilled') {
22
+ results.push(res.value);
23
+ }
24
+ else {
25
+ const error = res.reason;
26
+ errors.push(error);
27
+ }
28
+ });
29
+ return { results, errors };
30
+ }
31
+ async getResults(results, errors) {
32
+ const infoErrorCombained = results.concat(errors);
33
+ const details = this.getSummary(infoErrorCombained);
34
+ let status = 'ok';
35
+ status = errors.length > 0 ? 'error' : status;
36
+ return {
37
+ status,
38
+ details
39
+ };
40
+ }
41
+ getSummary(results) {
42
+ return results.reduce((prev, curr) => Object.assign(prev, curr), {});
43
+ }
44
+ };
45
+ HealthCheckExecutor = __decorate([
46
+ (0, Container_1.Service)()
47
+ ], HealthCheckExecutor);
48
+ exports.HealthCheckExecutor = HealthCheckExecutor;
@@ -0,0 +1,6 @@
1
+ import { HealthIndicatorResult } from '../healthIndicator/HealthIndicatorResult';
2
+ export type HealthCheckStatus = 'error' | 'ok' | 'shutdown';
3
+ export interface HealthCheckResult {
4
+ status: HealthCheckStatus;
5
+ details: HealthIndicatorResult;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { HealthIndicatorResult } from './HealthIndicatorResult';
2
+ export type HealthIndicatorFunction = () => Promise<HealthIndicatorResult> | HealthIndicatorResult;
3
+ export declare abstract class HealthIndicator {
4
+ protected getStatus(key: string, isHealthy: boolean, data?: {
5
+ [key: string]: any;
6
+ }): HealthIndicatorResult;
7
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HealthIndicator = void 0;
4
+ class HealthIndicator {
5
+ getStatus(key, isHealthy, data) {
6
+ return {
7
+ [key]: {
8
+ status: isHealthy ? 'up' : 'down',
9
+ ...data
10
+ }
11
+ };
12
+ }
13
+ }
14
+ exports.HealthIndicator = HealthIndicator;
@@ -0,0 +1,7 @@
1
+ export type HealthIndicatorStatus = 'up' | 'down';
2
+ export type HealthIndicatorResult = {
3
+ [key: string]: {
4
+ status: HealthIndicatorStatus;
5
+ [key: string]: any;
6
+ };
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { HealthIndicatorResult } from '../HealthIndicatorResult';
2
+ import { HealthIndicator } from '../HealthIndicator';
3
+ export interface MongoosePingCheckOptions {
4
+ connection?: any;
5
+ /**
6
+ * The amount of time the check should require in ms
7
+ */
8
+ timeout?: number;
9
+ }
10
+ export declare class MongooseHealthIndicator extends HealthIndicator {
11
+ /**
12
+ * Checks if the MongoDB responds in (default) 1000ms and
13
+ * returns a result object corresponding to the result
14
+ *
15
+ * @example
16
+ * mongooseHealthIndicator.pingCheck('mongodb', { timeout: 1000 });
17
+ */
18
+ pingCheck(key: string, options?: MongoosePingCheckOptions): Promise<HealthIndicatorResult>;
19
+ private pingDB;
20
+ private getContextConnection;
21
+ }
@@ -0,0 +1,69 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MongooseHealthIndicator = void 0;
13
+ const HealthIndicator_1 = require("../HealthIndicator");
14
+ const mongoose_1 = __importDefault(require("mongoose"));
15
+ const ConnectionNotFoundError_1 = require("../../../errors/ConnectionNotFoundError");
16
+ const HealthCheckError_1 = require("../../../errors/HealthCheckError");
17
+ const promise_1 = require("../../../utils/promise");
18
+ const TimeoutError_1 = require("../../../errors/TimeoutError");
19
+ const Container_1 = require("../../../../../../core/infrastructure/Container");
20
+ let MongooseHealthIndicator = class MongooseHealthIndicator extends HealthIndicator_1.HealthIndicator {
21
+ /**
22
+ * Checks if the MongoDB responds in (default) 1000ms and
23
+ * returns a result object corresponding to the result
24
+ *
25
+ * @example
26
+ * mongooseHealthIndicator.pingCheck('mongodb', { timeout: 1000 });
27
+ */
28
+ async pingCheck(key, options) {
29
+ let isHealthy = false;
30
+ const connection = options?.connection || this.getContextConnection();
31
+ const timeout = options?.timeout || 1000;
32
+ if (!connection) {
33
+ throw new ConnectionNotFoundError_1.ConnectionNotFoundError();
34
+ }
35
+ try {
36
+ await this.pingDB(connection, timeout);
37
+ isHealthy = true;
38
+ }
39
+ catch (err) {
40
+ if (err instanceof TimeoutError_1.TimeoutError) {
41
+ throw new TimeoutError_1.TimeoutError(timeout);
42
+ }
43
+ }
44
+ if (isHealthy) {
45
+ return this.getStatus(key, isHealthy);
46
+ }
47
+ else {
48
+ throw this.getStatus(key, isHealthy, {
49
+ error: new HealthCheckError_1.HealthCheckError(`${key} is not available`).message
50
+ });
51
+ }
52
+ }
53
+ async pingDB(connection, timeout) {
54
+ const promise = connection.readyState === 1 ? Promise.resolve() : Promise.reject();
55
+ return await (0, promise_1.promiseTimeout)(timeout, promise);
56
+ }
57
+ getContextConnection() {
58
+ try {
59
+ return mongoose_1.default.connection;
60
+ }
61
+ catch (error) {
62
+ return null;
63
+ }
64
+ }
65
+ };
66
+ MongooseHealthIndicator = __decorate([
67
+ (0, Container_1.Service)()
68
+ ], MongooseHealthIndicator);
69
+ exports.MongooseHealthIndicator = MongooseHealthIndicator;
@@ -0,0 +1,27 @@
1
+ import { HealthIndicatorResult } from '../HealthIndicatorResult';
2
+ import { HealthIndicator } from '../HealthIndicator';
3
+ import { Sequelize } from 'sequelize';
4
+ export interface SequelizePingCheckOptions {
5
+ connection?: Sequelize;
6
+ /**
7
+ * The amount of time the check should require in ms
8
+ */
9
+ timeout?: number;
10
+ }
11
+ export declare class SequelizeHealthIndicator extends HealthIndicator {
12
+ /**
13
+ * Checks if the MySQL/PostgreSQL database responds in (default) 1000ms
14
+ * Uses existing connection pool, does NOT create new connections
15
+ *
16
+ * @example
17
+ * sequelizeHealthIndicator.pingCheck('mysql', { timeout: 1000 });
18
+ */
19
+ pingCheck(key: string, options?: SequelizePingCheckOptions): Promise<HealthIndicatorResult>;
20
+ /**
21
+ * Ping database using existing connection pool
22
+ * Uses Sequelize.authenticate() which executes a simple query (SELECT 1)
23
+ * Does NOT create new database connections
24
+ */
25
+ private pingDB;
26
+ private getContextConnection;
27
+ }
@@ -0,0 +1,73 @@
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.SequelizeHealthIndicator = void 0;
10
+ const HealthIndicator_1 = require("../HealthIndicator");
11
+ const ConnectionNotFoundError_1 = require("../../../errors/ConnectionNotFoundError");
12
+ const HealthCheckError_1 = require("../../../errors/HealthCheckError");
13
+ const promise_1 = require("../../../utils/promise");
14
+ const TimeoutError_1 = require("../../../errors/TimeoutError");
15
+ const Container_1 = require("../../../../../../core/infrastructure/Container");
16
+ let SequelizeHealthIndicator = class SequelizeHealthIndicator extends HealthIndicator_1.HealthIndicator {
17
+ /**
18
+ * Checks if the MySQL/PostgreSQL database responds in (default) 1000ms
19
+ * Uses existing connection pool, does NOT create new connections
20
+ *
21
+ * @example
22
+ * sequelizeHealthIndicator.pingCheck('mysql', { timeout: 1000 });
23
+ */
24
+ async pingCheck(key, options) {
25
+ let isHealthy = false;
26
+ const connection = options?.connection || this.getContextConnection();
27
+ const timeout = options?.timeout || 1000;
28
+ if (!connection) {
29
+ throw new ConnectionNotFoundError_1.ConnectionNotFoundError();
30
+ }
31
+ try {
32
+ await this.pingDB(connection, timeout);
33
+ isHealthy = true;
34
+ }
35
+ catch (err) {
36
+ if (err instanceof TimeoutError_1.TimeoutError) {
37
+ throw new TimeoutError_1.TimeoutError(timeout);
38
+ }
39
+ // Log error for debugging
40
+ console.error(`Health check failed for ${key}:`, err);
41
+ }
42
+ if (isHealthy) {
43
+ return this.getStatus(key, isHealthy);
44
+ }
45
+ else {
46
+ throw this.getStatus(key, isHealthy, {
47
+ error: new HealthCheckError_1.HealthCheckError(`${key} is not available`).message
48
+ });
49
+ }
50
+ }
51
+ /**
52
+ * Ping database using existing connection pool
53
+ * Uses Sequelize.authenticate() which executes a simple query (SELECT 1)
54
+ * Does NOT create new database connections
55
+ */
56
+ async pingDB(connection, timeout) {
57
+ const promise = connection.authenticate();
58
+ return await (0, promise_1.promiseTimeout)(timeout, promise);
59
+ }
60
+ getContextConnection() {
61
+ try {
62
+ const sequelize = Container_1.Container.get('sequelize');
63
+ return sequelize;
64
+ }
65
+ catch (error) {
66
+ return null;
67
+ }
68
+ }
69
+ };
70
+ SequelizeHealthIndicator = __decorate([
71
+ (0, Container_1.Service)()
72
+ ], SequelizeHealthIndicator);
73
+ exports.SequelizeHealthIndicator = SequelizeHealthIndicator;
@@ -0,0 +1,21 @@
1
+ import { HealthIndicatorResult } from '../HealthIndicatorResult';
2
+ import { HealthIndicator } from '../HealthIndicator';
3
+ export interface RabbitmqPingCheckOptions {
4
+ connection?: any;
5
+ /**
6
+ * The amount of time the check should require in ms
7
+ */
8
+ timeout?: number;
9
+ }
10
+ export declare class RabbitmqHealthIndicator extends HealthIndicator {
11
+ /**
12
+ * Checks if the RabbitMQ responds in (default) 1000ms and
13
+ * returns a result object corresponding to the result
14
+ *
15
+ * @example
16
+ * rabbitmqHealthIndicator.pingCheck('rabbitmq', { timeout: 1000 });
17
+ */
18
+ pingCheck(key: string, options?: RabbitmqPingCheckOptions): Promise<HealthIndicatorResult>;
19
+ private pingMQ;
20
+ private getContextConnection;
21
+ }