exodus-framework 2.0.66 → 2.0.67

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.
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=tenant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../src/contracts/tenant.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -3,7 +3,7 @@ import HttpController from '../app/controller';
3
3
  import { TAccountType } from '../contracts';
4
4
  declare class AccessMiddleware extends HttpController {
5
5
  accessLevel: (level: TAccountType[]) => RequestHandler;
6
- getConnection: RequestHandler;
6
+ getTenant: RequestHandler;
7
7
  }
8
8
  export default AccessMiddleware;
9
9
  //# sourceMappingURL=access.d.ts.map
@@ -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,aAAa,EAAE,cAAc,CAqB3B;CACH;AAED,eAAe,gBAAgB,CAAC"}
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;AAI5C,cAAM,gBAAiB,SAAQ,cAAc;IAC3C,WAAW,UAAW,YAAY,EAAE,KAAG,cAAc,CAWnD;IAEF,SAAS,EAAE,cAAc,CAevB;CACH;AAED,eAAe,gBAAgB,CAAC"}
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _controller = _interopRequireDefault(require("../app/controller"));
8
8
  var _http = require("../contracts/http");
9
- var _services = require("../services");
10
9
  var _error = require("../services/error");
11
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
11
  class AccessMiddleware extends _controller.default {
@@ -18,19 +17,14 @@ class AccessMiddleware extends _controller.default {
18
17
  next();
19
18
  };
20
19
  };
21
- getConnection = async (req, res, next) => {
20
+ getTenant = async (req, res, next) => {
22
21
  const account = req.auth?.account;
23
- const envToken = req.header('X-Exodus-Environment-Token');
24
- const connUuid = req.header('X-Exodus-Connection');
22
+ const tenantId = req.header('X-Exodus-Tenant-ID');
25
23
  if (account && account.type != 'ADMINISTRATOR') {
26
- if (!envToken || !connUuid) {
24
+ if (!tenantId) {
27
25
  throw new _error.ApplicationHttpException('Informações do ambiente incompletas', _http.EHttpResponseCode.incompleteRequest);
28
26
  }
29
- const connection = await _services.SequelizeService.singleton().getDB(connUuid, envToken);
30
- if (!connection) {
31
- throw new _error.ApplicationHttpException('Não foi possível obter a conexão deste ambiente');
32
- }
33
- req.auth.connection = connection;
27
+ req.tenant.id = tenantId;
34
28
  }
35
29
  next();
36
30
  };
@@ -14,12 +14,16 @@ declare class SequelizeService extends Service implements IService {
14
14
  getMasterConnection(): Sequelize;
15
15
  createDB(connection_uuid: string, name: string): Promise<boolean>;
16
16
  deleteDB(connection_uuid: string, name: string): Promise<boolean>;
17
- getDB(uuid: string, name: string): Promise<Sequelize>;
18
- initDB(uuid: string, name: string): Promise<unknown>;
17
+ getDB(tenantId: string): Promise<Sequelize>;
18
+ initDB(tenantId: string): Promise<unknown>;
19
19
  registerModels(models: ModelStatic<any>[]): void;
20
20
  getModel<M extends typeof Model<any, any>>(model: typeof Model<any, any> & {
21
21
  initialize: (connection: Sequelize) => M;
22
- }, conn_uuid: string, envToken: string): Promise<M>;
22
+ }, tenantId: string): Promise<M>;
23
+ parseDataInfoByTenantId(tenant: string): {
24
+ envToken: string;
25
+ con_uuid: string;
26
+ };
23
27
  }
24
28
  export default SequelizeService;
25
29
  //# sourceMappingURL=sequelize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sequelize.d.ts","sourceRoot":"","sources":["../../src/services/sequelize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAahD,cAAM,gBAAiB,SAAQ,OAAQ,YAAW,QAAQ;IACxD,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3B,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;;IAMjD,IAAI;IAMJ,mBAAmB;IA4BzB,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,SAAI;IAerC,mBAAmB;IAGb,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IA6C9C,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAwC9C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAKhC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IA8CvC,cAAc,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE;IAInC,QAAQ,CAAC,CAAC,SAAS,OAAO,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAC7C,KAAK,EAAE,OAAO,KAAK,CAAC,GA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E,GAAG,CAAC,GAAG;QAAE,UAAU,EAAE,CAAC,UAAU,EAAE,SAAS,KAAK,CAAC,CAAA;KAAE,EAC5E,QAAQ,EAAE,MAAM;IAmBlB,uBAAuB,CAAC,MAAM,EAAE,MAAM;;;;CAMvC;AAED,eAAe,gBAAgB,CAAC"}
@@ -146,20 +146,28 @@ class SequelizeService extends _service.default {
146
146
  });
147
147
  });
148
148
  }
149
- async getDB(uuid, name) {
150
- const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${name}`;
151
- const queryId = `${uuid}@${dbQueryName}`;
149
+ async getDB(tenantId) {
150
+ const {
151
+ con_uuid,
152
+ envToken
153
+ } = this.parseDataInfoByTenantId(tenantId);
154
+ const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`;
155
+ const queryId = `${con_uuid}@${dbQueryName}`;
152
156
  return this.connections.get(queryId);
153
157
  }
154
- async initDB(uuid, name) {
155
- const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${name}`;
156
- const queryId = `${uuid}@${dbQueryName}`;
158
+ async initDB(tenantId) {
159
+ const {
160
+ con_uuid,
161
+ envToken
162
+ } = this.parseDataInfoByTenantId(tenantId);
163
+ const dbQueryName = `${_app.Core.settings.getDatabase().service.database}_${envToken}`;
164
+ const queryId = `${con_uuid}@${dbQueryName}`;
157
165
  if (this.connections.get(queryId)) {
158
166
  return false;
159
167
  }
160
- const connData = await _Connection.Connection.findByPk(uuid);
168
+ const connData = await _Connection.Connection.findByPk(con_uuid);
161
169
  if (!connData) {
162
- this.log('Connection data not found: ' + uuid);
170
+ this.log('Connection data not found: ' + con_uuid);
163
171
  return false;
164
172
  }
165
173
  const conn = new _sequelize.Sequelize({
@@ -183,18 +191,22 @@ class SequelizeService extends _service.default {
183
191
  this.connections.set(queryId, conn);
184
192
  resolve(true);
185
193
  }).catch(reason => {
186
- this.log(`error trying to connect: ${dbQueryName}, UUID: ${uuid}`);
194
+ this.log(`error trying to connect: ${dbQueryName}, UUID: ${con_uuid}`);
187
195
  reject(reason);
188
- new _error.ApplicationException(`error trying to connect: ${dbQueryName}, UUID: ${uuid}`, reason);
196
+ new _error.ApplicationException(`error trying to connect: ${dbQueryName}, UUID: ${con_uuid}`, reason);
189
197
  });
190
198
  });
191
199
  }
192
200
  registerModels(models) {
193
201
  this.models = models;
194
202
  }
195
- async getModel(model, conn_uuid, envToken) {
196
- const connection = await this.getDB(conn_uuid, envToken);
197
- const query = `${envToken}@${conn_uuid}`;
203
+ async getModel(model, tenantId) {
204
+ const {
205
+ con_uuid,
206
+ envToken
207
+ } = this.parseDataInfoByTenantId(tenantId);
208
+ const connection = await this.getDB(tenantId);
209
+ const query = `${envToken}@${con_uuid}`;
198
210
  const cache = this.initializedModels.get(query);
199
211
  if (cache) {
200
212
  return cache;
@@ -206,5 +218,14 @@ class SequelizeService extends _service.default {
206
218
  }
207
219
  return null;
208
220
  }
221
+ parseDataInfoByTenantId(tenant) {
222
+ const e = tenant.split('@');
223
+ const envToken = e[0];
224
+ const con_uuid = e[1];
225
+ return {
226
+ envToken,
227
+ con_uuid
228
+ };
229
+ }
209
230
  }
210
231
  var _default = exports.default = SequelizeService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.66",
3
+ "version": "2.0.67",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",