@adaptivestone/framework 3.0.0 → 3.0.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 3.0.4
2
+
3
+ [UPDATE] fix bug with app shutdown
4
+
5
+ ### 3.0.3
6
+
7
+ [UPDATE] update deps
8
+
9
+ ### 3.0.2
10
+
11
+ [UPDATE] update deps
12
+
13
+ ### 3.0.1
14
+
15
+ [UPDATE] update deps
16
+ [UPDATE] getUserByTokens more logs
17
+
1
18
  ### 3.0.0
2
19
 
3
20
  [BREAKING] Mongoose v6. Than a lot of changes:[mongoDB drive changes](https://github.com/mongodb/node-mongodb-native/blob/4.0/docs/CHANGES_4.0.0.md), [Mongoose changes](https://mongoosejs.com/docs/migrating_to_6.html).
package/Cli.js CHANGED
@@ -12,7 +12,7 @@ class Cli extends BaseCli {
12
12
  async run() {
13
13
  const command = process.argv[2]?.toLowerCase();
14
14
  await super.run(command, this.args);
15
- this.app.events.emit('die');
15
+ this.app.events.emit('shutdown');
16
16
  }
17
17
  }
18
18
 
@@ -205,10 +205,12 @@ class AbstractController extends Base {
205
205
  } catch (e) {
206
206
  let { errors } = e;
207
207
  // translate it
208
- if (req.i18n) {
209
- errors = e.errors.map((err) => req.i18n.t(err));
208
+ if (req.i18n && errors) {
209
+ errors = errors.map((err) => req.i18n.t(err));
210
210
  }
211
- this.logger.error(`Request validation failed: ${errors}`);
211
+ this.logger.error(
212
+ `Request validation failed with message: ${e.message}. errors: ${errors}`,
213
+ );
212
214
 
213
215
  return res.status(400).json({
214
216
  errors: {
@@ -23,7 +23,7 @@ class AbstractModel extends Base {
23
23
  mongoose.connect(this.app.getConfig('mongo').connectionString, {}).then(
24
24
  () => {
25
25
  this.logger.info('Mongo connection success');
26
- this.app.events.on('die', async () => {
26
+ this.app.events.on('shutdown', async () => {
27
27
  for (const c of mongoose.connections) {
28
28
  c.close(true);
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "3.0.0",
3
+ "version": "3.0.4",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -28,7 +28,7 @@
28
28
  "bcrypt": "^5.0.1",
29
29
  "cors": "^2.8.5",
30
30
  "deepmerge": "^4.2.2",
31
- "dotenv": "^10.0.0",
31
+ "dotenv": "^14.0.0",
32
32
  "email-templates": "^8.0.7",
33
33
  "express": "^4.17.1",
34
34
  "i18next": "^21.2.4",
@@ -53,7 +53,7 @@
53
53
  "eslint-config-airbnb-base": "^15.0.0",
54
54
  "eslint-config-prettier": "^8.3.0",
55
55
  "eslint-plugin-import": "^2.23.4",
56
- "eslint-plugin-jest": "^25.0.0",
56
+ "eslint-plugin-jest": "^26.0.0",
57
57
  "husky": "^7.0.0",
58
58
  "jest": "^27.0.6",
59
59
  "lint-staged": "^12.0.0",
@@ -17,6 +17,9 @@ class Cache extends Base {
17
17
  this.redisClient.on('connect', () => {
18
18
  this.logger.info('Redis connection success');
19
19
  });
20
+ this.app.events.on('shutdown', () => {
21
+ this.redisClient.quit();
22
+ });
20
23
  this.redisGetAsync = promisify(this.redisClient.get).bind(this.redisClient);
21
24
  this.promiseMapping = new Map();
22
25
  }
@@ -168,7 +168,7 @@ class HttpServer extends Base {
168
168
  /**
169
169
  * Stop http server (mostly for unit testing)
170
170
  */
171
- die() {
171
+ shutdown() {
172
172
  this.httpServer.close();
173
173
  }
174
174
  }
@@ -7,6 +7,11 @@ class GetUserByToken extends AbstractMiddleware {
7
7
 
8
8
  async middleware(req, res, next) {
9
9
  let { token } = req.body;
10
+ this.logger.verbose(
11
+ `GetUserByToken token in BODY ${token}. Token if Authorization header ${req.get(
12
+ 'Authorization',
13
+ )}`,
14
+ );
10
15
  if (!token) {
11
16
  token = req.get('Authorization');
12
17
  if (!token || token === 'null') {
@@ -55,6 +55,10 @@ class RateLimiter extends AbstractMiddleware {
55
55
  this.logger.info('Redis connection success');
56
56
  });
57
57
 
58
+ this.app.events.on('shutdown', () => {
59
+ redisClient.quit();
60
+ });
61
+
58
62
  return new RateLimiterRedis({
59
63
  storeClient: redisClient,
60
64
  ...this.finalOptions.limiterOptions,
package/tests/setup.js CHANGED
@@ -64,7 +64,8 @@ beforeAll(async () => {
64
64
  });
65
65
  afterAll(async () => {
66
66
  if (global.server) {
67
- global.server.app.httpServer.die();
67
+ global.server.app.httpServer.shutdown();
68
+ global.server.app.events.emit('shutdown');
68
69
  }
69
70
  setTimeout(async () => {
70
71
  if (typeof global.testSetup.afterAll === 'function') {