exodus-framework 2.0.697 → 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.
Files changed (53) hide show
  1. package/lib/app/settings.d.ts.map +1 -1
  2. package/lib/app/settings.js +7 -2
  3. package/lib/contracts/messaging.d.ts +28 -1
  4. package/lib/contracts/messaging.d.ts.map +1 -1
  5. package/lib/contracts/messaging.js +4 -0
  6. package/lib/contracts/security.d.ts +11 -0
  7. package/lib/contracts/security.d.ts.map +1 -0
  8. package/lib/contracts/security.js +5 -0
  9. package/lib/contracts/settings.d.ts +6 -0
  10. package/lib/contracts/settings.d.ts.map +1 -1
  11. package/lib/controllers/messaging/database.d.ts +9 -0
  12. package/lib/controllers/messaging/database.d.ts.map +1 -0
  13. package/lib/controllers/messaging/database.js +53 -0
  14. package/lib/controllers/messaging/environment.d.ts +10 -0
  15. package/lib/controllers/messaging/environment.d.ts.map +1 -0
  16. package/lib/controllers/messaging/environment.js +70 -0
  17. package/lib/middlewares/access.d.ts.map +1 -1
  18. package/lib/middlewares/access.js +33 -5
  19. package/lib/middlewares/authentication.d.ts +1 -1
  20. package/lib/middlewares/authentication.d.ts.map +1 -1
  21. package/lib/middlewares/authentication.js +4 -10
  22. package/lib/models/Application.d.ts +13 -0
  23. package/lib/models/Application.d.ts.map +1 -0
  24. package/lib/models/Application.js +61 -0
  25. package/lib/models/Connection.d.ts +1 -0
  26. package/lib/models/Connection.d.ts.map +1 -1
  27. package/lib/models/Connection.js +5 -1
  28. package/lib/models/EnvConnection.d.ts +9 -0
  29. package/lib/models/EnvConnection.d.ts.map +1 -0
  30. package/lib/models/EnvConnection.js +41 -0
  31. package/lib/models/index.d.ts +4 -0
  32. package/lib/models/index.d.ts.map +1 -1
  33. package/lib/models/index.js +31 -1
  34. package/lib/routes/index.d.ts +2 -0
  35. package/lib/routes/index.d.ts.map +1 -0
  36. package/lib/routes/index.js +16 -0
  37. package/lib/routes/messaging/index.d.ts +4 -0
  38. package/lib/routes/messaging/index.d.ts.map +1 -0
  39. package/lib/routes/messaging/index.js +26 -0
  40. package/lib/services/index.d.ts +1 -0
  41. package/lib/services/index.d.ts.map +1 -1
  42. package/lib/services/index.js +9 -1
  43. package/lib/services/rabitmq.d.ts.map +1 -1
  44. package/lib/services/rabitmq.js +6 -0
  45. package/lib/services/security.d.ts +29 -0
  46. package/lib/services/security.d.ts.map +1 -0
  47. package/lib/services/security.js +224 -0
  48. package/lib/services/sequelize.d.ts.map +1 -1
  49. package/lib/services/sequelize.js +4 -0
  50. package/package.json +3 -1
  51. package/lib/contracts/tenant.d.ts +0 -1
  52. package/lib/contracts/tenant.d.ts.map +0 -1
  53. package/lib/contracts/tenant.js +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/app/settings.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAKvB,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,cAAM,YAAY;IAChB,WAAW,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAM;IAChD,cAAc,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAM;IACtD,KAAK,EAAE,OAAO,CAAC,cAAc,CAAC,CAAM;IACpC,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAM;IAC1C,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAM;IAClC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAM;IAC9B,SAAS,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAM;IAE5C,QAAQ,EAAE,eAAe,CA2EvB;IACF,QAAQ,EAAE,eAAe,CAAC;;IAM1B,SAAS,CAAC,aAAa;IAavB,aAAa;IAGb,iBAAiB;IAGjB,QAAQ;IAGR,WAAW;IAGX,OAAO;IAGP,SAAS;IAGT,YAAY;CAGb;AAED,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/app/settings.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAKvB,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAE/B,cAAM,YAAY;IAChB,WAAW,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAM;IAChD,cAAc,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAM;IACtD,KAAK,EAAE,OAAO,CAAC,cAAc,CAAC,CAAM;IACpC,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAM;IAC1C,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAM;IAClC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAM;IAC9B,SAAS,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAM;IAE5C,QAAQ,EAAE,eAAe,CAgFvB;IACF,QAAQ,EAAE,eAAe,CAAC;;IAM1B,SAAS,CAAC,aAAa;IAavB,aAAa;IAGb,iBAAiB;IAGjB,QAAQ;IAGR,WAAW;IAGX,OAAO;IAGP,SAAS;IAGT,YAAY;CAGb;AAED,eAAe,YAAY,CAAC"}
@@ -36,8 +36,13 @@ class CoreSettings {
36
36
  },
37
37
  authentication: {
38
38
  host: process.env.APP_SESSION_URL,
39
- /* APPAuthID:APPAuthPort/SECURITY_JWT_ISSUER */
40
- issuer: `exodus.session.hub:4000/${process.env.SECURITY_JWT_ISSUER}`
39
+ issuer: `${process.env.APP_ID}/${process.env.SECURITY_JWT_ISSUER}`,
40
+ serviceIssuer: `exodus.session.hub:4000/${process.env.SECURITY_JWT_ISSUER}`,
41
+ servicePublicKeyPath: _path.default.resolve(__dirname, '../certificates/service_key.pem'),
42
+ certPath: _path.default.resolve(__dirname, '../certificates'),
43
+ algorithm: 'aes-256-cbc',
44
+ initialVector: 16,
45
+ signExpirationSecs: 60 * 60 * 4 //4hours
41
46
  },
42
47
  cache: {
43
48
  host: process.env.CACHE_HOST || 'localhost',
@@ -1,10 +1,16 @@
1
+ import { Dialect } from 'sequelize';
1
2
  import { IAccount, IEnvironment } from './entity';
3
+ import { Connection } from '@sequelize/core';
2
4
  export declare enum EMessagingQueue {
3
5
  test = "exodus.queue.test",
4
6
  accountCreated = "exodus.account.created",
5
7
  environmentCreated = "exodus.environment.created",
6
8
  environmentDeleted = "exodus.environment.deleted",
7
- environmentUpdatedToken = "exodus.environment.updated.token"
9
+ environmentUpdatedToken = "exodus.environment.updated.token",
10
+ environmentUpdatedDatabase = "exodus.environment.updated.database",
11
+ databaseCreated = "exodus.database.created",
12
+ databaseUpdate = "exodus.database.updated",
13
+ databaseDeleted = "exodus.database.deleted"
8
14
  }
9
15
  export type TMessageQueueDataMap = {
10
16
  [EMessagingQueue.test]: {
@@ -17,11 +23,32 @@ export type TMessageQueueDataMap = {
17
23
  oldToken: string;
18
24
  newToken: string;
19
25
  };
26
+ [EMessagingQueue.environmentUpdatedDatabase]: {
27
+ database: string;
28
+ envUuid: string;
29
+ };
20
30
  [EMessagingQueue.environmentDeleted]: {
21
31
  uuid: string;
22
32
  token: string;
23
33
  database: string;
24
34
  };
35
+ [EMessagingQueue.databaseCreated]: {
36
+ uuid: string;
37
+ name: string;
38
+ dialect: Dialect;
39
+ username: string;
40
+ password: string;
41
+ credential: Buffer;
42
+ active: boolean;
43
+ params?: Record<string, any>;
44
+ };
45
+ [EMessagingQueue.databaseUpdate]: {
46
+ uuid: string;
47
+ updated: Partial<Connection>;
48
+ };
49
+ [EMessagingQueue.databaseDeleted]: {
50
+ uuid: string;
51
+ };
25
52
  };
26
53
  export type TMessagingQueueHandler<K extends keyof TMessageQueueDataMap = any> = (data: TMessageQueueDataMap[K], ack: () => void) => void;
27
54
  export type TMessagingQueueEventList = Partial<Record<keyof TMessageQueueDataMap, TMessagingQueueHandler>>;
@@ -1 +1 @@
1
- {"version":3,"file":"messaging.d.ts","sourceRoot":"","sources":["../../src/contracts/messaging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAElD,oBAAY,eAAe;IACzB,IAAI,sBAAsB;IAG1B,cAAc,2BAA2B;IAGzC,kBAAkB,+BAA+B;IACjD,kBAAkB,+BAA+B;IACjD,uBAAuB,qCAAqC;CAC7D;AAGD,MAAM,MAAM,oBAAoB,GAAG;IACjC,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QACtB,IAAI,EAAE,GAAG,CAAC;KACX,CAAC;IACF,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC3C,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,YAAY,CAAC;IACnD,CAAC,eAAe,CAAC,uBAAuB,CAAC,EAAE;QACzC,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE;QACpC,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,oBAAoB,GAAG,GAAG,IAAI,CAC/E,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,IAAI,KACZ,IAAI,CAAC;AAEV,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAC5C,MAAM,CAAC,MAAM,oBAAoB,EAAE,sBAAsB,CAAC,CAC3D,CAAC"}
1
+ {"version":3,"file":"messaging.d.ts","sourceRoot":"","sources":["../../src/contracts/messaging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE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EAAE,OAAO,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC9B,CAAC;IACF,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;KAC9B,CAAC;IACF,CAAC,eAAe,CAAC,eAAe,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,oBAAoB,GAAG,GAAG,IAAI,CAC/E,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,IAAI,KACZ,IAAI,CAAC;AAEV,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAC5C,MAAM,CAAC,MAAM,oBAAoB,EAAE,sBAAsB,CAAC,CAC3D,CAAC"}
@@ -10,5 +10,9 @@ let EMessagingQueue = exports.EMessagingQueue = /*#__PURE__*/function (EMessagin
10
10
  EMessagingQueue["environmentCreated"] = "exodus.environment.created";
11
11
  EMessagingQueue["environmentDeleted"] = "exodus.environment.deleted";
12
12
  EMessagingQueue["environmentUpdatedToken"] = "exodus.environment.updated.token";
13
+ EMessagingQueue["environmentUpdatedDatabase"] = "exodus.environment.updated.database";
14
+ EMessagingQueue["databaseCreated"] = "exodus.database.created";
15
+ EMessagingQueue["databaseUpdate"] = "exodus.database.updated";
16
+ EMessagingQueue["databaseDeleted"] = "exodus.database.deleted";
13
17
  return EMessagingQueue;
14
18
  }({}); // Mapeamento de tópicos para tipos
@@ -0,0 +1,11 @@
1
+ export type TSignData = {
2
+ payload: any;
3
+ exp?: number;
4
+ iss?: string;
5
+ };
6
+ export type TApplicationSignedData = {
7
+ envUuid: string;
8
+ token: string;
9
+ database: string;
10
+ };
11
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/contracts/security.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -18,6 +18,12 @@ export type TApplicationSettings = {
18
18
  export type TAuthenticationSettings = {
19
19
  host: string;
20
20
  issuer: string;
21
+ serviceIssuer: string;
22
+ algorithm: string;
23
+ initialVector: number;
24
+ certPath: string;
25
+ servicePublicKeyPath: string;
26
+ signExpirationSecs: number;
21
27
  };
22
28
  export type TCacheSettings = {
23
29
  host: string;
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/contracts/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,OAAO,CAAC;IAG1B,SAAS,EAAE,iBAAiB,CAAC;CAC9B,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H,CAAC;AACF,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,UAAU,GAAG,QAAQ,CAAC;CACpC,CAAC;AACF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IAC3C,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,oBAAoB,CAAC;IAClC,cAAc,EAAE,uBAAuB,CAAC;IACxC,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,kBAAkB,CAAC;CAC/B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { MessagingController } from '../../app';
2
+ import { EMessagingQueue, TMessagingQueueHandler } from '../../contracts';
3
+ declare class DatabaseController extends MessagingController {
4
+ created: TMessagingQueueHandler<EMessagingQueue.databaseCreated>;
5
+ update: TMessagingQueueHandler<EMessagingQueue.databaseUpdate>;
6
+ delete: TMessagingQueueHandler<EMessagingQueue.databaseDeleted>;
7
+ }
8
+ export default DatabaseController;
9
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/controllers/messaging/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAI1E,cAAM,kBAAmB,SAAQ,mBAAmB;IAClD,OAAO,EAAE,sBAAsB,CAAC,eAAe,CAAC,eAAe,CAAC,CAc9D;IAEF,MAAM,EAAE,sBAAsB,CAAC,eAAe,CAAC,cAAc,CAAC,CAmB5D;IAEF,MAAM,EAAE,sBAAsB,CAAC,eAAe,CAAC,eAAe,CAAC,CAmB7D;CACH;AAED,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _app = require("../../app");
8
+ var _models = require("../../models");
9
+ var _utils = require("../../utils");
10
+ class DatabaseController extends _app.MessagingController {
11
+ created = async (data, ack) => {
12
+ try {
13
+ const connection = await _models.Connection.create(data);
14
+ if (!connection) {
15
+ (0, _utils.logger)().error(data, 'Não foi possível criar o banco de dados');
16
+ return this.log('Não foi possível criar um banco de dados', 'danger');
17
+ }
18
+ ack();
19
+ } catch (error) {
20
+ (0, _utils.logger)().error(error);
21
+ this.log('Houve um erro ao tentar criar um banco de dados, check o log...', 'danger');
22
+ }
23
+ };
24
+ update = async (data, ack) => {
25
+ try {
26
+ const connection = await _models.Connection.findByPk(data.uuid);
27
+ if (!connection) {
28
+ (0, _utils.logger)().error(data, 'Não foi possível atualizar um banco de dados. Banco não encontrado');
29
+ return this.log('Não foi possível atualizar um banco de dados. Banco não encontrado', 'danger');
30
+ }
31
+ await connection.update(data.updated);
32
+ ack();
33
+ } catch (error) {
34
+ (0, _utils.logger)().error(error);
35
+ this.log('Houve um erro ao tentar atualizar um banco de dados, check o log...', 'danger');
36
+ }
37
+ };
38
+ delete = async (data, ack) => {
39
+ try {
40
+ const connection = await _models.Connection.findByPk(data.uuid);
41
+ if (!connection) {
42
+ (0, _utils.logger)().error(data, 'Não foi possível excluír um banco de dados. Banco não encontrado');
43
+ return this.log('Não foi possível excluír um banco de dados. Banco não encontrado', 'danger');
44
+ }
45
+ await connection.destroy();
46
+ ack();
47
+ } catch (error) {
48
+ (0, _utils.logger)().error(error);
49
+ this.log('Houve um erro ao tentar excluír um banco de dados, check o log...', 'danger');
50
+ }
51
+ };
52
+ }
53
+ var _default = exports.default = DatabaseController;
@@ -0,0 +1,10 @@
1
+ import { MessagingController } from '../../app';
2
+ import { EMessagingQueue, TMessagingQueueHandler } from '../../contracts';
3
+ declare class EnvironmentController extends MessagingController {
4
+ created: TMessagingQueueHandler<EMessagingQueue.environmentCreated>;
5
+ deleted: TMessagingQueueHandler<EMessagingQueue.environmentDeleted>;
6
+ updatedToken: TMessagingQueueHandler<EMessagingQueue.environmentUpdatedToken>;
7
+ updatedDatabase: TMessagingQueueHandler<EMessagingQueue.environmentUpdatedDatabase>;
8
+ }
9
+ export default EnvironmentController;
10
+ //# sourceMappingURL=environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/controllers/messaging/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAI1E,cAAM,qBAAsB,SAAQ,mBAAmB;IACrD,OAAO,EAAE,sBAAsB,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAuBjE;IAEF,OAAO,EAAE,sBAAsB,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAmBjE;IAEF,YAAY,EAAE,sBAAsB,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAK3E;IAEF,eAAe,EAAE,sBAAsB,CAAC,eAAe,CAAC,0BAA0B,CAAC,CAwBjF;CACH;AAED,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _app = require("../../app");
8
+ var _models = require("../../models");
9
+ var _services = require("../../services");
10
+ class EnvironmentController extends _app.MessagingController {
11
+ created = async (data, ack) => {
12
+ const db = data.database;
13
+ const token = data.envToken;
14
+ _services.SequelizeService.singleton().createDB(db, token).then(() => {
15
+ _models.EnvConnection.create({
16
+ envUuid: data.uuid,
17
+ connUuid: data.database,
18
+ envToken: data.envToken
19
+ }).then(() => {
20
+ this.log(`New database created sucessfuly: ${db}`);
21
+ ack();
22
+ }).catch(error => {
23
+ new _services.ApplicationException('Erro ao criar a relação env-db', error);
24
+ });
25
+ }).catch(error => {
26
+ new _services.ApplicationException('Erro ao criar o novo banco de dados', error);
27
+ });
28
+ };
29
+ deleted = async (data, ack) => {
30
+ // const uuid = data.uuid;
31
+ const token = data.token;
32
+ const db = data.database;
33
+ try {
34
+ await _services.SequelizeService.singleton().deleteDB(db, token);
35
+ const relation = await _models.EnvConnection.findOne({
36
+ where: {
37
+ envUuid: data.uuid
38
+ }
39
+ });
40
+ if (relation) await relation.destroy();
41
+ this.log(`Database deleted successfully: ${token}`);
42
+ ack();
43
+ } catch (error) {
44
+ throw new _services.ApplicationException('Erro ao deletar a relação env-db ou não foi possível encontrá-la', error);
45
+ }
46
+ };
47
+ updatedToken = async (data, ack) => {
48
+ //TODO: need implement
49
+ };
50
+ updatedDatabase = async (data, ack) => {
51
+ try {
52
+ const relation = await _models.EnvConnection.findOne({
53
+ where: {
54
+ envUuid: data.envUuid
55
+ }
56
+ });
57
+ if (!relation) {
58
+ new _services.ApplicationException('Não foi possível atualizar a relação EDB, a relação não foi encontrada');
59
+ }
60
+ await relation.update({
61
+ connUuid: data.database
62
+ });
63
+ this.log(`A relação para o ambiente ${data.envUuid} foi atualizada, a migração deverá ser realizada de forma manual`);
64
+ ack();
65
+ } catch (error) {
66
+ new _services.ApplicationException('Erro ao atualizar a relação EDB', error);
67
+ }
68
+ };
69
+ }
70
+ var _default = exports.default = EnvironmentController;
@@ -1 +1 @@
1
- {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/middlewares/access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C,cAAM,gBAAiB,SAAQ,cAAc;IAC3C,WAAW,UAAW,YAAY,EAAE,KAAG,cAAc,CAWnD;IAEF,SAAS,EAAE,cAAc,CAiBvB;CACH;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/middlewares/access.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAO5C,cAAM,gBAAiB,SAAQ,cAAc;IAC3C,WAAW,UAAW,YAAY,EAAE,KAAG,cAAc,CAWnD;IAEF,SAAS,EAAE,cAAc,CAiDvB;CACH;AAED,eAAe,gBAAgB,CAAC"}
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _dateFns = require("date-fns");
8
+ var _app = require("../app");
7
9
  var _controller = _interopRequireDefault(require("../app/controller"));
8
10
  var _http = require("../contracts/http");
11
+ var _models = require("../models");
9
12
  var _error = require("../services/error");
10
- var _app = require("../app");
13
+ var _security = _interopRequireDefault(require("../services/security"));
11
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
15
  class AccessMiddleware extends _controller.default {
13
16
  accessLevel = level => {
@@ -21,13 +24,38 @@ class AccessMiddleware extends _controller.default {
21
24
  getTenant = async (req, res, next) => {
22
25
  const account = req.auth?.account;
23
26
  const tenantId = req.header('X-Exodus-Tenant-ID');
24
- if (account && account.type != 'ADMINISTRATOR') {
25
- if (!tenantId) {
26
- throw new _error.ApplicationHttpException('Informações do ambiente incompletas', _http.EHttpResponseCode.incompleteRequest);
27
+ const applicationId = req.header('X-Exodus-Application-ID');
28
+ let envUuid = '';
29
+
30
+ /* Aplicações */
31
+ if (applicationId) {
32
+ const application = await _models.Application.findOne({
33
+ where: {
34
+ token: applicationId
35
+ }
36
+ });
37
+ if (!application) {
38
+ throw new _error.ApplicationHttpException('Token de aplicação inválido', _http.EHttpResponseCode.informationUnauthorized);
39
+ } else if (!application.active) {
40
+ throw new _error.ApplicationHttpException('Token desativado', _http.EHttpResponseCode.informationBlocked);
41
+ } else if ((0, _dateFns.isBefore)(application.expiresAt, new Date())) {
42
+ throw new _error.ApplicationHttpException('Token expirado', _http.EHttpResponseCode.informationBlocked);
43
+ } else {
44
+ //valido
45
+ const data = await _security.default.singleton().verifySignature(applicationId, _security.default.singleton().getServicePublicKey());
46
+ if (!data) {
47
+ throw new _error.ApplicationHttpException('Token sem autênticidade.', _http.EHttpResponseCode.informationBlocked);
48
+ }
49
+ envUuid = data.envUuid;
27
50
  }
51
+ } else if (tenantId) {
52
+ envUuid = tenantId;
53
+ }
54
+ if (account && account.type != 'ADMINISTRATOR') {
55
+ envUuid = account.envUuid;
28
56
  }
29
57
  req.tenant = {
30
- id: tenantId || `root@${_app.Core.settings.getDatabase().service.database}`
58
+ id: envUuid || `root@${_app.Core.settings.getDatabase().service.database}`
31
59
  };
32
60
  next();
33
61
  };
@@ -1,5 +1,5 @@
1
- import HttpController from '../app/controller';
2
1
  import { RequestHandler } from 'express';
2
+ import HttpController from '../app/controller';
3
3
  declare class AuthenticationMiddleware extends HttpController {
4
4
  decryptToken: RequestHandler;
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middlewares/authentication.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,cAAM,wBAAyB,SAAQ,cAAc;IACnD,YAAY,EAAE,cAAc,CAYzB;CACJ;AAED,eAAe,wBAAwB,CAAC"}
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middlewares/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGzC,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAG/C,cAAM,wBAAyB,SAAQ,cAAc;IACnD,YAAY,EAAE,cAAc,CAMzB;CACJ;AAED,eAAe,wBAAwB,CAAC"}
@@ -4,23 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _expressJwt = require("express-jwt");
7
8
  var _app = require("../app");
8
9
  var _controller = _interopRequireDefault(require("../app/controller"));
9
- var _session = require("../utils/session");
10
- var _expressJwt = require("express-jwt");
10
+ var _security = _interopRequireDefault(require("../services/security"));
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  class AuthenticationMiddleware extends _controller.default {
13
13
  decryptToken = (0, _expressJwt.expressjwt)({
14
14
  secret: async () => {
15
- try {
16
- const api = new _session.SessionAPI();
17
- return (await api.getCertificate()).data;
18
- } catch (error) {
19
- this.log('Não foi possível obter o certificado de segurança.', 'danger');
20
- return '';
21
- }
15
+ return _security.default.singleton().getServicePublicKey().toPEM(false);
22
16
  },
23
- issuer: _app.Core.settings.getAuthentication().issuer,
17
+ issuer: _app.Core.settings.getAuthentication().serviceIssuer,
24
18
  algorithms: ['RS256']
25
19
  });
26
20
  }
@@ -0,0 +1,13 @@
1
+ import { CreationOptional, InferAttributes, InferCreationAttributes, Model } from 'sequelize';
2
+ export declare class Application extends Model<InferAttributes<Application>, InferCreationAttributes<Application>> {
3
+ uuid: CreationOptional<string>;
4
+ name: string;
5
+ comments: string;
6
+ token: string;
7
+ acess: string;
8
+ expiresAt: string;
9
+ key: string;
10
+ active: boolean;
11
+ params: CreationOptional<Record<string, any>>;
12
+ }
13
+ //# sourceMappingURL=Application.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../src/models/Application.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,eAAe,EACf,uBAAuB,EACvB,KAAK,EACN,MAAM,WAAW,CAAC;AAGnB,qBAAa,WAAY,SAAQ,KAAK,CACpC,eAAe,CAAC,WAAW,CAAC,EAC5B,uBAAuB,CAAC,WAAW,CAAC,CACrC;IACS,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACvD"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Application = void 0;
7
+ var _sequelize = require("sequelize");
8
+ var _database = require("../utils/database");
9
+ class Application extends _sequelize.Model {}
10
+ exports.Application = Application;
11
+ Application.init({
12
+ uuid: {
13
+ type: _sequelize.DataTypes.UUID,
14
+ defaultValue: _sequelize.DataTypes.UUIDV4,
15
+ primaryKey: true,
16
+ allowNull: false,
17
+ autoIncrement: false
18
+ },
19
+ name: {
20
+ type: _sequelize.DataTypes.STRING(200),
21
+ allowNull: false
22
+ },
23
+ token: {
24
+ type: _sequelize.DataTypes.TEXT,
25
+ allowNull: false
26
+ },
27
+ key: {
28
+ type: _sequelize.DataTypes.TEXT,
29
+ allowNull: false
30
+ },
31
+ acess: {
32
+ type: _sequelize.DataTypes.JSON(),
33
+ allowNull: true
34
+ },
35
+ expiresAt: {
36
+ type: _sequelize.DataTypes.DATE,
37
+ allowNull: false
38
+ },
39
+ active: {
40
+ type: _sequelize.DataTypes.BOOLEAN,
41
+ defaultValue: true
42
+ },
43
+ comments: {
44
+ type: _sequelize.DataTypes.STRING(255),
45
+ allowNull: true
46
+ },
47
+ params: {
48
+ type: _sequelize.DataTypes.JSON,
49
+ defaultValue: {},
50
+ allowNull: true
51
+ }
52
+ }, {
53
+ tableName: 'connections',
54
+ sequelize: _database.serviceDB,
55
+ indexes: [{
56
+ fields: ['name']
57
+ }, {
58
+ fields: ['token'],
59
+ unique: true
60
+ }]
61
+ });
@@ -5,6 +5,7 @@ export declare class Connection extends Model<InferAttributes<Connection>, Infer
5
5
  dialect: Dialect;
6
6
  username: string;
7
7
  password: string;
8
+ credential: Buffer;
8
9
  active: boolean;
9
10
  params: CreationOptional<Record<string, any>>;
10
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Connection.d.ts","sourceRoot":"","sources":["../../src/models/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,OAAO,EACP,eAAe,EACf,uBAAuB,EACvB,KAAK,EACN,MAAM,WAAW,CAAC;AAGnB,qBAAa,UAAW,SAAQ,KAAK,CACnC,eAAe,CAAC,UAAU,CAAC,EAC3B,uBAAuB,CAAC,UAAU,CAAC,CACpC;IACS,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACvD"}
1
+ {"version":3,"file":"Connection.d.ts","sourceRoot":"","sources":["../../src/models/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,OAAO,EACP,eAAe,EACf,uBAAuB,EACvB,KAAK,EACN,MAAM,WAAW,CAAC;AAGnB,qBAAa,UAAW,SAAQ,KAAK,CACnC,eAAe,CAAC,UAAU,CAAC,EAC3B,uBAAuB,CAAC,UAAU,CAAC,CACpC;IACS,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACvD"}
@@ -28,6 +28,10 @@ Connection.init({
28
28
  type: _sequelize.DataTypes.STRING(100),
29
29
  allowNull: false
30
30
  },
31
+ credential: {
32
+ type: _sequelize.DataTypes.BLOB('medium'),
33
+ allowNull: false
34
+ },
31
35
  password: {
32
36
  type: _sequelize.DataTypes.STRING(100),
33
37
  allowNull: false
@@ -43,7 +47,7 @@ Connection.init({
43
47
  }
44
48
  }, {
45
49
  tableName: 'connections',
46
- sequelize: _database.masterDB,
50
+ sequelize: _database.serviceDB,
47
51
  indexes: [{
48
52
  fields: ['name']
49
53
  }]
@@ -0,0 +1,9 @@
1
+ import type { CreationOptional, InferAttributes, InferCreationAttributes } from 'sequelize';
2
+ import { Model } from 'sequelize';
3
+ export declare class EnvConnection extends Model<InferAttributes<EnvConnection>, InferCreationAttributes<EnvConnection>> {
4
+ uuid: CreationOptional<string>;
5
+ envUuid: string;
6
+ connUuid: string;
7
+ envToken: string;
8
+ }
9
+ //# sourceMappingURL=EnvConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvConnection.d.ts","sourceRoot":"","sources":["../../src/models/EnvConnection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAC5F,OAAO,EAAa,KAAK,EAAE,MAAM,WAAW,CAAC;AAG7C,qBAAa,aAAc,SAAQ,KAAK,CACtC,eAAe,CAAC,aAAa,CAAC,EAC9B,uBAAuB,CAAC,aAAa,CAAC,CACvC;IACS,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EnvConnection = void 0;
7
+ var _sequelize = require("sequelize");
8
+ var _utils = require("../utils");
9
+ class EnvConnection extends _sequelize.Model {}
10
+ exports.EnvConnection = EnvConnection;
11
+ EnvConnection.init({
12
+ uuid: {
13
+ type: _sequelize.DataTypes.UUID,
14
+ defaultValue: _sequelize.DataTypes.UUIDV4,
15
+ primaryKey: true,
16
+ allowNull: false,
17
+ autoIncrement: false
18
+ },
19
+ connUuid: {
20
+ type: _sequelize.DataTypes.UUID,
21
+ allowNull: false
22
+ },
23
+ envUuid: {
24
+ type: _sequelize.DataTypes.UUID,
25
+ allowNull: false
26
+ },
27
+ envToken: {
28
+ type: _sequelize.DataTypes.UUID,
29
+ allowNull: false
30
+ }
31
+ }, {
32
+ tableName: 'env_connection',
33
+ sequelize: _utils.serviceDB,
34
+ indexes: [{
35
+ fields: ['envUuid'],
36
+ unique: true
37
+ }, {
38
+ fields: ['envToken', 'connUuid'],
39
+ unique: true
40
+ }]
41
+ });
@@ -1,2 +1,6 @@
1
+ import { ModelStatic } from 'sequelize';
1
2
  export * from './Connection';
3
+ export * from './EnvConnection';
4
+ export * from './Application';
5
+ export declare const NativeModels: ModelStatic<any>[];
2
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAKxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAE9B,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,GAAG,CAAC,EAA6C,CAAC"}
@@ -3,9 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ NativeModels: true
8
+ };
9
+ exports.NativeModels = void 0;
6
10
  var _Connection = require("./Connection");
7
11
  Object.keys(_Connection).forEach(function (key) {
8
12
  if (key === "default" || key === "__esModule") return;
13
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
9
14
  if (key in exports && exports[key] === _Connection[key]) return;
10
15
  Object.defineProperty(exports, key, {
11
16
  enumerable: true,
@@ -13,4 +18,29 @@ Object.keys(_Connection).forEach(function (key) {
13
18
  return _Connection[key];
14
19
  }
15
20
  });
16
- });
21
+ });
22
+ var _EnvConnection = require("./EnvConnection");
23
+ Object.keys(_EnvConnection).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
26
+ if (key in exports && exports[key] === _EnvConnection[key]) return;
27
+ Object.defineProperty(exports, key, {
28
+ enumerable: true,
29
+ get: function () {
30
+ return _EnvConnection[key];
31
+ }
32
+ });
33
+ });
34
+ var _Application = require("./Application");
35
+ Object.keys(_Application).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
38
+ if (key in exports && exports[key] === _Application[key]) return;
39
+ Object.defineProperty(exports, key, {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _Application[key];
43
+ }
44
+ });
45
+ });
46
+ const NativeModels = exports.NativeModels = [_Connection.Connection, _EnvConnection.EnvConnection, _Application.Application];
@@ -0,0 +1,2 @@
1
+ export * from './messaging';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -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,4 @@
1
+ import { TMessagingQueueEventList } from '../../contracts';
2
+ declare const NativeMessagingRoutes: TMessagingQueueEventList;
3
+ export default NativeMessagingRoutes;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/routes/messaging/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAS3D,QAAA,MAAM,qBAAqB,EAAE,wBAW5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -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;
@@ -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"}
@@ -9,7 +9,8 @@ var _exportNames = {
9
9
  RabbitMQService: true,
10
10
  RedisService: true,
11
11
  SequelizeService: true,
12
- SocketIOService: true
12
+ SocketIOService: true,
13
+ SecurityService: true
13
14
  };
14
15
  Object.defineProperty(exports, "ExpressService", {
15
16
  enumerable: true,
@@ -35,6 +36,12 @@ Object.defineProperty(exports, "RedisService", {
35
36
  return _redis.default;
36
37
  }
37
38
  });
39
+ Object.defineProperty(exports, "SecurityService", {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _security.default;
43
+ }
44
+ });
38
45
  Object.defineProperty(exports, "SequelizeService", {
39
46
  enumerable: true,
40
47
  get: function () {
@@ -65,6 +72,7 @@ var _rabitmq = _interopRequireDefault(require("./rabitmq"));
65
72
  var _redis = _interopRequireDefault(require("./redis"));
66
73
  var _sequelize = _interopRequireDefault(require("./sequelize"));
67
74
  var _socket = _interopRequireDefault(require("./socket"));
75
+ var _security = _interopRequireDefault(require("./security"));
68
76
  var _task = require("./task");
69
77
  Object.keys(_task).forEach(function (key) {
70
78
  if (key === "default" || key === "__esModule") return;
@@ -1 +1 @@
1
- {"version":3,"file":"rabitmq.d.ts","sourceRoot":"","sources":["../../src/services/rabitmq.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAEL,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,cAAc,CAAC;AACtB,OAAe,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MA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AC,EACR,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC;IA2BrC,cAAc,CAAC,MAAM,EAAE,wBAAwB;CAGhD;AAED,eAAe,eAAe,CAAC"}
@@ -8,6 +8,7 @@ var _service = _interopRequireDefault(require("../app/service"));
8
8
  var _amqplib = _interopRequireDefault(require("amqplib"));
9
9
  var _error = require("./error");
10
10
  var _app = require("../app");
11
+ var _messaging = _interopRequireDefault(require("../routes/messaging"));
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
13
  /**
13
14
  * Serviço de Mensageria
@@ -28,6 +29,11 @@ class RabbitMQService extends _service.default {
28
29
  }
29
30
  async init() {
30
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
31
37
  await this.connect();
32
38
  }
33
39
  registerHandles() {
@@ -0,0 +1,29 @@
1
+ import { JWK, JWS } from 'node-jose';
2
+ import { Service } from '../app';
3
+ import { IService } from '../contracts';
4
+ import { TSignData } from '../contracts/security';
5
+ declare class SecurityService extends Service implements IService {
6
+ private privateKey;
7
+ private publicKey;
8
+ private servicePublicKey;
9
+ init(): Promise<void>;
10
+ private checkPaths;
11
+ private loadPrivateKey;
12
+ private loadPublicKey;
13
+ createKeyPairs(): Promise<{
14
+ publicKey: string;
15
+ privateKey: string;
16
+ }>;
17
+ loadServicePublicKey(): Promise<void>;
18
+ getPrivateKey(): JWK.Key;
19
+ getPublicKey(): JWK.Key;
20
+ getServicePublicKey(): JWK.Key;
21
+ encrypt(data: TSignData, publicKey: JWK.Key): Promise<string | false>;
22
+ decrypt<T = any>(encryptedData: string, privateKey: JWK.Key): Promise<T | false>;
23
+ sign(data: TSignData, privateKey: JWK.Key): Promise<JWS.CreateSignResult>;
24
+ verifySignature<T = any>(signature: string, publicKey: JWK.Key): Promise<T | false>;
25
+ simpleEncrypt(data: string | object): [string, Buffer];
26
+ simpleDecrypt(data: string, key: Buffer): Buffer | false;
27
+ }
28
+ export default SecurityService;
29
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/services/security.ts"],"names":[],"mappings":"AAEA,OAAO,EAAO,GAAG,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAQ,OAAO,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,cAAM,eAAgB,SAAQ,OAAQ,YAAW,QAAQ;IACvD,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,gBAAgB,CAAU;IAE5B,IAAI;IAMV,OAAO,CAAC,UAAU;YAMJ,cAAc;YAWd,aAAa;IAMd,cAAc;;;;IASd,oBAAoB;IAgB1B,aAAa;IAQb,YAAY;IAQZ,mBAAmB;IASb,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,GAAG;IAyB3C,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC;IAkBhF,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,GAAG;IA0BzC,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC;IAiBzF,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAoBtD,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK;CAgBhE;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var crypto = _interopRequireWildcard(require("crypto"));
8
+ var fs = _interopRequireWildcard(require("fs"));
9
+ var _nodeJose = require("node-jose");
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _app = require("../app");
12
+ var _error = require("./error");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ 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); }
15
+ 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; }
16
+ class SecurityService extends _app.Service {
17
+ privateKey;
18
+ publicKey;
19
+ servicePublicKey;
20
+ async init() {
21
+ this.checkPaths();
22
+ await this.loadPrivateKey();
23
+ await this.loadPublicKey();
24
+ }
25
+ checkPaths() {
26
+ !fs.existsSync(_app.Core.settings.getAuthentication().certPath) && fs.mkdirSync(_app.Core.settings.getAuthentication().certPath, {
27
+ recursive: true
28
+ });
29
+ }
30
+
31
+ /* Key Pair */
32
+ async loadPrivateKey() {
33
+ const privateKeyPath = _path.default.join(_app.Core.settings.getAuthentication().certPath, 'private_key.pem');
34
+ if (fs.existsSync(privateKeyPath)) {
35
+ const pem = fs.readFileSync(privateKeyPath, 'utf8');
36
+ this.privateKey = await _nodeJose.JWK.asKey(pem, 'pem');
37
+ } else {
38
+ const {
39
+ privateKey
40
+ } = await this.createKeyPairs();
41
+ this.privateKey = await _nodeJose.JWK.asKey(privateKey, 'pem');
42
+ }
43
+ }
44
+ async loadPublicKey() {
45
+ const publicKeyPath = _path.default.join(_app.Core.settings.getAuthentication().certPath, 'public_key.pem');
46
+ const pem = this.privateKey.toPEM(false);
47
+ this.publicKey == (await _nodeJose.JWK.asKey(pem, 'pem'));
48
+ fs.writeFileSync(publicKeyPath, pem, 'utf8');
49
+ }
50
+ async createKeyPairs() {
51
+ const keyPair = await _nodeJose.JWK.createKey('RSA', 2048, {
52
+ alg: 'RS256',
53
+ use: 'sig',
54
+ iss: _app.Core.settings.getAuthentication().issuer
55
+ });
56
+ return {
57
+ publicKey: keyPair.toPEM(false),
58
+ privateKey: keyPair.toPEM(true)
59
+ };
60
+ }
61
+ async loadServicePublicKey() {
62
+ if (fs.existsSync(_app.Core.settings.getAuthentication().servicePublicKeyPath)) {
63
+ const pem = fs.readFileSync(_app.Core.settings.getAuthentication().servicePublicKeyPath, 'utf8');
64
+ this.servicePublicKey = await _nodeJose.JWK.asKey(pem, 'pem');
65
+ } else {
66
+ throw new _error.ApplicationException('Não foi possível localizar o certificado de serviço. Verifique o caminho nas configurações');
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Chave privada emitida por este serviço
72
+ *
73
+ * @memberof SecurityService
74
+ */
75
+ getPrivateKey() {
76
+ return this.privateKey;
77
+ }
78
+ /**
79
+ * Chave publica emitida por este serviço
80
+ *
81
+ * @memberof SecurityService
82
+ */
83
+ getPublicKey() {
84
+ return this.publicKey;
85
+ }
86
+ /**
87
+ * Chave publica emitida pelo serviço do hub se sessões
88
+ *
89
+ * @memberof SecurityService
90
+ */
91
+ getServicePublicKey() {
92
+ return this.servicePublicKey;
93
+ }
94
+ /**
95
+ * Criptografía utilizando chave publica
96
+ *
97
+ * @param {TSignData} data
98
+ * @memberof SecurityService
99
+ */
100
+ async encrypt(data, publicKey) {
101
+ const currentTime = Math.floor(Date.now() / 1000);
102
+ const defaults = {
103
+ iat: currentTime,
104
+ exp: currentTime + _app.Core.settings.getAuthentication().signExpirationSecs,
105
+ iss: _app.Core.settings.getAuthentication().issuer
106
+ };
107
+ const payload = JSON.stringify({
108
+ ...defaults,
109
+ ...data
110
+ });
111
+ try {
112
+ const encrypted = await _nodeJose.JWE.createEncrypt({
113
+ format: 'compact'
114
+ }, publicKey).update(payload).final();
115
+ return encrypted;
116
+ } catch (error) {
117
+ new _error.ApplicationException('Não foi possível criptografar os dados', error);
118
+ return false;
119
+ }
120
+ }
121
+ /**
122
+ * Descriptografia utilizando chave privada
123
+ *
124
+ * @param {string} encryptedData
125
+ * @memberof SecurityService
126
+ */
127
+ async decrypt(encryptedData, privateKey) {
128
+ try {
129
+ const decrypted = await _nodeJose.JWE.createDecrypt(privateKey).decrypt(encryptedData);
130
+ const result = decrypted.plaintext.toString();
131
+ const parserd = JSON.parse(result);
132
+ // Tenta parsear como JSON se for objeto
133
+ return parserd.payload;
134
+ } catch (error) {
135
+ new _error.ApplicationException('Não foi possível descriptografar os dados', error);
136
+ return false;
137
+ }
138
+ }
139
+ /**
140
+ * Realiza uma assinatura usando chave privada
141
+ *
142
+ * @param {TSignData} data
143
+ * @memberof SecurityService
144
+ */
145
+ async sign(data, privateKey) {
146
+ const currentTime = Math.floor(Date.now() / 1000);
147
+ const defaults = {
148
+ iat: currentTime,
149
+ exp: currentTime + _app.Core.settings.getAuthentication().signExpirationSecs,
150
+ iss: _app.Core.settings.getAuthentication().issuer
151
+ };
152
+ try {
153
+ const payload = JSON.stringify({
154
+ ...defaults,
155
+ ...data
156
+ });
157
+ const signature = await _nodeJose.JWS.createSign({
158
+ compact: true,
159
+ fields: {
160
+ typ: 'jwt'
161
+ }
162
+ }, privateKey).update(payload, 'utf8').final();
163
+ return signature;
164
+ } catch (error) {
165
+ throw new _error.ApplicationException('Erro ao assinar os dados', error);
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Verifica assinatura utilizando chave publica
171
+ *
172
+ * @param {string} signature
173
+ * @memberof SecurityService
174
+ */
175
+ async verifySignature(signature, publicKey) {
176
+ try {
177
+ const result = await _nodeJose.JWS.createVerify(publicKey).verify(signature);
178
+ const payload = result.payload.toString();
179
+ return JSON.parse(payload);
180
+ } catch (error) {
181
+ new _error.ApplicationException('Assinatura inválida ou erro durante a verificação', error);
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Criptografía de dados utilizando um buffer automático ao invés de chaves
187
+ *
188
+ * @param {(string | object)} data
189
+ * @memberof SecurityService
190
+ */
191
+ simpleEncrypt(data) {
192
+ if (process.versions.openssl <= '1.0.1f') {
193
+ throw new Error('OpenSSL Version too old, vulnerability to Heartbleed');
194
+ }
195
+ const key = crypto.randomBytes(32);
196
+ const iv = crypto.randomBytes(16);
197
+ const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv);
198
+ let encrypted = cipher.update(data);
199
+ encrypted = Buffer.concat([encrypted, cipher.final()]);
200
+ return [iv.toString('hex') + ':' + encrypted.toString('hex'), key];
201
+ }
202
+ /**
203
+ * Utiliza um buffer para descriptografar dados criptografados através de simpleEncrypt()
204
+ *
205
+ * @param {string} data
206
+ * @param {Buffer} key
207
+ * @memberof SecurityService
208
+ */
209
+ simpleDecrypt(data, key) {
210
+ try {
211
+ const textParts = data.split(':');
212
+ const iv = Buffer.from(textParts.shift(), 'hex');
213
+ const encryptedText = Buffer.from(textParts.join(':'), 'hex');
214
+ const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key), iv);
215
+ let decrypted = decipher.update(encryptedText);
216
+ decrypted = Buffer.concat([decrypted, decipher.final()]);
217
+ return decrypted;
218
+ } catch (error) {
219
+ new _error.ApplicationException('Erro durante a descriptografia de dados', error);
220
+ return false;
221
+ }
222
+ }
223
+ }
224
+ var _default = exports.default = SecurityService;
@@ -1 +1 @@
1
- {"version":3,"file":"sequelize.d.ts","sourceRoot":"","sources":["../../src/services/sequ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Connection");
11
11
  var _database = require("../utils/database");
12
12
  var _logger = _interopRequireDefault(require("../utils/logger"));
13
13
  var _error = require("./error");
14
+ var _models = require("../models");
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  /**
16
17
  * Serviço de gerênciamento do banco de dados
@@ -39,6 +40,9 @@ class SequelizeService extends _service.default {
39
40
  }
40
41
  async connectMainDatabase() {
41
42
  if (!this.models) throw new _error.ApplicationException('Models are requireds! Call registerModels(modelsArray)');
43
+
44
+ // #Include native models
45
+ this.models = [...this.models, ..._models.NativeModels];
42
46
  return new Promise(resolve => {
43
47
  this.masterDB.sync({
44
48
  force: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.697",
3
+ "version": "2.0.700",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@sequelize/core": "^7.0.0-alpha.37",
27
+ "@types/node-jose": "^1.1.13",
27
28
  "amqplib": "^0.10.4",
28
29
  "axios": "^1.7.5",
29
30
  "bullmq": "^5.12.11",
@@ -38,6 +39,7 @@
38
39
  "mariadb": "^3.3.1",
39
40
  "multer": "^1.4.5-lts.1",
40
41
  "mysql2": "^3.11.0",
42
+ "node-jose": "^2.2.0",
41
43
  "node-schedule": "^2.1.1",
42
44
  "pino": "^9.3.2",
43
45
  "pino-http": "^10.2.0",
@@ -1 +0,0 @@
1
- //# sourceMappingURL=tenant.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../src/contracts/tenant.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- "use strict";