@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.
- package/core/domain/Command.d.ts +3 -0
- package/core/domain/Command.js +2 -0
- package/core/domain/Entity.d.ts +6 -0
- package/core/domain/Entity.js +13 -0
- package/core/domain/Identifier.d.ts +5 -0
- package/core/domain/Identifier.js +13 -0
- package/core/domain/UniqueId.d.ts +4 -0
- package/core/domain/UniqueId.js +11 -0
- package/core/domain/UseCase.d.ts +3 -0
- package/core/domain/UseCase.js +2 -0
- package/core/domain/ValueObject.d.ts +4 -0
- package/core/domain/ValueObject.js +10 -0
- package/core/domain/auth/Auth.d.ts +17 -0
- package/core/domain/auth/Auth.js +41 -0
- package/core/domain/auth/Authenticable.d.ts +4 -0
- package/core/domain/auth/Authenticable.js +2 -0
- package/core/domain/auth/Guard.d.ts +20 -0
- package/core/domain/auth/Guard.js +2 -0
- package/core/domain/auth/TokenGuard.d.ts +33 -0
- package/core/domain/auth/TokenGuard.js +94 -0
- package/core/domain/auth/UserProvider.d.ts +17 -0
- package/core/domain/auth/UserProvider.js +2 -0
- package/core/domain/cache/Cache.d.ts +8 -0
- package/core/domain/cache/Cache.js +2 -0
- package/core/domain/cache/Repo.d.ts +51 -0
- package/core/domain/cache/Repo.js +2 -0
- package/core/domain/cache/Store.d.ts +26 -0
- package/core/domain/cache/Store.js +2 -0
- package/core/domain/events/Event.d.ts +8 -0
- package/core/domain/events/Event.js +2 -0
- package/core/domain/events/Listener.d.ts +4 -0
- package/core/domain/events/Listener.js +2 -0
- package/core/domain/events/Worker.d.ts +3 -0
- package/core/domain/events/Worker.js +2 -0
- package/core/domain/loaders/Loader.d.ts +4 -0
- package/core/domain/loaders/Loader.js +2 -0
- package/core/domain/loaders/Manager.d.ts +3 -0
- package/core/domain/loaders/Manager.js +2 -0
- package/core/errors/AppError.d.ts +10 -0
- package/core/errors/AppError.js +16 -0
- package/core/errors/AuthenticationTokenMissingError.d.ts +5 -0
- package/core/errors/AuthenticationTokenMissingError.js +11 -0
- package/core/errors/BadRequestError.d.ts +5 -0
- package/core/errors/BadRequestError.js +11 -0
- package/core/errors/NotAuthorizedError.d.ts +5 -0
- package/core/errors/NotAuthorizedError.js +11 -0
- package/core/errors/NotFoundError.d.ts +5 -0
- package/core/errors/NotFoundError.js +11 -0
- package/core/errors/RequestValidationError.d.ts +10 -0
- package/core/errors/RequestValidationError.js +47 -0
- package/core/errors/ValidationError.d.ts +8 -0
- package/core/errors/ValidationError.js +19 -0
- package/core/errors/WrongAuthenticationTokenError.d.ts +5 -0
- package/core/errors/WrongAuthenticationTokenError.js +11 -0
- package/core/errors/WrongCredentialsError.d.ts +5 -0
- package/core/errors/WrongCredentialsError.js +11 -0
- package/core/index.d.ts +48 -0
- package/core/index.js +69 -0
- package/core/infrastructure/Container.d.ts +1 -0
- package/core/infrastructure/Container.js +8 -0
- package/core/infrastructure/Controller.d.ts +9 -0
- package/core/infrastructure/Controller.js +30 -0
- package/core/infrastructure/DatabaseRepository.d.ts +35 -0
- package/core/infrastructure/DatabaseRepository.js +2 -0
- package/core/infrastructure/Mapper.d.ts +2 -0
- package/core/infrastructure/Mapper.js +6 -0
- package/core/infrastructure/Repo.d.ts +2 -0
- package/core/infrastructure/Repo.js +6 -0
- package/core/infrastructure/cache/Cache.d.ts +47 -0
- package/core/infrastructure/cache/Cache.js +101 -0
- package/core/infrastructure/cache/InMemoryCache.d.ts +20 -0
- package/core/infrastructure/cache/InMemoryCache.js +62 -0
- package/core/infrastructure/cache/RedisCache.d.ts +15 -0
- package/core/infrastructure/cache/RedisCache.js +51 -0
- package/core/infrastructure/cache/Repo.d.ts +25 -0
- package/core/infrastructure/cache/Repo.js +103 -0
- package/core/infrastructure/cache/stores/ArrayStore.d.ts +17 -0
- package/core/infrastructure/cache/stores/ArrayStore.js +65 -0
- package/core/infrastructure/cache/stores/FileStore.d.ts +14 -0
- package/core/infrastructure/cache/stores/FileStore.js +171 -0
- package/core/infrastructure/cache/stores/NullStore.d.ts +9 -0
- package/core/infrastructure/cache/stores/NullStore.js +24 -0
- package/core/infrastructure/cache/stores/RedisStore.d.ts +13 -0
- package/core/infrastructure/cache/stores/RedisStore.js +44 -0
- package/core/infrastructure/events/ChannelEvent.d.ts +9 -0
- package/core/infrastructure/events/ChannelEvent.js +37 -0
- package/core/infrastructure/events/Connection.d.ts +8 -0
- package/core/infrastructure/events/Connection.js +30 -0
- package/core/infrastructure/events/Event.d.ts +16 -0
- package/core/infrastructure/events/Event.js +42 -0
- package/core/infrastructure/events/Listener.d.ts +23 -0
- package/core/infrastructure/events/Listener.js +77 -0
- package/core/infrastructure/events/Worker.d.ts +9 -0
- package/core/infrastructure/events/Worker.js +34 -0
- package/core/infrastructure/events/grpc/Connection.d.ts +9 -0
- package/core/infrastructure/events/grpc/Connection.js +34 -0
- package/core/infrastructure/events/grpc/Event.d.ts +12 -0
- package/core/infrastructure/events/grpc/Event.js +80 -0
- package/core/infrastructure/events/grpc/Listener.d.ts +16 -0
- package/core/infrastructure/events/grpc/Listener.js +74 -0
- package/core/infrastructure/events/rpc/Event.d.ts +13 -0
- package/core/infrastructure/events/rpc/Event.js +98 -0
- package/core/infrastructure/events/rpc/Listener.d.ts +6 -0
- package/core/infrastructure/events/rpc/Listener.js +30 -0
- package/core/infrastructure/http/App.d.ts +15 -0
- package/core/infrastructure/http/App.js +73 -0
- package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/alwaysAcceptJsonMiddleware.js +8 -0
- package/core/infrastructure/http/middleware/errorMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/errorMiddleware.js +18 -0
- package/core/infrastructure/http/middleware/loggerMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/loggerMiddleware.js +17 -0
- package/core/infrastructure/http/middleware/routeNotFoundMiddleware.d.ts +2 -0
- package/core/infrastructure/http/middleware/routeNotFoundMiddleware.js +11 -0
- package/core/infrastructure/http/middleware/validationMiddleware.d.ts +4 -0
- package/core/infrastructure/http/middleware/validationMiddleware.js +35 -0
- package/core/infrastructure/loaders/Loader.d.ts +8 -0
- package/core/infrastructure/loaders/Loader.js +14 -0
- package/core/infrastructure/loaders/Manager.d.ts +7 -0
- package/core/infrastructure/loaders/Manager.js +24 -0
- package/core/modules/health/errors/ConnectionNotFoundError.d.ts +4 -0
- package/core/modules/health/errors/ConnectionNotFoundError.js +10 -0
- package/core/modules/health/errors/HealthCheckError.d.ts +3 -0
- package/core/modules/health/errors/HealthCheckError.js +10 -0
- package/core/modules/health/errors/TimeoutError.d.ts +4 -0
- package/core/modules/health/errors/TimeoutError.js +10 -0
- package/core/modules/health/useCases/health/HealthController.d.ts +20 -0
- package/core/modules/health/useCases/health/HealthController.js +75 -0
- package/core/modules/health/useCases/healthCheck/HealthCheck.d.ts +8 -0
- package/core/modules/health/useCases/healthCheck/HealthCheck.js +37 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.d.ts +8 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckExecutor.js +48 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckResult.d.ts +6 -0
- package/core/modules/health/useCases/healthCheck/HealthCheckResult.js +2 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicator.d.ts +7 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicator.js +14 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.d.ts +7 -0
- package/core/modules/health/useCases/healthIndicator/HealthIndicatorResult.js +2 -0
- package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.d.ts +21 -0
- package/core/modules/health/useCases/healthIndicator/database/mongooseHealthIndicator.js +69 -0
- package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.d.ts +27 -0
- package/core/modules/health/useCases/healthIndicator/database/sequelizeHealthIndicator.js +73 -0
- package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.d.ts +21 -0
- package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.js +66 -0
- package/core/modules/health/utils/promise.d.ts +1 -0
- package/core/modules/health/utils/promise.js +12 -0
- package/core/modules/service/useCases/detail/DetailController.d.ts +6 -0
- package/core/modules/service/useCases/detail/DetailController.js +25 -0
- package/core/utils/Crypto.d.ts +24 -0
- package/core/utils/Crypto.js +93 -0
- package/core/utils/Hash.d.ts +6 -0
- package/core/utils/Hash.js +23 -0
- package/core/utils/cache.d.ts +1 -0
- package/core/utils/cache.js +16 -0
- package/core/utils/commands.d.ts +2 -0
- package/core/utils/commands.js +7 -0
- package/core/utils/events.d.ts +3 -0
- package/core/utils/events.js +11 -0
- package/core/utils/logger.d.ts +2 -0
- package/core/utils/logger.js +15 -0
- package/core/utils/response.d.ts +4 -0
- package/core/utils/response.js +11 -0
- package/core/utils/validator.d.ts +4 -0
- package/core/utils/validator.js +48 -0
- package/domain/BalanceMutation.d.ts +18 -0
- package/domain/BalanceMutation.js +8 -0
- package/domain/ChannelWhatsapp.d.ts +18 -0
- package/domain/ChannelWhatsapp.js +2 -0
- package/domain/MessageTemplate.d.ts +26 -0
- package/domain/MessageTemplate.js +12 -0
- package/domain/MessageTemplateCategoryUpdate.d.ts +8 -0
- package/domain/MessageTemplateCategoryUpdate.js +2 -0
- package/domain/MessageTemplateStatusUpdate.d.ts +8 -0
- package/domain/MessageTemplateStatusUpdate.js +2 -0
- package/domain/Payment.d.ts +14 -0
- package/domain/Payment.js +8 -0
- package/domain/Report.d.ts +33 -0
- package/domain/Report.js +15 -0
- package/domain/TransactionMessaging.d.ts +33 -0
- package/domain/TransactionMessaging.js +11 -0
- package/domain/TransactionMessagingStatusUpdate.d.ts +6 -0
- package/domain/TransactionMessagingStatusUpdate.js +2 -0
- package/domain/User.d.ts +25 -0
- package/domain/User.js +19 -0
- package/domain/index.d.ts +10 -0
- package/domain/index.js +26 -0
- package/index.d.ts +3 -0
- package/index.js +19 -0
- package/package.json +57 -0
- package/readme.md +4 -0
- package/shared/index.d.ts +5 -0
- package/shared/index.js +21 -0
- package/shared/plugins/axios-logger-mongo.d.ts +5 -0
- package/shared/plugins/axios-logger-mongo.js +113 -0
- package/shared/plugins/axios.d.ts +1 -0
- package/shared/plugins/axios.js +31 -0
- package/shared/plugins/cursor.d.ts +29 -0
- package/shared/plugins/cursor.js +231 -0
- package/shared/plugins/mongoose.d.ts +31 -0
- package/shared/plugins/mongoose.js +125 -0
- package/shared/resources/JsonResource.d.ts +16 -0
- package/shared/resources/JsonResource.js +59 -0
package/core/modules/health/useCases/healthIndicator/message-broker/rabbitmqHealthIndicator.js
ADDED
|
@@ -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,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,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,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,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,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,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
|
+
}
|
package/domain/Report.js
ADDED
|
@@ -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;
|