exodus-framework 2.0.699 → 2.0.700
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/lib/app/app.js +84 -0
- package/lib/app/controller.js +95 -0
- package/lib/app/core.js +66 -0
- package/lib/app/index.js +60 -0
- package/lib/app/service.js +24 -0
- package/lib/app/settings.js +135 -0
- package/lib/app/singleton.js +29 -0
- package/lib/contracts/console.js +5 -0
- package/lib/contracts/entity.js +5 -0
- package/lib/contracts/http.js +50 -0
- package/lib/contracts/index.js +104 -0
- package/lib/contracts/messaging.js +18 -0
- package/lib/contracts/security.js +5 -0
- package/lib/contracts/service.js +5 -0
- package/lib/contracts/session.js +5 -0
- package/lib/contracts/settings.js +5 -0
- package/lib/contracts/singleton.js +5 -0
- package/lib/contracts/socket.js +11 -0
- package/lib/controllers/api/file.js +24 -0
- package/lib/controllers/api/index.js +13 -0
- package/lib/controllers/index.js +16 -0
- package/lib/controllers/messaging/database.js +53 -0
- package/lib/controllers/messaging/environment.js +70 -0
- package/lib/express.d.js +5 -0
- package/lib/index.js +92 -0
- package/lib/middlewares/access.js +63 -0
- package/lib/middlewares/authentication.js +21 -0
- package/lib/middlewares/file.js +41 -0
- package/lib/middlewares/index.js +27 -0
- package/lib/models/Application.js +61 -0
- package/lib/models/Connection.js +54 -0
- package/lib/models/EnvConnection.js +41 -0
- package/lib/models/index.js +46 -0
- package/lib/routes/index.js +16 -0
- package/lib/routes/messaging/index.js +26 -0
- package/lib/services/error.js +49 -0
- package/lib/services/express.js +140 -0
- package/lib/services/file.js +65 -0
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.d.ts.map +1 -1
- package/lib/services/index.js +88 -0
- package/lib/services/rabitmq.js +93 -0
- package/lib/services/redis.js +60 -0
- package/lib/services/security.js +224 -0
- package/lib/services/sequelize.js +242 -0
- package/lib/services/socket.js +56 -0
- package/lib/services/task.js +162 -0
- package/lib/utils/api.js +50 -0
- package/lib/utils/database.js +36 -0
- package/lib/utils/date.js +28 -0
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +60 -0
- package/lib/utils/logger.js +55 -0
- package/lib/utils/session.js +23 -0
- package/package.json +1 -1
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
var _messaging = require("./messaging");
|
7
|
+
Object.keys(_messaging).forEach(function (key) {
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
9
|
+
if (key in exports && exports[key] === _messaging[key]) return;
|
10
|
+
Object.defineProperty(exports, key, {
|
11
|
+
enumerable: true,
|
12
|
+
get: function () {
|
13
|
+
return _messaging[key];
|
14
|
+
}
|
15
|
+
});
|
16
|
+
});
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _database = _interopRequireDefault(require("../../controllers/messaging/database"));
|
8
|
+
var _environment = _interopRequireDefault(require("../../controllers/messaging/environment"));
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
10
|
+
//* Controllers
|
11
|
+
const databaseController = new _database.default();
|
12
|
+
const envController = new _environment.default();
|
13
|
+
|
14
|
+
//* Definitions
|
15
|
+
const NativeMessagingRoutes = {
|
16
|
+
/* Connections Library */
|
17
|
+
'exodus.database.created': databaseController.created,
|
18
|
+
'exodus.database.updated': databaseController.update,
|
19
|
+
'exodus.database.deleted': databaseController.delete,
|
20
|
+
/* Environment Sync Database Relations */
|
21
|
+
'exodus.environment.created': envController.created,
|
22
|
+
'exodus.environment.deleted': envController.deleted,
|
23
|
+
'exodus.environment.updated.token': envController.updatedToken,
|
24
|
+
'exodus.environment.updated.database': envController.updatedDatabase
|
25
|
+
};
|
26
|
+
var _default = exports.default = NativeMessagingRoutes;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.ApplicationHttpException = exports.ApplicationException = void 0;
|
7
|
+
var _logger = _interopRequireDefault(require("../utils/logger"));
|
8
|
+
var _http = require("../contracts/http");
|
9
|
+
var _core = _interopRequireDefault(require("../app/core"));
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
11
|
+
class ExodusErrorBase extends _core.default {
|
12
|
+
constructor() {
|
13
|
+
super();
|
14
|
+
}
|
15
|
+
}
|
16
|
+
class ApplicationHttpException extends ExodusErrorBase {
|
17
|
+
message;
|
18
|
+
statusCode;
|
19
|
+
level;
|
20
|
+
data;
|
21
|
+
constructor(message, statusCode = _http.EHttpResponseCode.iternalErro, level = 'error', data) {
|
22
|
+
super();
|
23
|
+
this.message = message;
|
24
|
+
this.statusCode = statusCode;
|
25
|
+
this.level = level;
|
26
|
+
this.data = data;
|
27
|
+
this.handle();
|
28
|
+
}
|
29
|
+
handle() {
|
30
|
+
(0, _logger.default)().warn(this.message, this.statusCode);
|
31
|
+
(0, _logger.default)().warn(this.data);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
exports.ApplicationHttpException = ApplicationHttpException;
|
35
|
+
class ApplicationException extends ExodusErrorBase {
|
36
|
+
message;
|
37
|
+
error;
|
38
|
+
constructor(message, error) {
|
39
|
+
super();
|
40
|
+
this.message = message;
|
41
|
+
this.error = error;
|
42
|
+
this.handle();
|
43
|
+
}
|
44
|
+
handle() {
|
45
|
+
this.log(`${this.message}`, 'danger');
|
46
|
+
(0, _logger.default)().error(this.error);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
exports.ApplicationException = ApplicationException;
|
@@ -0,0 +1,140 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _service = _interopRequireDefault(require("../app/service"));
|
8
|
+
var _logger = _interopRequireDefault(require("../utils/logger"));
|
9
|
+
var _cors = _interopRequireDefault(require("cors"));
|
10
|
+
var _express = _interopRequireDefault(require("express"));
|
11
|
+
require("express-async-errors");
|
12
|
+
var http = _interopRequireWildcard(require("http"));
|
13
|
+
var _pinoHttp = _interopRequireDefault(require("pino-http"));
|
14
|
+
var _http2 = require("../contracts/http");
|
15
|
+
var _error = require("./error");
|
16
|
+
var _app = require("../app");
|
17
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
20
|
+
class ExpressService extends _service.default {
|
21
|
+
server;
|
22
|
+
mainRouter;
|
23
|
+
async init() {
|
24
|
+
if (!this.mainRouter) throw new _error.ApplicationException('Need router'); //!sem router
|
25
|
+
|
26
|
+
const expss = (0, _express.default)();
|
27
|
+
const pino = (0, _pinoHttp.default)({
|
28
|
+
logger: (0, _logger.default)()
|
29
|
+
});
|
30
|
+
this.server = http.createServer(expss);
|
31
|
+
expss.use('/public', _express.default.static(_app.Core.settings.getHttp().publicPath));
|
32
|
+
expss.use(pino);
|
33
|
+
expss.use(this.responseTypeMiddleware.bind(this));
|
34
|
+
expss.use(_express.default.json());
|
35
|
+
expss.use(_express.default.urlencoded({
|
36
|
+
extended: false
|
37
|
+
}));
|
38
|
+
expss.use((0, _cors.default)({
|
39
|
+
origin: '*'
|
40
|
+
}));
|
41
|
+
expss.use(this.mainRouter);
|
42
|
+
expss.use(this.handleAuthorizationFailure.bind(this));
|
43
|
+
expss.use(this.handleNotFoud.bind(this));
|
44
|
+
expss.use(this.handleRequestProcessFailure.bind(this));
|
45
|
+
this.server.listen(_app.Core.settings.getAppication().port, () => {
|
46
|
+
(0, _logger.default)().info(`servidor iniciado na porta: ${_app.Core.settings.getAppication().port}`);
|
47
|
+
this.log(`🌍 Http Server Listering On: ${_app.Core.settings.getAppication().port}`, 'success');
|
48
|
+
});
|
49
|
+
}
|
50
|
+
getHttpServer() {
|
51
|
+
return this.server;
|
52
|
+
}
|
53
|
+
sendResponse(objResponse, res, next) {
|
54
|
+
objResponse.timestamp = Date.now();
|
55
|
+
if (!objResponse.code) objResponse.code = _http2.EHttpResponseCode.successfullyProcessedInformation;
|
56
|
+
res.status(objResponse.code);
|
57
|
+
if (objResponse.location) {
|
58
|
+
res.location(objResponse.location);
|
59
|
+
delete objResponse.location;
|
60
|
+
}
|
61
|
+
let FormulatedResponse;
|
62
|
+
switch (_app.Core.settings.getHttp().formulation) {
|
63
|
+
case 'direct':
|
64
|
+
if (objResponse['data']) {
|
65
|
+
FormulatedResponse = objResponse.data;
|
66
|
+
} else {
|
67
|
+
FormulatedResponse = objResponse;
|
68
|
+
}
|
69
|
+
break;
|
70
|
+
case 'standart':
|
71
|
+
FormulatedResponse = objResponse;
|
72
|
+
break;
|
73
|
+
default:
|
74
|
+
FormulatedResponse = objResponse;
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
if (next) {
|
78
|
+
res.write(JSON.stringify(FormulatedResponse));
|
79
|
+
next();
|
80
|
+
} else {
|
81
|
+
res.send(JSON.stringify(FormulatedResponse));
|
82
|
+
}
|
83
|
+
}
|
84
|
+
responseTypeMiddleware(req, res, next) {
|
85
|
+
res.contentType('application/json');
|
86
|
+
next();
|
87
|
+
}
|
88
|
+
|
89
|
+
//* Handlers
|
90
|
+
handleNotFoud(req, res) {
|
91
|
+
this.sendResponse({
|
92
|
+
message: 'Endereço não encontrado',
|
93
|
+
type: 'warning',
|
94
|
+
status: false,
|
95
|
+
code: _http2.EHttpResponseCode.informationNotFound
|
96
|
+
}, res);
|
97
|
+
}
|
98
|
+
handleAuthorizationFailure(err, req, res, next) {
|
99
|
+
if (err.name === 'UnauthorizedError') {
|
100
|
+
throw new _error.ApplicationHttpException('Falha na autorização', _http2.EHttpResponseCode.informationUnauthorized);
|
101
|
+
} else {
|
102
|
+
next(err);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
handleRequestProcessFailure = async (err, req, res, _) => {
|
106
|
+
if (err instanceof _error.ApplicationHttpException) {
|
107
|
+
return this.sendResponse({
|
108
|
+
message: err.message,
|
109
|
+
type: err.level,
|
110
|
+
status: false,
|
111
|
+
code: err.statusCode,
|
112
|
+
data: err.data
|
113
|
+
}, res);
|
114
|
+
}
|
115
|
+
this.sendResponse({
|
116
|
+
message: 'Houve um erro ao acessar este recurso',
|
117
|
+
type: 'error',
|
118
|
+
status: false,
|
119
|
+
code: 500
|
120
|
+
}, res);
|
121
|
+
new _error.ApplicationException('Erro não tratado em uma rota.', err);
|
122
|
+
};
|
123
|
+
async checkRequest(params) {
|
124
|
+
let pass = true;
|
125
|
+
const need = [];
|
126
|
+
for (const [key, param] of Object.entries(params)) {
|
127
|
+
if (!param || param === null || param.length < 1 || typeof param === 'string' && param === '' || typeof param === 'object' && Object.values(param).length < 1) {
|
128
|
+
pass = false;
|
129
|
+
need.push(key);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
if (!pass) throw new _error.ApplicationHttpException('Requisição incompleta', _http2.EHttpResponseCode.incompleteRequest, 'error', {
|
133
|
+
need
|
134
|
+
});
|
135
|
+
}
|
136
|
+
registerRouter(router) {
|
137
|
+
this.mainRouter = router;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
var _default = exports.default = ExpressService;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _service = _interopRequireDefault(require("../app/service"));
|
8
|
+
var _logger = _interopRequireDefault(require("../utils/logger"));
|
9
|
+
var fs = _interopRequireWildcard(require("fs"));
|
10
|
+
var fsPromisses = _interopRequireWildcard(require("fs/promises"));
|
11
|
+
var _app = require("../app");
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
15
|
+
class FileService extends _service.default {
|
16
|
+
async init() {
|
17
|
+
await this.checkPaths();
|
18
|
+
await this.cleanTemp();
|
19
|
+
}
|
20
|
+
async checkPaths() {
|
21
|
+
for (const path of Object.values(_app.Core.settings.getAppication().filePaths)) {
|
22
|
+
!fs.existsSync(path) && fs.mkdirSync(path, {
|
23
|
+
recursive: true
|
24
|
+
});
|
25
|
+
}
|
26
|
+
}
|
27
|
+
async cleanTemp() {
|
28
|
+
this.listFiles('temporary', files => {
|
29
|
+
files.forEach(file => {
|
30
|
+
const p = _app.Core.settings.getAppication().filePaths.temporary + '/' + file;
|
31
|
+
fs.rmSync(p, {
|
32
|
+
recursive: true
|
33
|
+
});
|
34
|
+
});
|
35
|
+
});
|
36
|
+
}
|
37
|
+
async save(filename, destiny) {
|
38
|
+
const p = _app.Core.settings.getAppication().filePaths.temporary + '/' + filename;
|
39
|
+
const d = _app.Core.settings.getAppication().filePaths[destiny] + '/' + filename;
|
40
|
+
return await fsPromisses.rename(p, d).then(() => d).catch(e => {
|
41
|
+
(0, _logger.default)().error({
|
42
|
+
filename,
|
43
|
+
destiny,
|
44
|
+
erro: e
|
45
|
+
}, 'Não foi possível salvar o arquivo');
|
46
|
+
return false;
|
47
|
+
});
|
48
|
+
}
|
49
|
+
async delete(filename, destiny) {
|
50
|
+
const d = _app.Core.settings.getAppication().filePaths[destiny] + '/' + filename;
|
51
|
+
return await fsPromisses.unlink(d).then(() => true).catch(e => {
|
52
|
+
(0, _logger.default)().error({
|
53
|
+
filename,
|
54
|
+
destiny,
|
55
|
+
erro: e
|
56
|
+
}, 'Não foi possível deletar o arquivo');
|
57
|
+
return false;
|
58
|
+
});
|
59
|
+
}
|
60
|
+
listFiles(origin, cb) {
|
61
|
+
const p = _app.Core.settings.getAppication().filePaths[origin];
|
62
|
+
fs.readdir(p, (_, file) => cb(file));
|
63
|
+
}
|
64
|
+
}
|
65
|
+
var _default = exports.default = FileService;
|
package/lib/services/index.d.ts
CHANGED
@@ -5,5 +5,6 @@ export { default as RabbitMQService } from './rabitmq';
|
|
5
5
|
export { default as RedisService } from './redis';
|
6
6
|
export { default as SequelizeService } from './sequelize';
|
7
7
|
export { default as SocketIOService } from './socket';
|
8
|
+
export { default as SecurityService } from './security';
|
8
9
|
export * from './task';
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AACtD,cAAc,QAAQ,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,YAAY,CAAC;AACxD,cAAc,QAAQ,CAAC"}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
var _exportNames = {
|
7
|
+
ExpressService: true,
|
8
|
+
FileService: true,
|
9
|
+
RabbitMQService: true,
|
10
|
+
RedisService: true,
|
11
|
+
SequelizeService: true,
|
12
|
+
SocketIOService: true,
|
13
|
+
SecurityService: true
|
14
|
+
};
|
15
|
+
Object.defineProperty(exports, "ExpressService", {
|
16
|
+
enumerable: true,
|
17
|
+
get: function () {
|
18
|
+
return _express.default;
|
19
|
+
}
|
20
|
+
});
|
21
|
+
Object.defineProperty(exports, "FileService", {
|
22
|
+
enumerable: true,
|
23
|
+
get: function () {
|
24
|
+
return _file.default;
|
25
|
+
}
|
26
|
+
});
|
27
|
+
Object.defineProperty(exports, "RabbitMQService", {
|
28
|
+
enumerable: true,
|
29
|
+
get: function () {
|
30
|
+
return _rabitmq.default;
|
31
|
+
}
|
32
|
+
});
|
33
|
+
Object.defineProperty(exports, "RedisService", {
|
34
|
+
enumerable: true,
|
35
|
+
get: function () {
|
36
|
+
return _redis.default;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
Object.defineProperty(exports, "SecurityService", {
|
40
|
+
enumerable: true,
|
41
|
+
get: function () {
|
42
|
+
return _security.default;
|
43
|
+
}
|
44
|
+
});
|
45
|
+
Object.defineProperty(exports, "SequelizeService", {
|
46
|
+
enumerable: true,
|
47
|
+
get: function () {
|
48
|
+
return _sequelize.default;
|
49
|
+
}
|
50
|
+
});
|
51
|
+
Object.defineProperty(exports, "SocketIOService", {
|
52
|
+
enumerable: true,
|
53
|
+
get: function () {
|
54
|
+
return _socket.default;
|
55
|
+
}
|
56
|
+
});
|
57
|
+
var _error = require("./error");
|
58
|
+
Object.keys(_error).forEach(function (key) {
|
59
|
+
if (key === "default" || key === "__esModule") return;
|
60
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
61
|
+
if (key in exports && exports[key] === _error[key]) return;
|
62
|
+
Object.defineProperty(exports, key, {
|
63
|
+
enumerable: true,
|
64
|
+
get: function () {
|
65
|
+
return _error[key];
|
66
|
+
}
|
67
|
+
});
|
68
|
+
});
|
69
|
+
var _express = _interopRequireDefault(require("./express"));
|
70
|
+
var _file = _interopRequireDefault(require("./file"));
|
71
|
+
var _rabitmq = _interopRequireDefault(require("./rabitmq"));
|
72
|
+
var _redis = _interopRequireDefault(require("./redis"));
|
73
|
+
var _sequelize = _interopRequireDefault(require("./sequelize"));
|
74
|
+
var _socket = _interopRequireDefault(require("./socket"));
|
75
|
+
var _security = _interopRequireDefault(require("./security"));
|
76
|
+
var _task = require("./task");
|
77
|
+
Object.keys(_task).forEach(function (key) {
|
78
|
+
if (key === "default" || key === "__esModule") return;
|
79
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
80
|
+
if (key in exports && exports[key] === _task[key]) return;
|
81
|
+
Object.defineProperty(exports, key, {
|
82
|
+
enumerable: true,
|
83
|
+
get: function () {
|
84
|
+
return _task[key];
|
85
|
+
}
|
86
|
+
});
|
87
|
+
});
|
88
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
@@ -0,0 +1,93 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _service = _interopRequireDefault(require("../app/service"));
|
8
|
+
var _amqplib = _interopRequireDefault(require("amqplib"));
|
9
|
+
var _error = require("./error");
|
10
|
+
var _app = require("../app");
|
11
|
+
var _messaging = _interopRequireDefault(require("../routes/messaging"));
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
13
|
+
/**
|
14
|
+
* Serviço de Mensageria
|
15
|
+
*
|
16
|
+
* @class RabbitMQService
|
17
|
+
* @extends {Service}
|
18
|
+
* @implements {IService}
|
19
|
+
*/
|
20
|
+
class RabbitMQService extends _service.default {
|
21
|
+
connection;
|
22
|
+
channel;
|
23
|
+
connected;
|
24
|
+
mainRouter;
|
25
|
+
|
26
|
+
//# Initialization
|
27
|
+
constructor() {
|
28
|
+
super();
|
29
|
+
}
|
30
|
+
async init() {
|
31
|
+
if (!this.mainRouter) throw new _error.ApplicationException('Need router'); //!sem router
|
32
|
+
|
33
|
+
this.mainRouter = {
|
34
|
+
...this.mainRouter,
|
35
|
+
..._messaging.default
|
36
|
+
}; // # Register native router
|
37
|
+
await this.connect();
|
38
|
+
}
|
39
|
+
registerHandles() {
|
40
|
+
for (const [queue, handle] of Object.entries(this.mainRouter)) {
|
41
|
+
this.consumeFromQueue(queue, handle);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
async connect() {
|
45
|
+
if (this.connected && this.channel) return;else this.connected = true;
|
46
|
+
try {
|
47
|
+
this.log(`⌛️ Connecting to Rabbit-MQ Server`);
|
48
|
+
this.connection = await _amqplib.default.connect(`amqp://${_app.Core.settings.getMessaging().user}:${_app.Core.settings.getMessaging().pass}@${_app.Core.settings.getMessaging().host}:5672`);
|
49
|
+
this.log(`✅ Rabbit MQ Connection is ready`);
|
50
|
+
this.channel = await this.connection.createChannel();
|
51
|
+
this.log(`🛸 Created RabbitMQ Channel successfully`);
|
52
|
+
this.registerHandles();
|
53
|
+
} catch (error) {
|
54
|
+
new _error.ApplicationException(`Not connected to MQ Server`, error);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
//# Common
|
59
|
+
async sendToQueue(queue, data) {
|
60
|
+
try {
|
61
|
+
if (!this.channel) {
|
62
|
+
await this.connect();
|
63
|
+
}
|
64
|
+
this.channel.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
|
65
|
+
} catch (error) {
|
66
|
+
new _error.ApplicationException('Houve um erro no envio de uma mensagem para o rabitmq', error);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
async consumeFromQueue(queue, callBack) {
|
70
|
+
await this.channel.assertQueue(queue, {
|
71
|
+
durable: true
|
72
|
+
});
|
73
|
+
this.channel.consume(queue, msg => {
|
74
|
+
{
|
75
|
+
if (!msg) {
|
76
|
+
return this.log(`Invalid incoming message in`);
|
77
|
+
}
|
78
|
+
try {
|
79
|
+
callBack(JSON.parse(msg.content.toString()), () => this.channel.ack(msg));
|
80
|
+
} catch (error) {
|
81
|
+
this.channel.ack(msg);
|
82
|
+
new _error.ApplicationException('Error on parsing message from queue', error);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}, {
|
86
|
+
noAck: false
|
87
|
+
});
|
88
|
+
}
|
89
|
+
registerRouter(router) {
|
90
|
+
this.mainRouter = router;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
var _default = exports.default = RabbitMQService;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _service = _interopRequireDefault(require("../app/service"));
|
8
|
+
var _redis = require("redis");
|
9
|
+
var _error = require("./error");
|
10
|
+
var _app = require("../app");
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
12
|
+
/**
|
13
|
+
* Serviço de cache
|
14
|
+
*
|
15
|
+
* @class RedisService
|
16
|
+
* @extends {Service}
|
17
|
+
* @implements {IService}
|
18
|
+
*/
|
19
|
+
class RedisService extends _service.default {
|
20
|
+
client;
|
21
|
+
|
22
|
+
//* Initialization
|
23
|
+
async init() {
|
24
|
+
this.client = (0, _redis.createClient)({
|
25
|
+
url: `redis://${_app.Core.settings.getCache().host}:${_app.Core.settings.getCache().port}`,
|
26
|
+
password: _app.Core.settings.getCache().password
|
27
|
+
});
|
28
|
+
await this.connect();
|
29
|
+
}
|
30
|
+
connect() {
|
31
|
+
this.client.on('error', this.onClientError.bind(this));
|
32
|
+
return new Promise(resolve => {
|
33
|
+
this.client.connect().then(() => {
|
34
|
+
this.log('Redis client connected.', 'success');
|
35
|
+
resolve(true);
|
36
|
+
});
|
37
|
+
});
|
38
|
+
}
|
39
|
+
async disconnect() {
|
40
|
+
await this.client.quit();
|
41
|
+
}
|
42
|
+
|
43
|
+
//* Common
|
44
|
+
async setValue(key, value) {
|
45
|
+
await this.client.set(key, value);
|
46
|
+
}
|
47
|
+
async getValue(key) {
|
48
|
+
const value = await this.client.get(key);
|
49
|
+
return value;
|
50
|
+
}
|
51
|
+
async deleteValue(key) {
|
52
|
+
await this.client.del(key);
|
53
|
+
}
|
54
|
+
|
55
|
+
//* Events
|
56
|
+
onClientError(err) {
|
57
|
+
new _error.ApplicationException('Error on init redis client', err);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
var _default = exports.default = RedisService;
|