@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,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestValidationError = void 0;
4
+ const AppError_1 = require("../../core/errors/AppError");
5
+ class RequestValidationError extends AppError_1.AppError {
6
+ errors;
7
+ constructor(errors) {
8
+ super('Unprocessable Content', 422);
9
+ this.errors = errors;
10
+ }
11
+ serializeErrors() {
12
+ return this.errors
13
+ .flatMap((error) => this.mapChildrenToValidationErrors(error))
14
+ .filter((error) => !!error.constraints && !!Object.entries(error.constraints).length)
15
+ .flatMap((error) => {
16
+ return { message: Object.values(error.constraints).join(', '), field: error.property };
17
+ });
18
+ }
19
+ mapChildrenToValidationErrors(error, parentPath) {
20
+ if (!(error.children && error.children.length)) {
21
+ return [error];
22
+ }
23
+ const validationErrors = [];
24
+ parentPath = parentPath
25
+ ? `${parentPath}.${error.property}`
26
+ : error.property;
27
+ for (const item of error.children) {
28
+ if (item.children && item.children.length) {
29
+ validationErrors.push(...this.mapChildrenToValidationErrors(item, parentPath));
30
+ }
31
+ validationErrors.push(this.prependConstraintsWithParentProp(item, parentPath));
32
+ }
33
+ return validationErrors;
34
+ }
35
+ prependConstraintsWithParentProp(error, parentPath) {
36
+ const constraints = {};
37
+ for (const key in error.constraints) {
38
+ constraints[key] = `${parentPath}.${error.constraints[key]}`;
39
+ }
40
+ return {
41
+ ...error,
42
+ constraints,
43
+ };
44
+ }
45
+ }
46
+ exports.RequestValidationError = RequestValidationError;
47
+ exports.default = RequestValidationError;
@@ -0,0 +1,8 @@
1
+ import { AppError, ErrorMessage } from '../../core/errors/AppError';
2
+ export declare class ValidationError extends AppError {
3
+ protected errors: ErrorMessage[];
4
+ constructor(errors: ErrorMessage[]);
5
+ static with(error: ErrorMessage): ValidationError;
6
+ serializeErrors(): ErrorMessage[];
7
+ }
8
+ export default ValidationError;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = void 0;
4
+ const AppError_1 = require("../../core/errors/AppError");
5
+ class ValidationError extends AppError_1.AppError {
6
+ errors;
7
+ constructor(errors) {
8
+ super('Unprocessable Content', 422);
9
+ this.errors = errors;
10
+ }
11
+ static with(error) {
12
+ return new ValidationError([error]);
13
+ }
14
+ serializeErrors() {
15
+ return this.errors;
16
+ }
17
+ }
18
+ exports.ValidationError = ValidationError;
19
+ exports.default = ValidationError;
@@ -0,0 +1,5 @@
1
+ import { AppError } from '../../core/errors/AppError';
2
+ export declare class WrongAuthenticationTokenError extends AppError {
3
+ constructor();
4
+ }
5
+ export default WrongAuthenticationTokenError;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WrongAuthenticationTokenError = void 0;
4
+ const AppError_1 = require("../../core/errors/AppError");
5
+ class WrongAuthenticationTokenError extends AppError_1.AppError {
6
+ constructor() {
7
+ super('Authentication token missing', 401);
8
+ }
9
+ }
10
+ exports.WrongAuthenticationTokenError = WrongAuthenticationTokenError;
11
+ exports.default = WrongAuthenticationTokenError;
@@ -0,0 +1,5 @@
1
+ import { AppError } from '../../core/errors/AppError';
2
+ export declare class WrongCredentialsError extends AppError {
3
+ constructor();
4
+ }
5
+ export default WrongCredentialsError;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WrongCredentialsError = void 0;
4
+ const AppError_1 = require("../../core/errors/AppError");
5
+ class WrongCredentialsError extends AppError_1.AppError {
6
+ constructor() {
7
+ super('Wrong credentials provided', 401);
8
+ }
9
+ }
10
+ exports.WrongCredentialsError = WrongCredentialsError;
11
+ exports.default = WrongCredentialsError;
@@ -0,0 +1,48 @@
1
+ export * from "../core/domain/Entity";
2
+ export * from "../core/domain/Identifier";
3
+ export * from "../core/domain/UniqueId";
4
+ export * from "../core/domain/UseCase";
5
+ export * from "../core/domain/ValueObject";
6
+ export * from "../core/domain/auth/Auth";
7
+ export * from "../core/domain/auth/Authenticable";
8
+ export * from "../core/domain/auth/Guard";
9
+ export * from "../core/domain/auth/TokenGuard";
10
+ export * from "../core/domain/auth/UserProvider";
11
+ export * from "../core/infrastructure/http/App";
12
+ export * from "../core/infrastructure/events/Event";
13
+ export * from "../core/infrastructure/events/Listener";
14
+ export * from "../core/infrastructure/events/Worker";
15
+ export { Event as EventRpc } from "../core/infrastructure/events/rpc/Event";
16
+ export { Listener as ListenerRpc } from "../core/infrastructure/events/rpc/Listener";
17
+ export { Event as EventGrpc } from "../core/infrastructure/events/grpc/Event";
18
+ export { Listener as ListenerGrpc } from "../core/infrastructure/events/grpc/Listener";
19
+ export * from "../core/infrastructure/Container";
20
+ export * from "../core/infrastructure/Controller";
21
+ export * from "../core/infrastructure/Mapper";
22
+ export * from "../core/infrastructure/Repo";
23
+ export * from "../core/infrastructure/DatabaseRepository";
24
+ export * from "../core/infrastructure/loaders/Loader";
25
+ export * from "../core/infrastructure/loaders/Manager";
26
+ export * from "../core/infrastructure/cache/Cache";
27
+ /**
28
+ * @deprecated
29
+ */
30
+ export * from "../core/infrastructure/cache/InMemoryCache";
31
+ export * from "../core/infrastructure/cache/RedisCache";
32
+ export * from "../core/errors/AppError";
33
+ export * from "../core/errors/AuthenticationTokenMissingError";
34
+ export * from "../core/errors/BadRequestError";
35
+ export * from "../core/errors/NotAuthorizedError";
36
+ export * from "../core/errors/NotFoundError";
37
+ export * from "../core/errors/RequestValidationError";
38
+ export * from "../core/errors/ValidationError";
39
+ export * from "../core/errors/WrongAuthenticationTokenError";
40
+ export * from "../core/errors/WrongCredentialsError";
41
+ export * from "../core/utils/Hash";
42
+ export * from "../core/utils/Crypto";
43
+ export * from "../core/utils/commands";
44
+ export * from "../core/utils/events";
45
+ export * from "../core/utils/logger";
46
+ export * from "../core/utils/response";
47
+ export * from "../core/utils/validator";
48
+ export * from "../core/utils/cache";
package/core/index.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ListenerGrpc = exports.EventGrpc = exports.ListenerRpc = exports.EventRpc = void 0;
18
+ __exportStar(require("../core/domain/Entity"), exports);
19
+ __exportStar(require("../core/domain/Identifier"), exports);
20
+ __exportStar(require("../core/domain/UniqueId"), exports);
21
+ __exportStar(require("../core/domain/UseCase"), exports);
22
+ __exportStar(require("../core/domain/ValueObject"), exports);
23
+ __exportStar(require("../core/domain/auth/Auth"), exports);
24
+ __exportStar(require("../core/domain/auth/Authenticable"), exports);
25
+ __exportStar(require("../core/domain/auth/Guard"), exports);
26
+ __exportStar(require("../core/domain/auth/TokenGuard"), exports);
27
+ __exportStar(require("../core/domain/auth/UserProvider"), exports);
28
+ __exportStar(require("../core/infrastructure/http/App"), exports);
29
+ __exportStar(require("../core/infrastructure/events/Event"), exports);
30
+ __exportStar(require("../core/infrastructure/events/Listener"), exports);
31
+ __exportStar(require("../core/infrastructure/events/Worker"), exports);
32
+ var Event_1 = require("../core/infrastructure/events/rpc/Event");
33
+ Object.defineProperty(exports, "EventRpc", { enumerable: true, get: function () { return Event_1.Event; } });
34
+ var Listener_1 = require("../core/infrastructure/events/rpc/Listener");
35
+ Object.defineProperty(exports, "ListenerRpc", { enumerable: true, get: function () { return Listener_1.Listener; } });
36
+ var Event_2 = require("../core/infrastructure/events/grpc/Event");
37
+ Object.defineProperty(exports, "EventGrpc", { enumerable: true, get: function () { return Event_2.Event; } });
38
+ var Listener_2 = require("../core/infrastructure/events/grpc/Listener");
39
+ Object.defineProperty(exports, "ListenerGrpc", { enumerable: true, get: function () { return Listener_2.Listener; } });
40
+ __exportStar(require("../core/infrastructure/Container"), exports);
41
+ __exportStar(require("../core/infrastructure/Controller"), exports);
42
+ __exportStar(require("../core/infrastructure/Mapper"), exports);
43
+ __exportStar(require("../core/infrastructure/Repo"), exports);
44
+ __exportStar(require("../core/infrastructure/DatabaseRepository"), exports);
45
+ __exportStar(require("../core/infrastructure/loaders/Loader"), exports);
46
+ __exportStar(require("../core/infrastructure/loaders/Manager"), exports);
47
+ __exportStar(require("../core/infrastructure/cache/Cache"), exports);
48
+ /**
49
+ * @deprecated
50
+ */
51
+ __exportStar(require("../core/infrastructure/cache/InMemoryCache"), exports);
52
+ __exportStar(require("../core/infrastructure/cache/RedisCache"), exports);
53
+ __exportStar(require("../core/errors/AppError"), exports);
54
+ __exportStar(require("../core/errors/AuthenticationTokenMissingError"), exports);
55
+ __exportStar(require("../core/errors/BadRequestError"), exports);
56
+ __exportStar(require("../core/errors/NotAuthorizedError"), exports);
57
+ __exportStar(require("../core/errors/NotFoundError"), exports);
58
+ __exportStar(require("../core/errors/RequestValidationError"), exports);
59
+ __exportStar(require("../core/errors/ValidationError"), exports);
60
+ __exportStar(require("../core/errors/WrongAuthenticationTokenError"), exports);
61
+ __exportStar(require("../core/errors/WrongCredentialsError"), exports);
62
+ __exportStar(require("../core/utils/Hash"), exports);
63
+ __exportStar(require("../core/utils/Crypto"), exports);
64
+ __exportStar(require("../core/utils/commands"), exports);
65
+ __exportStar(require("../core/utils/events"), exports);
66
+ __exportStar(require("../core/utils/logger"), exports);
67
+ __exportStar(require("../core/utils/response"), exports);
68
+ __exportStar(require("../core/utils/validator"), exports);
69
+ __exportStar(require("../core/utils/cache"), exports);
@@ -0,0 +1 @@
1
+ export { Container, ContainerInstance, Service, Inject } from 'typedi';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Inject = exports.Service = exports.ContainerInstance = exports.Container = void 0;
4
+ var typedi_1 = require("typedi");
5
+ Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return typedi_1.Container; } });
6
+ Object.defineProperty(exports, "ContainerInstance", { enumerable: true, get: function () { return typedi_1.ContainerInstance; } });
7
+ Object.defineProperty(exports, "Service", { enumerable: true, get: function () { return typedi_1.Service; } });
8
+ Object.defineProperty(exports, "Inject", { enumerable: true, get: function () { return typedi_1.Inject; } });
@@ -0,0 +1,9 @@
1
+ import { Response, Router } from 'express';
2
+ export declare abstract class Controller {
3
+ router: Router;
4
+ constructor();
5
+ abstract registerRoutes(): void;
6
+ ok<T>(res: Response, dto?: T): Response<any, Record<string, any>>;
7
+ created(res: Response): Response<any, Record<string, any>>;
8
+ fail(res: Response, error: Error | string): void;
9
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Controller = void 0;
4
+ const express_1 = require("express");
5
+ const response_1 = require("../../core/utils/response");
6
+ const AppError_1 = require("../../core/errors/AppError");
7
+ class Controller {
8
+ router = (0, express_1.Router)();
9
+ constructor() {
10
+ this.registerRoutes();
11
+ }
12
+ ok(res, dto) {
13
+ if (!!dto) {
14
+ return (0, response_1.sendSuccessResponse)(res, dto, 200);
15
+ }
16
+ else {
17
+ return res.sendStatus(200);
18
+ }
19
+ }
20
+ created(res) {
21
+ return res.sendStatus(201);
22
+ }
23
+ fail(res, error) {
24
+ if (error instanceof Error) {
25
+ throw error;
26
+ }
27
+ throw new AppError_1.AppError(error);
28
+ }
29
+ }
30
+ exports.Controller = Controller;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Interface representing a repository for database operations.
3
+ */
4
+ export default interface DatabaseRepository {
5
+ /**
6
+ * Save an entity to the database.
7
+ * @param entity - The entity to be saved.
8
+ * @returns A promise that resolves to the saved entity.
9
+ */
10
+ save(entity: any): Promise<any>;
11
+ /**
12
+ * Retrieve an entity from the database by its ID.
13
+ * @param id - The ID of the entity to be retrieved.
14
+ * @returns A promise that resolves to the retrieved entity.
15
+ */
16
+ show(id: string): Promise<any>;
17
+ /**
18
+ * List entities from the database based on the provided request.
19
+ * @param req - The request object containing query pagination parameters.
20
+ * @returns A promise that resolves to the list of entities.
21
+ */
22
+ list(req: any): Promise<any>;
23
+ /**
24
+ * Update an entity in the database.
25
+ * @param entity - The entity with updated values.
26
+ * @returns A promise that resolves to the updated entity.
27
+ */
28
+ update(entity: any): Promise<any>;
29
+ /**
30
+ * Delete an entity from the database.
31
+ * @param id - The ID of the entity to be deleted.
32
+ * @returns A promise that resolves to the result of the deletion operation.
33
+ */
34
+ delete(id: string): Promise<any>;
35
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare abstract class Mapper<T> {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Mapper = void 0;
4
+ class Mapper {
5
+ }
6
+ exports.Mapper = Mapper;
@@ -0,0 +1,2 @@
1
+ export declare abstract class Repo<T> {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Repo = void 0;
4
+ class Repo {
5
+ }
6
+ exports.Repo = Repo;
@@ -0,0 +1,47 @@
1
+ import { Repo } from '../../../core/infrastructure/cache/Repo';
2
+ type CacheDriver = 'null' | 'array' | 'file' | 'redis';
3
+ type StoreConfig = {
4
+ driver: CacheDriver;
5
+ [key: string]: any;
6
+ };
7
+ export type CacheConfig = {
8
+ store: string;
9
+ stores: {
10
+ [key: string]: StoreConfig;
11
+ };
12
+ prefix: string;
13
+ };
14
+ export declare class Cache {
15
+ protected stores: {
16
+ [key: string]: Repo;
17
+ };
18
+ protected readonly config: CacheConfig;
19
+ constructor(config: CacheConfig);
20
+ driver(driver?: CacheDriver): Repo;
21
+ protected store(name?: string): Repo;
22
+ protected resolve(name: string): any;
23
+ protected getConfig(name: string): {
24
+ driver: string;
25
+ };
26
+ protected getPrefix(): string;
27
+ protected getDefaultDriver(): string;
28
+ protected nullDriver(config: StoreConfig): Repo;
29
+ protected arrayDriver(config: StoreConfig): Repo;
30
+ protected fileDriver(config: StoreConfig): Repo;
31
+ protected redisDriver(config: StoreConfig): Repo;
32
+ /**
33
+ * CacheContract
34
+ */
35
+ has(key: string): Promise<boolean>;
36
+ missing(key: string): Promise<boolean>;
37
+ get<T>(key: string, _default?: any): Promise<T | null>;
38
+ pull<T>(key: string, _default?: any): Promise<T | null>;
39
+ put(key: string, value: any, ttl?: number): Promise<boolean>;
40
+ add(key: string, value: any, ttl?: number): Promise<boolean>;
41
+ forever(key: string, value: any): Promise<boolean>;
42
+ remember<T>(key: string, callback: Function, ttl?: number): Promise<T>;
43
+ rememberForever<T>(key: string, callback: Function): Promise<T>;
44
+ forget(key: string): Promise<boolean>;
45
+ flush(): Promise<boolean>;
46
+ }
47
+ export {};
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cache = void 0;
4
+ const ioredis_1 = require("ioredis");
5
+ const Repo_1 = require("../../../core/infrastructure/cache/Repo");
6
+ const NullStore_1 = require("../../../core/infrastructure/cache/stores/NullStore");
7
+ const ArrayStore_1 = require("../../../core/infrastructure/cache/stores/ArrayStore");
8
+ const RedisStore_1 = require("../../../core/infrastructure/cache/stores/RedisStore");
9
+ const FileStore_1 = require("../../../core/infrastructure/cache/stores/FileStore");
10
+ class Cache {
11
+ stores = {};
12
+ config;
13
+ constructor(config) {
14
+ this.config = config;
15
+ }
16
+ driver(driver) {
17
+ return this.store(driver);
18
+ }
19
+ store(name) {
20
+ name = name || this.getDefaultDriver();
21
+ if (!(name in this.stores)) {
22
+ this.stores[name] = this.resolve(name);
23
+ }
24
+ return this.stores[name];
25
+ }
26
+ resolve(name) {
27
+ const config = this.getConfig(name);
28
+ if (!config) {
29
+ throw new Error(`Cache store [${name}] is not defined.`);
30
+ }
31
+ const driverMethod = config.driver + 'Driver';
32
+ if (this[driverMethod]) {
33
+ return this[driverMethod](config);
34
+ }
35
+ throw new Error(`Cache driver [${config.driver}] is not supported.`);
36
+ }
37
+ getConfig(name) {
38
+ if (name && name !== 'null') {
39
+ return this.config.stores[name];
40
+ }
41
+ return { driver: 'null' };
42
+ }
43
+ getPrefix() {
44
+ return this.config.prefix;
45
+ }
46
+ getDefaultDriver() {
47
+ return this.config.store;
48
+ }
49
+ nullDriver(config) {
50
+ return new Repo_1.Repo(new NullStore_1.NullStore());
51
+ }
52
+ arrayDriver(config) {
53
+ return new Repo_1.Repo(new ArrayStore_1.ArrayStore());
54
+ }
55
+ fileDriver(config) {
56
+ const path = config.path || 'storage/cache/data';
57
+ return new Repo_1.Repo(new FileStore_1.FileStore(path));
58
+ }
59
+ redisDriver(config) {
60
+ const redis = new ioredis_1.Redis(config.redisUrl);
61
+ const prefix = this.getPrefix();
62
+ return new Repo_1.Repo(new RedisStore_1.RedisStore(redis, prefix));
63
+ }
64
+ /**
65
+ * CacheContract
66
+ */
67
+ async has(key) {
68
+ return await this.store().has(key);
69
+ }
70
+ async missing(key) {
71
+ return await this.store().missing(key);
72
+ }
73
+ async get(key, _default) {
74
+ return await this.store().get(key, _default);
75
+ }
76
+ async pull(key, _default) {
77
+ return await this.store().pull(key, _default);
78
+ }
79
+ async put(key, value, ttl) {
80
+ return await this.store().put(key, value, ttl);
81
+ }
82
+ async add(key, value, ttl) {
83
+ return await this.store().add(key, value, ttl);
84
+ }
85
+ async forever(key, value) {
86
+ return await this.store().forever(key, value);
87
+ }
88
+ async remember(key, callback, ttl) {
89
+ return await this.store().remember(key, callback, ttl);
90
+ }
91
+ async rememberForever(key, callback) {
92
+ return await this.store().rememberForever(key, callback);
93
+ }
94
+ async forget(key) {
95
+ return await this.store().forget(key);
96
+ }
97
+ async flush() {
98
+ return await this.store().flush();
99
+ }
100
+ }
101
+ exports.Cache = Cache;
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import { Cache as CacheContract } from '../../../core/domain/cache/Cache';
3
+ type CacheRecord<T> = {
4
+ data: T;
5
+ expire: number;
6
+ };
7
+ /**
8
+ * @deprecated
9
+ */
10
+ export declare class InMemoryCache implements CacheContract {
11
+ protected readonly TTL: number;
12
+ protected readonly store: Map<string, CacheRecord<any>>;
13
+ protected readonly timeoutRefs: Map<string, NodeJS.Timeout>;
14
+ constructor();
15
+ get<T>(key: string): Promise<T | null>;
16
+ set<T>(key: string, data: T, ttl?: number): Promise<void>;
17
+ invalidate(key: string): Promise<void>;
18
+ clear(): Promise<void>;
19
+ }
20
+ export {};
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryCache = void 0;
4
+ const DEFAULT_TTL_IN_SECONDS = 30; // seconds
5
+ /**
6
+ * @deprecated
7
+ */
8
+ class InMemoryCache {
9
+ TTL;
10
+ store = new Map();
11
+ timeoutRefs = new Map();
12
+ constructor() {
13
+ this.TTL = DEFAULT_TTL_IN_SECONDS;
14
+ }
15
+ async get(key) {
16
+ const now = Date.now();
17
+ const record = this.store.get(key);
18
+ const expiration = record?.expire ?? Infinity;
19
+ if (!record || expiration < now) {
20
+ return null;
21
+ }
22
+ return record.data;
23
+ }
24
+ async set(key, data, ttl = this.TTL) {
25
+ if (ttl === 0) {
26
+ return;
27
+ }
28
+ const record = { data, expire: ttl * 1000 + Date.now() };
29
+ const oldRecord = this.store.get(key);
30
+ if (oldRecord) {
31
+ clearTimeout(this.timeoutRefs.get(key));
32
+ this.timeoutRefs.delete(key);
33
+ }
34
+ const ref = setTimeout(async () => {
35
+ await this.invalidate(key);
36
+ }, ttl * 1000);
37
+ ref.unref();
38
+ this.timeoutRefs.set(key, ref);
39
+ this.store.set(key, record);
40
+ }
41
+ async invalidate(key) {
42
+ let keys = [key];
43
+ if (key.includes("*")) {
44
+ const regExp = new RegExp(key.replace("*", ".*"));
45
+ keys = Array.from(this.store.keys()).filter((k) => k.match(regExp));
46
+ }
47
+ keys.forEach((key) => {
48
+ const timeoutRef = this.timeoutRefs.get(key);
49
+ if (timeoutRef) {
50
+ clearTimeout(timeoutRef);
51
+ this.timeoutRefs.delete(key);
52
+ }
53
+ this.store.delete(key);
54
+ });
55
+ }
56
+ async clear() {
57
+ this.timeoutRefs.forEach((ref) => clearTimeout(ref));
58
+ this.timeoutRefs.clear();
59
+ this.store.clear();
60
+ }
61
+ }
62
+ exports.InMemoryCache = InMemoryCache;
@@ -0,0 +1,15 @@
1
+ import { Cache as CacheContract } from '../../../core/domain/cache/Cache';
2
+ import { Redis } from 'ioredis';
3
+ /**
4
+ * @deprecated
5
+ */
6
+ export declare class RedisCache implements CacheContract {
7
+ protected readonly TTL: number;
8
+ protected readonly redis: Redis;
9
+ private readonly namespace;
10
+ constructor();
11
+ get<T>(key: string): Promise<T | null>;
12
+ set(key: string, data: Record<string, unknown>, ttl?: number): Promise<void>;
13
+ invalidate(key: string): Promise<void>;
14
+ private getCacheKey;
15
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisCache = void 0;
4
+ const ioredis_1 = require("ioredis");
5
+ const DEFAULT_NAMESPACE = "waba";
6
+ const DEFAULT_CACHE_TIME_IN_SECONDS = 30;
7
+ const EXPIRY_MODE = "EX";
8
+ /**
9
+ * @deprecated
10
+ */
11
+ class RedisCache {
12
+ TTL;
13
+ redis;
14
+ namespace;
15
+ constructor() {
16
+ this.redis = new ioredis_1.Redis(process.env.REDIS_URL);
17
+ this.TTL = DEFAULT_CACHE_TIME_IN_SECONDS;
18
+ this.namespace = DEFAULT_NAMESPACE;
19
+ }
20
+ async get(key) {
21
+ key = this.getCacheKey(key);
22
+ try {
23
+ const cached = await this.redis.get(key);
24
+ if (cached) {
25
+ return JSON.parse(cached);
26
+ }
27
+ }
28
+ catch (error) {
29
+ await this.redis.del(key);
30
+ }
31
+ return null;
32
+ }
33
+ async set(key, data, ttl = this.TTL) {
34
+ if (ttl === 0) {
35
+ return;
36
+ }
37
+ await this.redis.set(this.getCacheKey(key), JSON.stringify(data), EXPIRY_MODE, ttl);
38
+ }
39
+ async invalidate(key) {
40
+ const keys = await this.redis.keys(this.getCacheKey(key));
41
+ const pipeline = this.redis.pipeline();
42
+ keys.forEach(function (key) {
43
+ pipeline.del(key);
44
+ });
45
+ await pipeline.exec();
46
+ }
47
+ getCacheKey(key) {
48
+ return this.namespace ? `${this.namespace}:${key}` : key;
49
+ }
50
+ }
51
+ exports.RedisCache = RedisCache;