@azteam/express 1.2.185 → 1.2.188

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.185",
3
+ "version": "1.2.188",
4
4
  "main": "src/index.js",
5
5
  "engines": {
6
6
  "node": ">= 12.0.0",
@@ -10,7 +10,7 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@azteam/crypto": "1.0.24",
13
- "@azteam/error": "1.0.19",
13
+ "@azteam/error": "1.0.20",
14
14
  "@azteam/http-client": "1.0.93",
15
15
  "@grpc/grpc-js": "1.6.7",
16
16
  "@grpc/proto-loader": "0.6.12",
@@ -1,7 +1,7 @@
1
1
  import {NOT_EXISTS} from '@azteam/error';
2
2
 
3
3
  import {REQUEST_TYPE} from './constant';
4
- import {rulesID} from './validate';
4
+ import {rulesId} from './validate';
5
5
  import Controller from './Controller';
6
6
  import {adminRoleMiddleware, paginateMiddleware, validateMiddleware, verifyGoogleAppMiddleware} from './middleware';
7
7
 
@@ -64,7 +64,7 @@ class AdminController extends Controller {
64
64
  return {
65
65
  disabled: !this.roles.READ,
66
66
  path: '/:id',
67
- method: [adminRoleMiddleware([this.roles.READ]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodGetOnePublic],
67
+ method: [adminRoleMiddleware([this.roles.READ]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesId), this.methodGetOnePublic],
68
68
  };
69
69
  }
70
70
 
@@ -78,7 +78,7 @@ class AdminController extends Controller {
78
78
  return {
79
79
  disabled: !this.roles.READ,
80
80
  path: '/:id',
81
- method: [adminRoleMiddleware([this.roles.READ]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodGetOneTrash],
81
+ method: [adminRoleMiddleware([this.roles.READ]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesId), this.methodGetOneTrash],
82
82
  };
83
83
  }
84
84
 
@@ -135,7 +135,7 @@ class AdminController extends Controller {
135
135
  path: '/:id',
136
136
  method: [
137
137
  adminRoleMiddleware([this.roles.UPDATE]),
138
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
138
+ validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
139
139
  validateMiddleware(REQUEST_TYPE.BODY, this.rulesModify),
140
140
  this.methodPutModifyPublic,
141
141
  ],
@@ -154,7 +154,7 @@ class AdminController extends Controller {
154
154
  return {
155
155
  disabled: !this.roles.DELETE,
156
156
  path: '/:id',
157
- method: [adminRoleMiddleware([this.roles.DELETE]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodDeletePublic],
157
+ method: [adminRoleMiddleware([this.roles.DELETE]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesId), this.methodDeletePublic],
158
158
  };
159
159
  }
160
160
 
@@ -170,7 +170,7 @@ class AdminController extends Controller {
170
170
  return {
171
171
  disabled: !this.roles.RESTORE,
172
172
  path: '/:id',
173
- method: [adminRoleMiddleware([this.roles.RESTORE]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodPostRestoreTrash],
173
+ method: [adminRoleMiddleware([this.roles.RESTORE]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesId), this.methodPostRestoreTrash],
174
174
  };
175
175
  }
176
176
 
@@ -186,7 +186,7 @@ class AdminController extends Controller {
186
186
  return {
187
187
  disabled: !this.roles.DESTROY,
188
188
  path: '/:id',
189
- method: [adminRoleMiddleware([this.roles.DESTROY]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesID), this.methodDeleteDestroyTrash],
189
+ method: [adminRoleMiddleware([this.roles.DESTROY]), validateMiddleware(REQUEST_TYPE.PARAMS, rulesId), this.methodDeleteDestroyTrash],
190
190
  };
191
191
  }
192
192
 
package/src/Server.js CHANGED
@@ -10,7 +10,7 @@ import morgan from 'morgan';
10
10
  import cors from 'cors';
11
11
  import _ from 'lodash';
12
12
  import 'express-async-errors';
13
- import {errorCatch, ErrorException, NOT_FOUND, UNKNOWN} from '@azteam/error';
13
+ import {errorCatch, ErrorException, NOT_FOUND, UNKNOWN, CORS} from '@azteam/error';
14
14
 
15
15
  const RES_TYPE = {
16
16
  ARRAY: 'ARRAY',
@@ -140,11 +140,11 @@ class Server {
140
140
  app.use(
141
141
  cors({
142
142
  credentials: true,
143
- origin: function (origin, callback) {
143
+ origin(origin, callback) {
144
144
  if (!origin || !WHITE_LIST.length || WHITE_LIST.some((re) => origin.endsWith(re))) {
145
145
  callback(null, true);
146
146
  } else {
147
- callback(new Error(`${origin} Not allowed by CORS`));
147
+ callback(new ErrorException(CORS, `${origin} Not allowed by CORS`));
148
148
  }
149
149
  },
150
150
  })
@@ -56,6 +56,7 @@ class SocketServer {
56
56
  const versionDirs = fs.readdirSync(`${apiDir}/${dirName}`);
57
57
 
58
58
  for (const versionName of versionDirs) {
59
+ // eslint-disable-next-line import/no-dynamic-require,global-require
59
60
  const controller = require(`${apiDir}/${dirName}/${versionName}/controller`).default;
60
61
  this.addController(dirName, versionName, controller);
61
62
  }
@@ -83,7 +84,7 @@ class SocketServer {
83
84
  },
84
85
  cors: {
85
86
  credentials: true,
86
- origin: function (origin, callback) {
87
+ origin(origin, callback) {
87
88
  if (!origin || !WHITE_LIST.length || WHITE_LIST.some((re) => origin.endsWith(re))) {
88
89
  callback(null, true);
89
90
  } else {
@@ -99,7 +100,7 @@ class SocketServer {
99
100
 
100
101
  const msg = [];
101
102
  _.map(this.controllers, (obj) => {
102
- const controller = obj.controller;
103
+ const {controller} = obj;
103
104
 
104
105
  _.map(controller, (item, key) => {
105
106
  item.path = obj.version.startsWith('v') ? `/${obj.version}${item.path}` : item.path;
@@ -145,7 +146,7 @@ class SocketServer {
145
146
  throw error;
146
147
  }
147
148
 
148
- let bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
149
+ let bind = typeof port === 'string' ? `Pipe ${port}` : `Port ${port}`;
149
150
 
150
151
  switch (error.code) {
151
152
  case 'EACCES':
@@ -164,10 +165,8 @@ class SocketServer {
164
165
  server.listen(port);
165
166
 
166
167
  return server;
167
- } else {
168
- throw Error('No controllers in use');
169
168
  }
170
- return null;
169
+ throw Error('No controllers in use');
171
170
  }
172
171
 
173
172
  setAlertCallback(callback) {
package/src/validate.js CHANGED
@@ -1,4 +1,4 @@
1
- export const schemaID = (optional = false) => ({
1
+ export const schemaId = (optional = false) => ({
2
2
  type: 'string',
3
3
  length: 24,
4
4
  pattern: /^[A-Fa-f0-9]{24}$/,
@@ -108,8 +108,8 @@ export const schemaObject = (props = {}, optional = false) => ({
108
108
 
109
109
  /* rules */
110
110
 
111
- export const rulesID = {
112
- id: schemaID(),
111
+ export const rulesId = {
112
+ id: schemaId(),
113
113
  };
114
114
  export const rulesSlug = {
115
115
  slug: schemaSlug(),