exodus-framework 2.0.696 → 2.0.699
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/settings.d.ts.map +1 -1
- package/lib/contracts/messaging.d.ts +28 -1
- package/lib/contracts/messaging.d.ts.map +1 -1
- package/lib/contracts/security.d.ts +11 -0
- package/lib/contracts/security.d.ts.map +1 -0
- package/lib/contracts/settings.d.ts +6 -0
- package/lib/contracts/settings.d.ts.map +1 -1
- package/lib/controllers/messaging/database.d.ts +9 -0
- package/lib/controllers/messaging/database.d.ts.map +1 -0
- package/lib/controllers/messaging/environment.d.ts +10 -0
- package/lib/controllers/messaging/environment.d.ts.map +1 -0
- package/lib/middlewares/access.d.ts.map +1 -1
- package/lib/middlewares/authentication.d.ts +1 -1
- package/lib/middlewares/authentication.d.ts.map +1 -1
- package/lib/models/Application.d.ts +13 -0
- package/lib/models/Application.d.ts.map +1 -0
- package/lib/models/Connection.d.ts +1 -0
- package/lib/models/Connection.d.ts.map +1 -1
- package/lib/models/EnvConnection.d.ts +9 -0
- package/lib/models/EnvConnection.d.ts.map +1 -0
- package/lib/models/index.d.ts +4 -0
- package/lib/models/index.d.ts.map +1 -1
- package/lib/routes/index.d.ts +2 -0
- package/lib/routes/index.d.ts.map +1 -0
- package/lib/routes/messaging/index.d.ts +4 -0
- package/lib/routes/messaging/index.d.ts.map +1 -0
- package/lib/services/rabitmq.d.ts.map +1 -1
- package/lib/services/security.d.ts +29 -0
- package/lib/services/security.d.ts.map +1 -0
- package/lib/services/sequelize.d.ts.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/package.json +3 -1
- package/lib/app/app.js +0 -84
- package/lib/app/controller.js +0 -95
- package/lib/app/core.js +0 -66
- package/lib/app/index.js +0 -60
- package/lib/app/service.js +0 -24
- package/lib/app/settings.js +0 -130
- package/lib/app/singleton.js +0 -29
- package/lib/contracts/console.js +0 -5
- package/lib/contracts/entity.js +0 -5
- package/lib/contracts/http.js +0 -50
- package/lib/contracts/index.js +0 -104
- package/lib/contracts/messaging.js +0 -14
- package/lib/contracts/service.js +0 -5
- package/lib/contracts/session.js +0 -5
- package/lib/contracts/settings.js +0 -5
- package/lib/contracts/singleton.js +0 -5
- package/lib/contracts/socket.js +0 -11
- package/lib/contracts/tenant.d.ts +0 -1
- package/lib/contracts/tenant.d.ts.map +0 -1
- package/lib/contracts/tenant.js +0 -1
- package/lib/controllers/api/file.js +0 -24
- package/lib/controllers/api/index.js +0 -13
- package/lib/controllers/index.js +0 -16
- package/lib/express.d.js +0 -5
- package/lib/index.js +0 -92
- package/lib/middlewares/access.js +0 -35
- package/lib/middlewares/authentication.js +0 -27
- package/lib/middlewares/file.js +0 -41
- package/lib/middlewares/index.js +0 -27
- package/lib/models/Connection.js +0 -50
- package/lib/models/index.js +0 -16
- package/lib/services/error.js +0 -49
- package/lib/services/express.js +0 -140
- package/lib/services/file.js +0 -65
- package/lib/services/index.js +0 -80
- package/lib/services/rabitmq.js +0 -87
- package/lib/services/redis.js +0 -60
- package/lib/services/sequelize.js +0 -238
- package/lib/services/socket.js +0 -56
- package/lib/services/task.js +0 -162
- package/lib/utils/api.js +0 -50
- package/lib/utils/database.js +0 -36
- package/lib/utils/date.js +0 -28
- package/lib/utils/index.js +0 -60
- package/lib/utils/logger.js +0 -55
- package/lib/utils/session.js +0 -23
@@ -1,238 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
var _sequelize = require("sequelize");
|
8
|
-
var _app = require("../app");
|
9
|
-
var _service = _interopRequireDefault(require("../app/service"));
|
10
|
-
var _Connection = require("../models/Connection");
|
11
|
-
var _database = require("../utils/database");
|
12
|
-
var _logger = _interopRequireDefault(require("../utils/logger"));
|
13
|
-
var _error = require("./error");
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
15
|
-
/**
|
16
|
-
* Serviço de gerênciamento do banco de dados
|
17
|
-
*
|
18
|
-
* @class SequelizeService
|
19
|
-
* @extends {Service}
|
20
|
-
* @implements {IService}
|
21
|
-
*/
|
22
|
-
class SequelizeService extends _service.default {
|
23
|
-
serviceDB;
|
24
|
-
masterDB;
|
25
|
-
models;
|
26
|
-
connections;
|
27
|
-
initializedModels;
|
28
|
-
|
29
|
-
//# Initialization
|
30
|
-
constructor() {
|
31
|
-
super();
|
32
|
-
}
|
33
|
-
async init() {
|
34
|
-
this.serviceDB = _database.serviceDB;
|
35
|
-
this.masterDB = _database.masterDB;
|
36
|
-
this.connections = new Map();
|
37
|
-
this.initializedModels = new Map();
|
38
|
-
await this.connectMainDatabase();
|
39
|
-
}
|
40
|
-
async connectMainDatabase() {
|
41
|
-
if (!this.models) throw new _error.ApplicationException('Models are requireds! Call registerModels(modelsArray)');
|
42
|
-
return new Promise(resolve => {
|
43
|
-
this.masterDB.sync({
|
44
|
-
force: false
|
45
|
-
}).then(() => {
|
46
|
-
this.log('✅ Connected master database sucessfully', 'success');
|
47
|
-
this.serviceDB.sync({
|
48
|
-
force: false
|
49
|
-
}).then(() => {
|
50
|
-
this.log('✅ Connected service database sucessfully', 'success');
|
51
|
-
resolve(true);
|
52
|
-
}).catch(reason => {
|
53
|
-
new _error.ApplicationException('Não foi possível inicializar a conexão com o ServiceDB', reason);
|
54
|
-
});
|
55
|
-
}).catch(reason => {
|
56
|
-
new _error.ApplicationException('Não foi possível inicializar a conexão com MasterDB', reason);
|
57
|
-
});
|
58
|
-
});
|
59
|
-
}
|
60
|
-
|
61
|
-
//# Common
|
62
|
-
reconnect(db, attempts = 2) {
|
63
|
-
db.sync().then(() => {
|
64
|
-
this.log('Database pronto', 'success');
|
65
|
-
}).catch(reason => {
|
66
|
-
this.log('Attemping to connect master database', 'warning');
|
67
|
-
(0, _logger.default)().warn('Erro ao inicializar o banco de dados, tentando novamente...', reason);
|
68
|
-
if (attempts > 0) {
|
69
|
-
setTimeout(() => this.reconnect(db, attempts - 1), 5000);
|
70
|
-
} else {
|
71
|
-
new _error.ApplicationException('Error on connecting master database', reason);
|
72
|
-
}
|
73
|
-
});
|
74
|
-
}
|
75
|
-
getMasterConnection() {
|
76
|
-
return this.masterDB;
|
77
|
-
}
|
78
|
-
async createDB(connection_uuid, name) {
|
79
|
-
const connData = await _Connection.Connection.findByPk(connection_uuid);
|
80
|
-
if (!connData) {
|
81
|
-
this.log('Connection data not found: ' + connection_uuid);
|
82
|
-
return false;
|
83
|
-
}
|
84
|
-
const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${name}`;
|
85
|
-
const sequelize = new _sequelize.Sequelize({
|
86
|
-
dialect: connData.dialect,
|
87
|
-
username: connData.username,
|
88
|
-
password: connData.password,
|
89
|
-
define: {
|
90
|
-
timestamps: true
|
91
|
-
},
|
92
|
-
timezone: '-03:00',
|
93
|
-
logging(sql, timing) {
|
94
|
-
(0, _logger.default)().trace('DATABASE', sql, timing);
|
95
|
-
}
|
96
|
-
});
|
97
|
-
return new Promise((resolve, reject) => {
|
98
|
-
sequelize.authenticate().then(async () => {
|
99
|
-
const [results] = await sequelize.query(`SHOW DATABASES LIKE '${dbQueryName}';`);
|
100
|
-
if (results.length === 0) {
|
101
|
-
// Se o banco de dados não existir, cria-o
|
102
|
-
await sequelize.query(`CREATE DATABASE ${dbQueryName};`);
|
103
|
-
this.log(`Database "${dbQueryName}" has been created.`);
|
104
|
-
resolve(true);
|
105
|
-
} else {
|
106
|
-
this.log(`Database "${dbQueryName}" already exists.`);
|
107
|
-
resolve(false);
|
108
|
-
}
|
109
|
-
}).catch(reason => {
|
110
|
-
new _error.ApplicationException('Error while checking/creating database:', reason);
|
111
|
-
reject(reason);
|
112
|
-
}).finally(() => {
|
113
|
-
sequelize.close();
|
114
|
-
});
|
115
|
-
});
|
116
|
-
}
|
117
|
-
async deleteDB(connection_uuid, name) {
|
118
|
-
const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${name}`;
|
119
|
-
const connData = await _Connection.Connection.findByPk(connection_uuid);
|
120
|
-
if (!connData) {
|
121
|
-
this.log('Connection data not found: ' + connection_uuid);
|
122
|
-
return false;
|
123
|
-
}
|
124
|
-
const sequelize = new _sequelize.Sequelize({
|
125
|
-
dialect: connData.dialect,
|
126
|
-
username: connData.username,
|
127
|
-
password: connData.password,
|
128
|
-
define: {
|
129
|
-
timestamps: true
|
130
|
-
},
|
131
|
-
timezone: '-03:00',
|
132
|
-
logging(sql, timing) {
|
133
|
-
(0, _logger.default)().trace('DATABASE', sql, timing);
|
134
|
-
}
|
135
|
-
});
|
136
|
-
return new Promise((resolve, reject) => {
|
137
|
-
sequelize.authenticate().then(async () => {
|
138
|
-
// Se o banco de dados não existir, cria-o
|
139
|
-
await sequelize.query(`DROP DATABASE IF EXISTS ${dbQueryName};`);
|
140
|
-
this.log(`Database "${dbQueryName}" has been deleted.`);
|
141
|
-
resolve(true);
|
142
|
-
}).catch(reason => {
|
143
|
-
new _error.ApplicationException('Error while checking/deleting database:', reason);
|
144
|
-
reject(reason);
|
145
|
-
}).finally(() => {
|
146
|
-
sequelize.close();
|
147
|
-
});
|
148
|
-
});
|
149
|
-
}
|
150
|
-
async getDB(tenantId) {
|
151
|
-
const {
|
152
|
-
con_uuid,
|
153
|
-
envToken
|
154
|
-
} = this.parseDataInfoByTenantId(tenantId);
|
155
|
-
if (con_uuid == _app.Core.settings.getDatabase().service.database) {
|
156
|
-
return _database.serviceDB;
|
157
|
-
} else if (con_uuid == _app.Core.settings.getDatabase().master.database) {
|
158
|
-
return _database.masterDB;
|
159
|
-
}
|
160
|
-
const dbName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`; //nomeclatura padrão do banco de dados do serviço
|
161
|
-
const queryId = `${con_uuid}@${dbName}`;
|
162
|
-
return this.connections.get(queryId) || (await this.initDB(tenantId));
|
163
|
-
}
|
164
|
-
async initDB(tenantId) {
|
165
|
-
const {
|
166
|
-
con_uuid,
|
167
|
-
envToken
|
168
|
-
} = this.parseDataInfoByTenantId(tenantId);
|
169
|
-
const dbName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`; //nomeclatura padrão do banco de dados do serviço
|
170
|
-
const queryId = `${con_uuid}@${dbName}`;
|
171
|
-
if (this.connections.get(queryId)) {
|
172
|
-
return this.connections.get(queryId);
|
173
|
-
}
|
174
|
-
const connData = await _Connection.Connection.findByPk(con_uuid);
|
175
|
-
if (!connData) {
|
176
|
-
this.log('Error on init connection, data not found! uuid: ' + con_uuid, 'danger');
|
177
|
-
return false;
|
178
|
-
}
|
179
|
-
const conn = new _sequelize.Sequelize({
|
180
|
-
database: dbName,
|
181
|
-
dialect: connData.dialect,
|
182
|
-
username: connData.username,
|
183
|
-
password: connData.password,
|
184
|
-
define: {
|
185
|
-
timestamps: true
|
186
|
-
},
|
187
|
-
timezone: '-03:00',
|
188
|
-
logging(sql, timing) {
|
189
|
-
(0, _logger.default)().trace('DATABASE', sql, timing);
|
190
|
-
}
|
191
|
-
});
|
192
|
-
return new Promise((resolve, reject) => {
|
193
|
-
conn.sync({
|
194
|
-
force: false
|
195
|
-
}).then(() => {
|
196
|
-
this.log(`✅ Connected ${dbName} database sucessfully`, 'success');
|
197
|
-
this.connections.set(queryId, conn);
|
198
|
-
resolve(conn);
|
199
|
-
}).catch(reason => {
|
200
|
-
this.log(`error trying to connect: ${dbName}, UUID: ${con_uuid}`);
|
201
|
-
reject(reason);
|
202
|
-
new _error.ApplicationException(`error trying to connect: ${dbName}, UUID: ${con_uuid}`, reason);
|
203
|
-
});
|
204
|
-
});
|
205
|
-
}
|
206
|
-
registerModels(models) {
|
207
|
-
this.models = models;
|
208
|
-
}
|
209
|
-
async getModel(model, tenantId) {
|
210
|
-
const {
|
211
|
-
con_uuid,
|
212
|
-
envToken
|
213
|
-
} = this.parseDataInfoByTenantId(tenantId);
|
214
|
-
const modelInitID = `${envToken}@${con_uuid}#${model.name}`;
|
215
|
-
const cache = this.initializedModels.get(modelInitID);
|
216
|
-
if (cache) {
|
217
|
-
return cache;
|
218
|
-
}
|
219
|
-
const connection = await this.getDB(tenantId);
|
220
|
-
if (!connection) {
|
221
|
-
throw new _error.ApplicationException('Não foi possível obter o model espeficificado: Conexão não encontrada');
|
222
|
-
}
|
223
|
-
const m = model.initialize(connection);
|
224
|
-
await m.sync();
|
225
|
-
this.initializedModels.set(modelInitID, m);
|
226
|
-
return m;
|
227
|
-
}
|
228
|
-
parseDataInfoByTenantId(tenant) {
|
229
|
-
const e = tenant.split('@');
|
230
|
-
const envToken = e[0];
|
231
|
-
const con_uuid = e[1];
|
232
|
-
return {
|
233
|
-
envToken,
|
234
|
-
con_uuid
|
235
|
-
};
|
236
|
-
}
|
237
|
-
}
|
238
|
-
var _default = exports.default = SequelizeService;
|
package/lib/services/socket.js
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
var _controller = require("../app/controller");
|
8
|
-
var _service = _interopRequireDefault(require("../app/service"));
|
9
|
-
var _socket = require("socket.io");
|
10
|
-
var _express = _interopRequireDefault(require("./express"));
|
11
|
-
var _error = require("./error");
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
13
|
-
/**
|
14
|
-
* Serviço de gerênciamento de comunicação WS/WSS Socket
|
15
|
-
*
|
16
|
-
* @class SocketIOService
|
17
|
-
* @extends {Service}
|
18
|
-
* @implements {IService}
|
19
|
-
*/
|
20
|
-
class SocketIOService extends _service.default {
|
21
|
-
server;
|
22
|
-
mainRouter;
|
23
|
-
constructor() {
|
24
|
-
super();
|
25
|
-
}
|
26
|
-
async init() {
|
27
|
-
if (!this.mainRouter) throw new _error.ApplicationException('Need router'); //!sem router
|
28
|
-
const server = _express.default.singleton().getHttpServer();
|
29
|
-
this.createSocket(server);
|
30
|
-
this.server.on('connection', this.onConnection.bind(this));
|
31
|
-
this.log('Socket server created');
|
32
|
-
}
|
33
|
-
onConnection(socket) {
|
34
|
-
this.log(`${socket.id} conectado`);
|
35
|
-
socket.on('disconnect', () => this.log(`${socket.id} desconectado`));
|
36
|
-
this.bindEvents(socket);
|
37
|
-
}
|
38
|
-
bindEvents(socket) {
|
39
|
-
Object.entries(this.mainRouter).forEach(([key, handle]) => {
|
40
|
-
socket.on(key, (...args) => {
|
41
|
-
handle(new _controller.SocketRequest(socket, key), ...args);
|
42
|
-
});
|
43
|
-
});
|
44
|
-
}
|
45
|
-
createSocket(app, cors = {
|
46
|
-
origin: '*'
|
47
|
-
}) {
|
48
|
-
this.server = new _socket.Server(app, {
|
49
|
-
cors
|
50
|
-
});
|
51
|
-
}
|
52
|
-
registerRouter(router) {
|
53
|
-
this.mainRouter = router;
|
54
|
-
}
|
55
|
-
}
|
56
|
-
var _default = exports.default = SocketIOService;
|
package/lib/services/task.js
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.TaskSchedulingService = exports.TaskQueueService = exports.SchedulingTask = exports.QueueTask = void 0;
|
7
|
-
var _bullmq = require("bullmq");
|
8
|
-
var _fs = require("fs");
|
9
|
-
var _nodeSchedule = require("node-schedule");
|
10
|
-
var _service = _interopRequireDefault(require("../app/service"));
|
11
|
-
var _singleton = _interopRequireDefault(require("../app/singleton"));
|
12
|
-
var _error = require("./error");
|
13
|
-
var _app = require("../app");
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
15
|
-
//* Base
|
16
|
-
class TaskServiceBase extends _service.default {
|
17
|
-
jobsPath;
|
18
|
-
setTaskPath(path) {
|
19
|
-
this.jobsPath = path;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
//* Scheduler
|
24
|
-
class TaskSchedulingService extends TaskServiceBase {
|
25
|
-
jobs;
|
26
|
-
async init() {
|
27
|
-
if (!this.jobsPath) {
|
28
|
-
return this.log('Tasks file path not found!', 'danger');
|
29
|
-
}
|
30
|
-
this.jobs = [];
|
31
|
-
this.log('Initializing jobs...', 'info');
|
32
|
-
await this.importAllJobs();
|
33
|
-
await this.processAllJobs();
|
34
|
-
this.log('All jobs initializeds...', 'info');
|
35
|
-
}
|
36
|
-
async registerJob(job) {
|
37
|
-
this.jobs.push(job);
|
38
|
-
}
|
39
|
-
async importAllJobs() {
|
40
|
-
if (!(0, _fs.existsSync)(this.jobsPath)) (0, _fs.mkdirSync)(this.jobsPath, {
|
41
|
-
recursive: true
|
42
|
-
});
|
43
|
-
for (const handlerFile of (0, _fs.readdirSync)(this.jobsPath)) {
|
44
|
-
try {
|
45
|
-
const job = require(`${this.jobsPath}/${handlerFile}`).default;
|
46
|
-
const jobInstance = job.singleton();
|
47
|
-
this.jobs.push(jobInstance);
|
48
|
-
} catch (error) {
|
49
|
-
new _error.ApplicationException(`Falha ao iniciar um ou mais jobs: ${handlerFile}`, error);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
async processAllJobs() {
|
54
|
-
for (const job of this.jobs) {
|
55
|
-
if (!job.getActive()) continue;
|
56
|
-
(0, _nodeSchedule.scheduleJob)(job.getJobTime(), job.handler.bind(job));
|
57
|
-
this.log(`Job '${job.getJobName()}' started...`, 'warning');
|
58
|
-
}
|
59
|
-
}
|
60
|
-
}
|
61
|
-
exports.TaskSchedulingService = TaskSchedulingService;
|
62
|
-
class SchedulingTask extends _singleton.default {
|
63
|
-
getJobTime() {
|
64
|
-
return this.cron;
|
65
|
-
}
|
66
|
-
getActive() {
|
67
|
-
return this.active;
|
68
|
-
}
|
69
|
-
getJobName() {
|
70
|
-
return this.name;
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
//* Queue
|
75
|
-
exports.SchedulingTask = SchedulingTask;
|
76
|
-
class TaskQueueService extends TaskServiceBase {
|
77
|
-
jobs;
|
78
|
-
connection;
|
79
|
-
async init() {
|
80
|
-
this.jobs = [];
|
81
|
-
this.connection = {
|
82
|
-
host: _app.Core.settings.getCache().host,
|
83
|
-
port: Number(_app.Core.settings.getCache().port),
|
84
|
-
password: _app.Core.settings.getCache().password
|
85
|
-
};
|
86
|
-
this.log('Initializing jobs...', 'info');
|
87
|
-
await this.importAllJobs();
|
88
|
-
await this.processAllJobs();
|
89
|
-
this.log('All jobs initializeds...', 'info');
|
90
|
-
}
|
91
|
-
async registerJob(job) {
|
92
|
-
this.jobs.push(job);
|
93
|
-
}
|
94
|
-
async importAllJobs() {
|
95
|
-
if (!(0, _fs.existsSync)(this.jobsPath)) (0, _fs.mkdirSync)(this.jobsPath, {
|
96
|
-
recursive: true
|
97
|
-
});
|
98
|
-
for (const handlerFile of (0, _fs.readdirSync)(this.jobsPath)) {
|
99
|
-
const job = require(`${this.jobsPath}/${handlerFile}`).default;
|
100
|
-
const jobInstance = job.singleton();
|
101
|
-
this.jobs.push(jobInstance);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
async processAllJobs() {
|
105
|
-
for (const job of this.jobs) {
|
106
|
-
if (!job.getActive()) continue;
|
107
|
-
const queue = new _bullmq.Queue(job.getQueueName(), {
|
108
|
-
connection: this.connection
|
109
|
-
});
|
110
|
-
const worker = new _bullmq.Worker(job.getQueueName(), job.handle.bind(job), {
|
111
|
-
connection: this.connection
|
112
|
-
});
|
113
|
-
job.setQueue(queue);
|
114
|
-
job.setWorker(worker);
|
115
|
-
job.init();
|
116
|
-
this.log(`Job '${job.getQueueName()}' started...`, 'warning');
|
117
|
-
}
|
118
|
-
}
|
119
|
-
}
|
120
|
-
exports.TaskQueueService = TaskQueueService;
|
121
|
-
class QueueTask extends _singleton.default {
|
122
|
-
queue;
|
123
|
-
worker;
|
124
|
-
initialize() {
|
125
|
-
this.queue = new _bullmq.Queue(this.getQueueName(), {
|
126
|
-
// Configurações do Redis
|
127
|
-
connection: {
|
128
|
-
host: 'localhost',
|
129
|
-
port: 6379
|
130
|
-
}
|
131
|
-
});
|
132
|
-
this.worker = new _bullmq.Worker(this.getQueueName(), this.handle.bind(this), {
|
133
|
-
connection: {
|
134
|
-
host: 'localhost',
|
135
|
-
port: 6379
|
136
|
-
}
|
137
|
-
});
|
138
|
-
}
|
139
|
-
async addJob(data) {
|
140
|
-
this.log('adicionando à fila...');
|
141
|
-
await this.queue.add(this.getQueueName(), data);
|
142
|
-
}
|
143
|
-
getQueue() {
|
144
|
-
return this.queue;
|
145
|
-
}
|
146
|
-
setQueue(queue) {
|
147
|
-
this.queue = queue;
|
148
|
-
}
|
149
|
-
getWorker() {
|
150
|
-
return this.worker;
|
151
|
-
}
|
152
|
-
setWorker(worker) {
|
153
|
-
this.worker = worker;
|
154
|
-
}
|
155
|
-
getActive() {
|
156
|
-
return this.active;
|
157
|
-
}
|
158
|
-
getQueueName() {
|
159
|
-
return this.queueName;
|
160
|
-
}
|
161
|
-
}
|
162
|
-
exports.QueueTask = QueueTask;
|
package/lib/utils/api.js
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
var _core = _interopRequireDefault(require("../app/core"));
|
8
|
-
var _error = require("../services/error");
|
9
|
-
var _axios = _interopRequireDefault(require("axios"));
|
10
|
-
var _dateFns = require("date-fns");
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
12
|
-
class Api extends _core.default {
|
13
|
-
axios;
|
14
|
-
constructor() {
|
15
|
-
super();
|
16
|
-
this.init();
|
17
|
-
}
|
18
|
-
async init() {
|
19
|
-
this.axios = _axios.default.create({
|
20
|
-
baseURL: this.host,
|
21
|
-
headers: {
|
22
|
-
...this.headers,
|
23
|
-
'Content-Type': 'application/json'
|
24
|
-
},
|
25
|
-
validateStatus: this.validateStatus
|
26
|
-
});
|
27
|
-
}
|
28
|
-
async request(endpoint, method, data, params, headers) {
|
29
|
-
try {
|
30
|
-
const res = await this.axios({
|
31
|
-
method,
|
32
|
-
url: this.host + endpoint,
|
33
|
-
data,
|
34
|
-
params,
|
35
|
-
headers: {
|
36
|
-
...headers,
|
37
|
-
...this.headers
|
38
|
-
}
|
39
|
-
});
|
40
|
-
return res.data;
|
41
|
-
} catch (error) {
|
42
|
-
new _error.ApplicationException('não foi possível realizar uma requisição', error);
|
43
|
-
}
|
44
|
-
}
|
45
|
-
getLogicalSecurityId() {
|
46
|
-
const date = (0, _dateFns.format)(new Date(), 'yyyy-MM-dd');
|
47
|
-
return String(Date.parse(date) - 5000);
|
48
|
-
}
|
49
|
-
}
|
50
|
-
var _default = exports.default = Api;
|
package/lib/utils/database.js
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.serviceDB = exports.masterDB = void 0;
|
7
|
-
var _sequelize = require("sequelize");
|
8
|
-
var _logger = _interopRequireDefault(require("./logger"));
|
9
|
-
var _app = require("../app");
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
11
|
-
const serviceDB = exports.serviceDB = new _sequelize.Sequelize({
|
12
|
-
database: _app.Core.settings.getDatabase().service.database,
|
13
|
-
dialect: _app.Core.settings.getDatabase().master.dialect,
|
14
|
-
username: _app.Core.settings.getDatabase().master.username,
|
15
|
-
password: _app.Core.settings.getDatabase().master.password,
|
16
|
-
define: {
|
17
|
-
timestamps: true
|
18
|
-
},
|
19
|
-
timezone: '-03:00',
|
20
|
-
logging(sql, timing) {
|
21
|
-
(0, _logger.default)().trace('DATABASE', sql, timing);
|
22
|
-
}
|
23
|
-
});
|
24
|
-
const masterDB = exports.masterDB = new _sequelize.Sequelize({
|
25
|
-
database: _app.Core.settings.getDatabase().master.database,
|
26
|
-
dialect: _app.Core.settings.getDatabase().master.dialect,
|
27
|
-
username: _app.Core.settings.getDatabase().master.username,
|
28
|
-
password: _app.Core.settings.getDatabase().master.password,
|
29
|
-
define: {
|
30
|
-
timestamps: true
|
31
|
-
},
|
32
|
-
timezone: '-03:00',
|
33
|
-
logging(sql, timing) {
|
34
|
-
(0, _logger.default)().trace('DATABASE', sql, timing);
|
35
|
-
}
|
36
|
-
});
|
package/lib/utils/date.js
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.timestampDifference = timestampDifference;
|
7
|
-
function timestampDifference(timestamp1, timestamp2, type = 'd') {
|
8
|
-
const difference = timestamp1 - timestamp2;
|
9
|
-
let dvrs;
|
10
|
-
switch (type) {
|
11
|
-
case 'd':
|
12
|
-
dvrs = difference / 1000 / 60 / 60 / 24;
|
13
|
-
break;
|
14
|
-
case 'h':
|
15
|
-
dvrs = difference / 1000 / 60 / 60;
|
16
|
-
break;
|
17
|
-
case 'm':
|
18
|
-
dvrs = difference / 1000 / 60;
|
19
|
-
break;
|
20
|
-
case 's':
|
21
|
-
dvrs = difference / 1000;
|
22
|
-
break;
|
23
|
-
default:
|
24
|
-
dvrs = difference / 1000 / 60 / 60 / 24;
|
25
|
-
break;
|
26
|
-
}
|
27
|
-
return Math.round(dvrs * -1 * 100) / 100;
|
28
|
-
}
|
package/lib/utils/index.js
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
var _exportNames = {
|
7
|
-
Api: true,
|
8
|
-
logger: true
|
9
|
-
};
|
10
|
-
Object.defineProperty(exports, "Api", {
|
11
|
-
enumerable: true,
|
12
|
-
get: function () {
|
13
|
-
return _api.default;
|
14
|
-
}
|
15
|
-
});
|
16
|
-
Object.defineProperty(exports, "logger", {
|
17
|
-
enumerable: true,
|
18
|
-
get: function () {
|
19
|
-
return _logger.default;
|
20
|
-
}
|
21
|
-
});
|
22
|
-
var _api = _interopRequireDefault(require("./api"));
|
23
|
-
var _database = require("./database");
|
24
|
-
Object.keys(_database).forEach(function (key) {
|
25
|
-
if (key === "default" || key === "__esModule") return;
|
26
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
27
|
-
if (key in exports && exports[key] === _database[key]) return;
|
28
|
-
Object.defineProperty(exports, key, {
|
29
|
-
enumerable: true,
|
30
|
-
get: function () {
|
31
|
-
return _database[key];
|
32
|
-
}
|
33
|
-
});
|
34
|
-
});
|
35
|
-
var _date = require("./date");
|
36
|
-
Object.keys(_date).forEach(function (key) {
|
37
|
-
if (key === "default" || key === "__esModule") return;
|
38
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
39
|
-
if (key in exports && exports[key] === _date[key]) return;
|
40
|
-
Object.defineProperty(exports, key, {
|
41
|
-
enumerable: true,
|
42
|
-
get: function () {
|
43
|
-
return _date[key];
|
44
|
-
}
|
45
|
-
});
|
46
|
-
});
|
47
|
-
var _logger = _interopRequireDefault(require("./logger"));
|
48
|
-
var _session = require("./session");
|
49
|
-
Object.keys(_session).forEach(function (key) {
|
50
|
-
if (key === "default" || key === "__esModule") return;
|
51
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
52
|
-
if (key in exports && exports[key] === _session[key]) return;
|
53
|
-
Object.defineProperty(exports, key, {
|
54
|
-
enumerable: true,
|
55
|
-
get: function () {
|
56
|
-
return _session[key];
|
57
|
-
}
|
58
|
-
});
|
59
|
-
});
|
60
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
package/lib/utils/logger.js
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = void 0;
|
7
|
-
var _fs = require("fs");
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
9
|
-
var _pino = _interopRequireDefault(require("pino"));
|
10
|
-
var _pinoMultiStream = require("pino-multi-stream");
|
11
|
-
var _app = require("../app");
|
12
|
-
var _dateFns = require("date-fns");
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
14
|
-
let loggerInstance = null;
|
15
|
-
const createLogger = () => {
|
16
|
-
const basePath = _path.default.resolve(_app.Core.settings.getLogger().path, (0, _dateFns.format)(new Date(), 'dd-MM-yyyy'), (0, _dateFns.format)(new Date(), 'HH_mm'));
|
17
|
-
(0, _fs.mkdirSync)(basePath, {
|
18
|
-
recursive: true
|
19
|
-
});
|
20
|
-
const streams = [{
|
21
|
-
level: 'error',
|
22
|
-
stream: (0, _fs.createWriteStream)(basePath + '/error' + _app.Core.settings.getLogger().fileformat)
|
23
|
-
}, {
|
24
|
-
level: 'info',
|
25
|
-
stream: (0, _fs.createWriteStream)(basePath + '/info' + _app.Core.settings.getLogger().fileformat)
|
26
|
-
}, {
|
27
|
-
level: 'fatal',
|
28
|
-
stream: (0, _fs.createWriteStream)(basePath + '/fatal' + _app.Core.settings.getLogger().fileformat)
|
29
|
-
}, {
|
30
|
-
level: 'warn',
|
31
|
-
stream: (0, _fs.createWriteStream)(basePath + '/warn' + _app.Core.settings.getLogger().fileformat)
|
32
|
-
}, {
|
33
|
-
level: 'silent',
|
34
|
-
stream: (0, _fs.createWriteStream)(basePath + '/silent' + _app.Core.settings.getLogger().fileformat)
|
35
|
-
}, {
|
36
|
-
level: 'trace',
|
37
|
-
stream: (0, _fs.createWriteStream)(basePath + '/trace' + _app.Core.settings.getLogger().fileformat)
|
38
|
-
}];
|
39
|
-
_app.Core.settings.getLogger().console ?? streams.push({
|
40
|
-
stream: process.stdout
|
41
|
-
});
|
42
|
-
return (0, _pino.default)({
|
43
|
-
name: 'exodus',
|
44
|
-
level: _app.Core.settings.getLogger().level,
|
45
|
-
// this MUST be set at the lowest level of the
|
46
|
-
timestamp: () => `,"time":"${new Date().toJSON()}"`
|
47
|
-
}, (0, _pinoMultiStream.multistream)(streams));
|
48
|
-
};
|
49
|
-
const logger = () => {
|
50
|
-
if (!loggerInstance) {
|
51
|
-
loggerInstance = createLogger();
|
52
|
-
}
|
53
|
-
return loggerInstance;
|
54
|
-
};
|
55
|
-
var _default = exports.default = logger;
|