@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,66 @@
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.RabbitmqHealthIndicator = void 0;
10
+ const HealthIndicator_1 = require("../HealthIndicator");
11
+ const ConnectionNotFoundError_1 = require("../../../errors/ConnectionNotFoundError");
12
+ const TimeoutError_1 = require("../../../errors/TimeoutError");
13
+ const HealthCheckError_1 = require("../../../errors/HealthCheckError");
14
+ const promise_1 = require("../../../utils/promise");
15
+ const Connection_1 = require("../../../../../../core/infrastructure/events/Connection");
16
+ const Container_1 = require("../../../../../../core/infrastructure/Container");
17
+ let RabbitmqHealthIndicator = class RabbitmqHealthIndicator extends HealthIndicator_1.HealthIndicator {
18
+ /**
19
+ * Checks if the RabbitMQ responds in (default) 1000ms and
20
+ * returns a result object corresponding to the result
21
+ *
22
+ * @example
23
+ * rabbitmqHealthIndicator.pingCheck('rabbitmq', { timeout: 1000 });
24
+ */
25
+ async pingCheck(key, options) {
26
+ let isHealthy = false;
27
+ const connection = options?.connection || this.getContextConnection();
28
+ const timeout = options?.timeout || 1000;
29
+ if (!connection) {
30
+ throw new ConnectionNotFoundError_1.ConnectionNotFoundError();
31
+ }
32
+ try {
33
+ await this.pingMQ(connection, timeout);
34
+ isHealthy = true;
35
+ }
36
+ catch (err) {
37
+ if (err instanceof TimeoutError_1.TimeoutError) {
38
+ throw new TimeoutError_1.TimeoutError(timeout);
39
+ }
40
+ }
41
+ if (isHealthy) {
42
+ return this.getStatus(key, isHealthy);
43
+ }
44
+ else {
45
+ throw this.getStatus(key, isHealthy, {
46
+ error: new HealthCheckError_1.HealthCheckError(`${key} is not available`).message
47
+ });
48
+ }
49
+ }
50
+ async pingMQ(connection, timeout) {
51
+ const promise = connection.isConnected() ? Promise.resolve() : Promise.reject();
52
+ return await (0, promise_1.promiseTimeout)(timeout, promise);
53
+ }
54
+ getContextConnection() {
55
+ try {
56
+ return Connection_1.Connection.getConnection();
57
+ }
58
+ catch (error) {
59
+ return null;
60
+ }
61
+ }
62
+ };
63
+ RabbitmqHealthIndicator = __decorate([
64
+ (0, Container_1.Service)()
65
+ ], RabbitmqHealthIndicator);
66
+ exports.RabbitmqHealthIndicator = RabbitmqHealthIndicator;
@@ -0,0 +1 @@
1
+ export declare const promiseTimeout: (ms: number, promise: Promise<any>) => Promise<any>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promiseTimeout = void 0;
4
+ const TimeoutError_1 = require("../errors/TimeoutError");
5
+ const promiseTimeout = function (ms, promise) {
6
+ let timer;
7
+ return Promise.race([
8
+ promise,
9
+ new Promise((_, reject) => (timer = setTimeout(() => reject(new TimeoutError_1.TimeoutError(ms)), ms))),
10
+ ]).finally(() => clearTimeout(timer));
11
+ };
12
+ exports.promiseTimeout = promiseTimeout;
@@ -0,0 +1,6 @@
1
+ import { Request, Response } from 'express';
2
+ import { Controller } from '../../../../../core/infrastructure/Controller';
3
+ export default class DetailController extends Controller {
4
+ registerRoutes(): void;
5
+ show(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
6
+ }
@@ -0,0 +1,25 @@
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
+ const Container_1 = require("../../../../../core/infrastructure/Container");
10
+ const Controller_1 = require("../../../../../core/infrastructure/Controller");
11
+ let DetailController = class DetailController extends Controller_1.Controller {
12
+ registerRoutes() {
13
+ this.router.get('/', this.show.bind(this));
14
+ }
15
+ async show(req, res) {
16
+ return this.ok(res, {
17
+ name: process.env.npm_package_name,
18
+ version: process.env.npm_package_version
19
+ });
20
+ }
21
+ };
22
+ DetailController = __decorate([
23
+ (0, Container_1.Service)()
24
+ ], DetailController);
25
+ exports.default = DetailController;
@@ -0,0 +1,24 @@
1
+ export declare enum CryptoAlgorithm {
2
+ AES256CTR = "aes-256-ctr",
3
+ AES256GCM = "aes-256-gcm",
4
+ AES256ECB = "aes-256-ecb"
5
+ }
6
+ export declare class Crypto {
7
+ static secretKey: string;
8
+ /**
9
+ * Make a encrypted text using key process.env.SECRET_KEY with the spesific algorithm.
10
+ * Please see CryptoAlgorithm enum for supported algorithm
11
+ * @param plain string
12
+ * @param algorithm CryptoAlgorithm
13
+ * @returns string
14
+ */
15
+ static encrypt: (plain: string, algorithm?: string) => string;
16
+ /**
17
+ * Decrypt the chipper message using key process.env.SECRET_KEY with the spesific algorithm.
18
+ * Please see CryptoAlgorithm enum for supported algorithm
19
+ * @param cryptedMessage string
20
+ * @param algorithm CryptoAlgorithm
21
+ * @returns string
22
+ */
23
+ static decrypt: (cryptedMessage: string, algorithm?: string) => string;
24
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Crypto = exports.CryptoAlgorithm = void 0;
4
+ const crypto_1 = require("crypto");
5
+ var CryptoAlgorithm;
6
+ (function (CryptoAlgorithm) {
7
+ CryptoAlgorithm["AES256CTR"] = "aes-256-ctr";
8
+ CryptoAlgorithm["AES256GCM"] = "aes-256-gcm";
9
+ CryptoAlgorithm["AES256ECB"] = "aes-256-ecb";
10
+ })(CryptoAlgorithm = exports.CryptoAlgorithm || (exports.CryptoAlgorithm = {}));
11
+ var CryptoError;
12
+ (function (CryptoError) {
13
+ CryptoError["UNKNOWN_ALGORITHM"] = "Unknown algorithm.";
14
+ CryptoError["INVALID_ENCRYPTED_FORMAT"] = "Invalid encrypted data format.";
15
+ })(CryptoError || (CryptoError = {}));
16
+ class Crypto {
17
+ static secretKey = process.env.SECRET_KEY ?? "this-is-secret-key";
18
+ /**
19
+ * Make a encrypted text using key process.env.SECRET_KEY with the spesific algorithm.
20
+ * Please see CryptoAlgorithm enum for supported algorithm
21
+ * @param plain string
22
+ * @param algorithm CryptoAlgorithm
23
+ * @returns string
24
+ */
25
+ static encrypt = (plain, algorithm = CryptoAlgorithm.AES256CTR) => {
26
+ if (algorithm == CryptoAlgorithm.AES256CTR) {
27
+ const key = (0, crypto_1.createHash)("sha256").update(Crypto.secretKey).digest();
28
+ const nonce = (0, crypto_1.randomBytes)(16);
29
+ const cipher = (0, crypto_1.createCipheriv)("aes-256-ctr", key, nonce);
30
+ let encrypted = cipher.update(plain, "utf8", "hex");
31
+ encrypted += cipher.final("hex");
32
+ return nonce.toString("hex") + ":" + encrypted;
33
+ }
34
+ if (algorithm == CryptoAlgorithm.AES256GCM) {
35
+ const keyBuffer = (0, crypto_1.createHash)("sha256").update(this.secretKey).digest();
36
+ const iv = (0, crypto_1.randomBytes)(12); // 96-bit IV for AES-GCM
37
+ const cipher = (0, crypto_1.createCipheriv)("aes-256-gcm", keyBuffer, iv);
38
+ let encrypted = cipher.update(plain, "utf8", "hex");
39
+ encrypted += cipher.final("hex");
40
+ const tag = cipher.getAuthTag();
41
+ return `${iv.toString("hex")}-${tag.toString("hex")}-${encrypted}`;
42
+ }
43
+ if (algorithm == CryptoAlgorithm.AES256ECB) {
44
+ const key = (0, crypto_1.createHash)("sha256").update(Crypto.secretKey).digest();
45
+ const cipher = (0, crypto_1.createCipheriv)("aes-256-ecb", key, null);
46
+ let encrypted = cipher.update(plain, "utf8", "hex");
47
+ encrypted += cipher.final("hex");
48
+ return encrypted;
49
+ }
50
+ throw new Error(CryptoError.UNKNOWN_ALGORITHM);
51
+ };
52
+ /**
53
+ * Decrypt the chipper message using key process.env.SECRET_KEY with the spesific algorithm.
54
+ * Please see CryptoAlgorithm enum for supported algorithm
55
+ * @param cryptedMessage string
56
+ * @param algorithm CryptoAlgorithm
57
+ * @returns string
58
+ */
59
+ static decrypt = (cryptedMessage, algorithm = CryptoAlgorithm.AES256CTR) => {
60
+ if (algorithm == CryptoAlgorithm.AES256CTR) {
61
+ const parts = cryptedMessage.split(":");
62
+ if (parts.length !== 2)
63
+ throw new Error(CryptoError.INVALID_ENCRYPTED_FORMAT);
64
+ const nonce = Buffer.from(parts[0], "hex");
65
+ const content = parts[1];
66
+ const key = (0, crypto_1.createHash)("sha256").update(Crypto.secretKey).digest();
67
+ const decipher = (0, crypto_1.createDecipheriv)("aes-256-ctr", key, nonce);
68
+ let decrypted = decipher.update(content, "hex", "utf8");
69
+ decrypted += decipher.final("utf8");
70
+ return decrypted;
71
+ }
72
+ if (algorithm == CryptoAlgorithm.AES256GCM) {
73
+ const keyBuffer = (0, crypto_1.createHash)("sha256").update(this.secretKey).digest();
74
+ const parts = cryptedMessage.split("-");
75
+ if (parts.length !== 3)
76
+ throw new Error(CryptoError.INVALID_ENCRYPTED_FORMAT);
77
+ const decipher = (0, crypto_1.createDecipheriv)("aes-256-gcm", keyBuffer, Buffer.from(parts[0], "hex"));
78
+ decipher.setAuthTag(Buffer.from(parts[1], "hex"));
79
+ let decrypted = decipher.update(parts[2], "hex", "utf8");
80
+ decrypted += decipher.final("utf8");
81
+ return decrypted;
82
+ }
83
+ if (algorithm == CryptoAlgorithm.AES256ECB) {
84
+ const key = (0, crypto_1.createHash)("sha256").update(Crypto.secretKey).digest();
85
+ const decipher = (0, crypto_1.createDecipheriv)("aes-256-ecb", key, null);
86
+ let decrypted = decipher.update(cryptedMessage, "hex", "utf8");
87
+ decrypted += decipher.final("utf8");
88
+ return decrypted;
89
+ }
90
+ throw new Error(CryptoError.UNKNOWN_ALGORITHM);
91
+ };
92
+ }
93
+ exports.Crypto = Crypto;
@@ -0,0 +1,6 @@
1
+ export declare class Hash {
2
+ static make: (text: string) => string;
3
+ static compare: (text: string, hash: string) => boolean;
4
+ static sha256: (text: string) => string;
5
+ private static encrypt;
6
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hash = void 0;
4
+ const crypto_1 = require("crypto");
5
+ class Hash {
6
+ static make = (text) => {
7
+ const salt = (0, crypto_1.randomBytes)(16).toString('hex');
8
+ return Hash.encrypt(text, salt) + salt;
9
+ };
10
+ static compare = (text, hash) => {
11
+ const salt = hash.slice(64);
12
+ const originalTextHash = hash.slice(0, 64);
13
+ const currentTextHash = Hash.encrypt(text, salt);
14
+ return originalTextHash === currentTextHash;
15
+ };
16
+ static sha256 = (text) => {
17
+ return (0, crypto_1.createHash)('sha256').update(text).digest('hex');
18
+ };
19
+ static encrypt = (text, salt) => {
20
+ return (0, crypto_1.scryptSync)(text, salt, 32).toString('hex');
21
+ };
22
+ }
23
+ exports.Hash = Hash;
@@ -0,0 +1 @@
1
+ export declare function cache<T>(key: string, callback: Function, ttl?: number): Promise<any>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cache = void 0;
4
+ const Container_1 = require("../../core/infrastructure/Container");
5
+ async function cache(key, callback, ttl = 30) {
6
+ const cache = Container_1.Container.get('cacheService');
7
+ const value = await cache.get(key);
8
+ if (value) {
9
+ return value;
10
+ }
11
+ return callback().then(async (data) => {
12
+ await cache.set(key, data, ttl);
13
+ return data;
14
+ });
15
+ }
16
+ exports.cache = cache;
@@ -0,0 +1,2 @@
1
+ import { Command } from '../../core/domain/Command';
2
+ export declare function executor(command: Command): Promise<any>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executor = void 0;
4
+ async function executor(command) {
5
+ return await command.execute();
6
+ }
7
+ exports.executor = executor;
@@ -0,0 +1,3 @@
1
+ import { Event, EventOptions } from "../../core/domain/events/Event";
2
+ export declare function dispatcher(publisher: Event, options?: EventOptions): Promise<any>;
3
+ export declare function dispatcherWithoutPersistence(publisher: Event, options?: EventOptions): Promise<any>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dispatcherWithoutPersistence = exports.dispatcher = void 0;
4
+ async function dispatcher(publisher, options) {
5
+ return await publisher.init().publish(options);
6
+ }
7
+ exports.dispatcher = dispatcher;
8
+ async function dispatcherWithoutPersistence(publisher, options) {
9
+ return await publisher.init().publishWithoutPersistence(options);
10
+ }
11
+ exports.dispatcherWithoutPersistence = dispatcherWithoutPersistence;
@@ -0,0 +1,2 @@
1
+ export declare const logger: import("winston").Logger;
2
+ export default logger;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = void 0;
4
+ const winston_1 = require("winston");
5
+ exports.logger = (0, winston_1.createLogger)({
6
+ level: process.env.LOG_LEVEL,
7
+ format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.json()),
8
+ transports: [
9
+ new winston_1.transports.Console()
10
+ ],
11
+ exceptionHandlers: [
12
+ new winston_1.transports.Console()
13
+ ]
14
+ });
15
+ exports.default = exports.logger;
@@ -0,0 +1,4 @@
1
+ import { Response } from 'express';
2
+ import { ErrorMessage } from '../../core/errors/AppError';
3
+ export declare function sendSuccessResponse(res: Response, data: any, status?: number): Response<any, Record<string, any>>;
4
+ export declare function sendErrorResponse(res: Response, error: ErrorMessage[], status?: number): Response<any, Record<string, any>>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendErrorResponse = exports.sendSuccessResponse = void 0;
4
+ function sendSuccessResponse(res, data, status = 200) {
5
+ return res.status(status).json({ status, data });
6
+ }
7
+ exports.sendSuccessResponse = sendSuccessResponse;
8
+ function sendErrorResponse(res, error, status = 500) {
9
+ return res.status(status).json({ status, error });
10
+ }
11
+ exports.sendErrorResponse = sendErrorResponse;
@@ -0,0 +1,4 @@
1
+ import { ValidatorOptions } from 'class-validator';
2
+ export type Klass<T> = new (...args: any[]) => T;
3
+ export declare function transformAndValidate<T extends object>(klass: Klass<T>, object: object, options?: ValidatorOptions): T;
4
+ export default transformAndValidate;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformAndValidate = void 0;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const class_validator_1 = require("class-validator");
6
+ const RequestValidationError_1 = require("../../core/errors/RequestValidationError");
7
+ function transformAndValidate(klass, object, options) {
8
+ object = normalizeObject(object);
9
+ const classObject = (0, class_transformer_1.plainToClass)(klass, object, { enableImplicitConversion: false });
10
+ const errors = (0, class_validator_1.validateSync)(classObject, options ? options : void 0);
11
+ if (errors.length) {
12
+ throw new RequestValidationError_1.RequestValidationError(errors);
13
+ }
14
+ return classObject;
15
+ }
16
+ exports.transformAndValidate = transformAndValidate;
17
+ function normalizeObject(object) {
18
+ let normalObject = {};
19
+ for (let key in object) {
20
+ const newKey = key.replace(/\[(.*?)\]/, '$1');
21
+ if (typeof object[key] !== 'object') {
22
+ normalObject[newKey] = object[key];
23
+ }
24
+ else if (Array.isArray(object[key])) {
25
+ normalObject[newKey] = normilizeArray(object[key]);
26
+ }
27
+ else if (object.hasOwnProperty(key)) {
28
+ normalObject[newKey] = normalizeObject(object[key]);
29
+ }
30
+ }
31
+ return normalObject;
32
+ }
33
+ function normilizeArray(array) {
34
+ let normalArray = [];
35
+ normalArray = array.map((item) => {
36
+ if (typeof item !== 'object') {
37
+ return item;
38
+ }
39
+ else if (Array.isArray(item)) {
40
+ return normilizeArray(item);
41
+ }
42
+ else {
43
+ return normalizeObject(item);
44
+ }
45
+ });
46
+ return normalArray;
47
+ }
48
+ exports.default = transformAndValidate;
@@ -0,0 +1,18 @@
1
+ export declare enum BalanceMutationType {
2
+ Credit = "credit",
3
+ Debit = "debit"
4
+ }
5
+ export interface BalanceMutation {
6
+ accountId: string;
7
+ account?: any;
8
+ creatorId?: string;
9
+ creatorName?: string;
10
+ amount: number;
11
+ resource: string;
12
+ resourceName: string;
13
+ type: BalanceMutationType;
14
+ notes: string;
15
+ before?: number;
16
+ after?: number;
17
+ }
18
+ export default BalanceMutation;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BalanceMutationType = void 0;
4
+ var BalanceMutationType;
5
+ (function (BalanceMutationType) {
6
+ BalanceMutationType["Credit"] = "credit";
7
+ BalanceMutationType["Debit"] = "debit";
8
+ })(BalanceMutationType = exports.BalanceMutationType || (exports.BalanceMutationType = {}));
@@ -0,0 +1,18 @@
1
+ export interface ProviderConfig {
2
+ accessToken?: string;
3
+ client?: string;
4
+ expiry?: string;
5
+ uid?: string;
6
+ wabaId?: string;
7
+ version?: string;
8
+ phoneNumberId?: string;
9
+ }
10
+ export interface ChannelWhatsapp {
11
+ _id?: string;
12
+ accountId: string;
13
+ account?: any;
14
+ phone: string;
15
+ provider?: string;
16
+ providerConfig?: ProviderConfig;
17
+ }
18
+ export default ChannelWhatsapp;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ export declare enum MessageTemplateStatus {
2
+ Draft = "draft",
3
+ Scheduled = "scheduled",
4
+ Published = "published",
5
+ Approved = "approved",
6
+ Declined = "declined",
7
+ Failed = "failed"
8
+ }
9
+ export interface MessageTemplate {
10
+ _id?: string;
11
+ name: string;
12
+ payload: any;
13
+ status: MessageTemplateStatus;
14
+ createdAt: any;
15
+ updatedAt: any;
16
+ senderId?: any;
17
+ sender?: any;
18
+ sourceId?: string;
19
+ sourceStatus?: string;
20
+ sourceReason?: string;
21
+ accountId: any;
22
+ account?: any;
23
+ notes?: any;
24
+ sentAt?: Date;
25
+ }
26
+ export default MessageTemplate;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageTemplateStatus = void 0;
4
+ var MessageTemplateStatus;
5
+ (function (MessageTemplateStatus) {
6
+ MessageTemplateStatus["Draft"] = "draft";
7
+ MessageTemplateStatus["Scheduled"] = "scheduled";
8
+ MessageTemplateStatus["Published"] = "published";
9
+ MessageTemplateStatus["Approved"] = "approved";
10
+ MessageTemplateStatus["Declined"] = "declined";
11
+ MessageTemplateStatus["Failed"] = "failed";
12
+ })(MessageTemplateStatus = exports.MessageTemplateStatus || (exports.MessageTemplateStatus = {}));
@@ -0,0 +1,8 @@
1
+ export interface MessageTemplateCategoryUpdate {
2
+ sourceId: string;
3
+ sourceName: string;
4
+ sourceLanguage: string;
5
+ category: string;
6
+ categoryOld: string;
7
+ }
8
+ export default MessageTemplateCategoryUpdate;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export interface MessageTemplateStatusUpdate {
2
+ sourceId: string;
3
+ sourceStatus?: string;
4
+ sourceReason?: string;
5
+ status: string;
6
+ notes?: string;
7
+ }
8
+ export default MessageTemplateStatusUpdate;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ export declare enum PaymentType {
2
+ Credit = "credit",
3
+ Debit = "debit"
4
+ }
5
+ export interface Payment {
6
+ accountId: string;
7
+ account?: any;
8
+ amount: number;
9
+ resource?: string;
10
+ resourceName?: string;
11
+ type: PaymentType;
12
+ notes: string;
13
+ }
14
+ export default Payment;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaymentType = void 0;
4
+ var PaymentType;
5
+ (function (PaymentType) {
6
+ PaymentType["Credit"] = "credit";
7
+ PaymentType["Debit"] = "debit";
8
+ })(PaymentType = exports.PaymentType || (exports.PaymentType = {}));
@@ -0,0 +1,33 @@
1
+ export interface Report {
2
+ accountId: string;
3
+ params: ReportParams;
4
+ status: string;
5
+ file?: string;
6
+ }
7
+ export interface ReportParams {
8
+ transactionDate?: ParamsDate;
9
+ createdDate?: ParamsDate;
10
+ sentDate?: ParamsDate;
11
+ deliveryReportDate?: ParamsDate;
12
+ area?: string;
13
+ customerId?: string;
14
+ senderId?: string;
15
+ creatorId?: string;
16
+ senderName?: string;
17
+ vendor?: string;
18
+ operator?: string;
19
+ productName?: string;
20
+ category?: string;
21
+ status?: string;
22
+ type?: string;
23
+ }
24
+ export declare class ParamsDate {
25
+ dateSince: Date;
26
+ dateUntil: Date;
27
+ }
28
+ export declare enum ReportStatus {
29
+ Created = "created",
30
+ Completed = "completed",
31
+ Empty = "empty",
32
+ Failed = "failed"
33
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReportStatus = exports.ParamsDate = void 0;
4
+ class ParamsDate {
5
+ dateSince;
6
+ dateUntil;
7
+ }
8
+ exports.ParamsDate = ParamsDate;
9
+ var ReportStatus;
10
+ (function (ReportStatus) {
11
+ ReportStatus["Created"] = "created";
12
+ ReportStatus["Completed"] = "completed";
13
+ ReportStatus["Empty"] = "empty";
14
+ ReportStatus["Failed"] = "failed";
15
+ })(ReportStatus = exports.ReportStatus || (exports.ReportStatus = {}));
@@ -0,0 +1,33 @@
1
+ export declare enum TransactionMessagingStatus {
2
+ Created = "created",
3
+ Paid = "paid",
4
+ Published = "published",
5
+ Succeeded = "succeeded",
6
+ Failed = "failed"
7
+ }
8
+ export interface TransactionMessaging {
9
+ _id?: string;
10
+ accountId: any;
11
+ account?: any;
12
+ campaignId: any;
13
+ campaign?: any;
14
+ sku: string;
15
+ amount: number;
16
+ msisdn: any;
17
+ status: TransactionMessagingStatus;
18
+ schedule: boolean;
19
+ scheduleAt?: Date;
20
+ scheduleZone?: string;
21
+ notes?: any;
22
+ productId?: string;
23
+ product?: any;
24
+ content?: any;
25
+ payment?: any;
26
+ senderId?: string;
27
+ sender?: any;
28
+ sourceId?: string;
29
+ sourceStatus?: string;
30
+ sourceReason?: string;
31
+ sentAt?: Date;
32
+ }
33
+ export default TransactionMessaging;