exodus-framework 2.0.799 → 2.0.801

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.
@@ -1,5 +1,5 @@
1
1
  import { NextFunction, Response } from 'express';
2
- import { THttpResponse, TSocket, TSocketEventDataMap, TSocketEventHandle } from '../contracts';
2
+ import { IAccount, IServiceRequestor, THttpResponse, TSocket, TSocketEventDataMap, TSocketEventHandle } from '../contracts';
3
3
  import Core from './core';
4
4
  export declare abstract class HttpController extends Core {
5
5
  constructor();
@@ -14,6 +14,17 @@ export declare abstract class SocketController extends Core {
14
14
  export declare class SocketRequest extends Core {
15
15
  protected socket: TSocket;
16
16
  protected event: keyof TSocketEventDataMap;
17
+ readonly auth: {
18
+ exp: number;
19
+ iat: number;
20
+ iss: string;
21
+ account: IAccount;
22
+ };
23
+ readonly tenant: {
24
+ id: string;
25
+ };
26
+ readonly requestor: IServiceRequestor;
27
+ readonly isApplication: boolean;
17
28
  constructor(socket: TSocket, event: keyof TSocketEventDataMap);
18
29
  send<K extends keyof TSocketEventDataMap>(event: K, ...data: TSocketEventDataMap[K]): void;
19
30
  getEvent(): keyof TSocketEventDataMap;
@@ -1 +1 @@
1
- {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/app/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC/F,OAAO,IAAI,MAAM,QAAQ,CAAC;AAS1B,8BAAsB,cAAe,SAAQ,IAAI;;IAe/C,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI;IAIhG,SAAS,CAAC,QAAQ,CAAC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
  }
63
63
  exports.SocketController = SocketController;
64
64
  class SocketRequest extends _core.default {
65
- socket;
66
- event;
65
+ auth;
66
+ tenant;
67
+ requestor;
68
+ isApplication;
67
69
  constructor(socket, event) {
68
70
  super();
69
- this.event = event;
70
71
  this.socket = socket;
72
+ this.event = event;
73
+ this.auth = this.socket.request.auth;
74
+ this.tenant = this.socket.request.tenant;
75
+ this.requestor = this.socket.request.requestor;
76
+ this.isApplication = this.socket.request.isApplication;
71
77
  }
72
78
  send(event, ...data) {
73
79
  this.socket.emit(event, ...data);
package/lib/app/core.js CHANGED
@@ -29,7 +29,7 @@ class Core {
29
29
  constructor(isSystem = false) {
30
30
  this.isSystem = isSystem;
31
31
  this.init();
32
- process.setMaxListeners(20);
32
+ process.setMaxListeners(30);
33
33
  }
34
34
  log(msg, level = 'normal') {
35
35
  if (!msg) return;
@@ -104,7 +104,7 @@ class Core {
104
104
  for (const id in _cluster.default.workers) {
105
105
  const worker = _cluster.default.workers[id];
106
106
  if (worker) {
107
- worker.setMaxListeners(20);
107
+ worker.setMaxListeners(30);
108
108
  worker.on('message', message => this.masterReceiveMessage(worker, message));
109
109
  worker.on('exit', (code, signal) => this.clusterExit(worker, code, signal));
110
110
  }
@@ -1,7 +1,11 @@
1
1
  import { RequestHandler } from 'express';
2
- import HttpController from '../app/controller';
3
- declare class AuthenticationMiddleware extends HttpController {
2
+ import HttpController, { SocketController } from '../app/controller';
3
+ import { IncomingMessage } from 'http';
4
+ import { ServerResponse } from 'http';
5
+ export declare class AuthenticationMiddleware extends HttpController {
4
6
  decryptToken(required?: boolean): RequestHandler;
5
7
  }
6
- export default AuthenticationMiddleware;
8
+ export declare class SocketAuthenticationMiddleware extends SocketController {
9
+ decryptToken: (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => Promise<void>;
10
+ }
7
11
  //# sourceMappingURL=authentication.d.ts.map
@@ -1 +1 @@
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,CAAC,QAAQ,GAAE,OAAc,GAAG,cAAc;CAUvD;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,EAAE,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAMtC,qBAAa,wBAAyB,SAAQ,cAAc;IAC1D,YAAY,CAAC,QAAQ,GAAE,OAAc,GAAG,cAAc;CAUvD;AAED,qBAAa,8BAA+B,SAAQ,gBAAgB;IAClE,YAAY,QAAe,eAAe,OAAO,cAAc,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,mBAgGxF;CACH"}
@@ -3,12 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.SocketAuthenticationMiddleware = exports.AuthenticationMiddleware = void 0;
7
7
  var _expressJwt = require("express-jwt");
8
8
  var _app = require("../app");
9
- var _controller = _interopRequireDefault(require("../app/controller"));
9
+ var _controller = _interopRequireWildcard(require("../app/controller"));
10
10
  var _security = _interopRequireDefault(require("../services/security"));
11
+ var _models = require("../models");
12
+ var _dateFns = require("date-fns");
11
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; }
12
16
  class AuthenticationMiddleware extends _controller.default {
13
17
  decryptToken(required = true) {
14
18
  return (0, _expressJwt.expressjwt)({
@@ -21,4 +25,92 @@ class AuthenticationMiddleware extends _controller.default {
21
25
  });
22
26
  }
23
27
  }
24
- var _default = exports.default = AuthenticationMiddleware;
28
+ exports.AuthenticationMiddleware = AuthenticationMiddleware;
29
+ class SocketAuthenticationMiddleware extends _controller.SocketController {
30
+ decryptToken = async (req, res, next) => {
31
+ const token = req.headers.authorization;
32
+ const tenantId = req.headers['X-Exodus-Tenant-ID'];
33
+ const applicationId = req.headers['X-Exodus-Application-ID'];
34
+ let isApplication = false;
35
+ let envUuid = '';
36
+ try {
37
+ if (!token) {
38
+ const error = new Error('Token ausente');
39
+ error.code = 401;
40
+ return next(error);
41
+ }
42
+ const data = await _security.default.getService().verifySignature(token, _security.default.singleton().getServicePublicKey());
43
+ if (!data) {
44
+ const error = new Error('Token inválido');
45
+ error.code = 401;
46
+ return next(error);
47
+ }
48
+ req.auth = {
49
+ account: data.payload,
50
+ exp: data.exp || 0,
51
+ iat: 0,
52
+ iss: data.iss || ''
53
+ };
54
+ const account = data.payload;
55
+ const requestor = {
56
+ database: '',
57
+ id: account.uuid,
58
+ name: account.name,
59
+ environmentId: tenantId,
60
+ trigger: tenantId
61
+ };
62
+
63
+ /* Aplicações */
64
+ if (applicationId) {
65
+ isApplication = true;
66
+ const application = await _models.Application.findOne({
67
+ where: {
68
+ token: applicationId
69
+ }
70
+ });
71
+ if (!application) {
72
+ const error = new Error('Token de aplicação inválido');
73
+ error.code = 401;
74
+ return next(error);
75
+ } else if (!application.active) {
76
+ const error = new Error('Token de aplicação desativado');
77
+ error.code = 403;
78
+ return next(error);
79
+ } else if ((0, _dateFns.isBefore)(application.expiresAt, new Date())) {
80
+ const error = new Error('Token de aplicação expirado');
81
+ error.code = 403;
82
+ return next(error);
83
+ } else {
84
+ //valido
85
+ const data = await _security.default.singleton().verifySignature(applicationId, _security.default.singleton().getServicePublicKey());
86
+ if (!data) {
87
+ const error = new Error('Token de aplicação sem autênticidade');
88
+ error.code = 401;
89
+ return next(error);
90
+ }
91
+ requestor.database = data.payload.database;
92
+ requestor.environmentId = data.payload.envUuid;
93
+ requestor.name = application.dataValues.name;
94
+ requestor.id = data.payload.token;
95
+ requestor.trigger = applicationId;
96
+ envUuid = data.payload.envUuid;
97
+ }
98
+ } else if (tenantId) {
99
+ envUuid = tenantId;
100
+ }
101
+ if (account && account.type != 'ADMINISTRATOR') {
102
+ requestor.environmentId = account.envUuid;
103
+ envUuid = account.envUuid;
104
+ }
105
+ req.tenant = {
106
+ id: envUuid || _app.Core.settings.getDatabase().service.database
107
+ };
108
+ req.requestor = requestor;
109
+ req.isApplication = isApplication;
110
+ next();
111
+ } catch (error) {
112
+ next(error);
113
+ }
114
+ };
115
+ }
116
+ exports.SocketAuthenticationMiddleware = SocketAuthenticationMiddleware;
@@ -1,4 +1,4 @@
1
1
  export { default as AccessMiddleware } from './access';
2
- export { default as AuthenticationMiddleware } from './authentication';
2
+ export * from './authentication';
3
3
  export { default as FileMiddleware } from './file';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,QAAQ,CAAC"}
@@ -3,18 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ AccessMiddleware: true,
8
+ FileMiddleware: true
9
+ };
6
10
  Object.defineProperty(exports, "AccessMiddleware", {
7
11
  enumerable: true,
8
12
  get: function () {
9
13
  return _access.default;
10
14
  }
11
15
  });
12
- Object.defineProperty(exports, "AuthenticationMiddleware", {
13
- enumerable: true,
14
- get: function () {
15
- return _authentication.default;
16
- }
17
- });
18
16
  Object.defineProperty(exports, "FileMiddleware", {
19
17
  enumerable: true,
20
18
  get: function () {
@@ -22,6 +20,17 @@ Object.defineProperty(exports, "FileMiddleware", {
22
20
  }
23
21
  });
24
22
  var _access = _interopRequireDefault(require("./access"));
25
- var _authentication = _interopRequireDefault(require("./authentication"));
23
+ var _authentication = require("./authentication");
24
+ Object.keys(_authentication).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] === _authentication[key]) return;
28
+ Object.defineProperty(exports, key, {
29
+ enumerable: true,
30
+ get: function () {
31
+ return _authentication[key];
32
+ }
33
+ });
34
+ });
26
35
  var _file = _interopRequireDefault(require("./file"));
27
36
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,8 +1,8 @@
1
- import Service from '../app/service';
2
- import { TSocketEventList } from '../contracts';
3
1
  import { CorsOptions, CorsOptionsDelegate } from 'cors';
4
2
  import { Server as HttpServer } from 'http';
5
3
  import { Server } from 'socket.io';
4
+ import Service from '../app/service';
5
+ import { TSocketEventList } from '../contracts';
6
6
  declare class SocketIOService extends Service {
7
7
  server: Server;
8
8
  private mainRouter;
@@ -1 +1 @@
1
- {"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/services/socket.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAgC,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAUnC,cAAM,eAAgB,SAAQ,OAAO;IAC5B,MAAM,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,UAAU,CAAmB;;IAK/B,oBAAoB;IAQ1B,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,UAAU;IAQlB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,GAAE,WAAW,GAAG,mBAAqC;IAIvF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,gBAAgB;CAG/C;AAED,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/services/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAgC,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAW9E,cAAM,eAAgB,SAAQ,OAAO;IAC5B,MAAM,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,UAAU,CAAmB;;IAK/B,oBAAoB;IAQ1B,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,UAAU;IAQlB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,GAAE,WAAW,GAAG,mBAAqC;IAMvF,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,gBAAgB;CAG/C;AAED,eAAe,eAAe,CAAC"}
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _socket = require("socket.io");
7
8
  var _controller = require("../app/controller");
8
9
  var _service = _interopRequireDefault(require("../app/service"));
9
- var _socket = require("socket.io");
10
+ var _authentication = require("../middlewares/authentication");
10
11
  var _express = _interopRequireDefault(require("./express"));
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
13
  /**
@@ -47,6 +48,8 @@ class SocketIOService extends _service.default {
47
48
  this.server = new _socket.Server(app, {
48
49
  cors
49
50
  });
51
+ const middleware = new _authentication.SocketAuthenticationMiddleware();
52
+ this.server.engine.use(middleware.decryptToken);
50
53
  }
51
54
  static registerRouter(router) {
52
55
  this.getService().mainRouter = router;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ var _http = require("http");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.799",
3
+ "version": "2.0.801",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",