@azteam/express 1.2.283 → 1.2.285
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/lib/AdminController.js +1 -1
- package/lib/Server.js +14 -33
- package/package.json +1 -1
- package/src/AdminController.js +12 -1
- package/src/Server.js +22 -30
package/lib/AdminController.js
CHANGED
|
@@ -34,7 +34,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
|
|
|
34
34
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
35
35
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
36
36
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
37
|
-
var ALLOW_FIELDS = ['created_id', 'modified_id', '
|
|
37
|
+
var ALLOW_FIELDS = ['created_at', 'created_id', 'modified_at', 'modified_id', 'deleted_at', 'deleted_id', 'restored_id', 'resource', 'priority', 'is_processing'];
|
|
38
38
|
var AdminController = /*#__PURE__*/function (_Controller) {
|
|
39
39
|
_inherits(AdminController, _Controller);
|
|
40
40
|
var _super = _createSuper(AdminController);
|
package/lib/Server.js
CHANGED
|
@@ -62,55 +62,36 @@ var Server = /*#__PURE__*/function () {
|
|
|
62
62
|
var currentDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
63
63
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
64
64
|
_classCallCheck(this, Server);
|
|
65
|
-
this.redis = null;
|
|
66
65
|
this.options = _objectSpread({
|
|
67
|
-
|
|
66
|
+
redis: null,
|
|
67
|
+
isAllowEmptyOrigin: true,
|
|
68
|
+
whiteList: [],
|
|
69
|
+
cookieOption: {},
|
|
70
|
+
debug: process.env.NODE_ENV === 'development'
|
|
68
71
|
}, options);
|
|
69
|
-
this.
|
|
72
|
+
this.redis = this.options.redis;
|
|
73
|
+
this.isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
|
|
74
|
+
this.whiteList = this.options.whiteList;
|
|
75
|
+
this.debug = this.options.debug;
|
|
76
|
+
this.cookieOption = _objectSpread({
|
|
70
77
|
domain: null,
|
|
71
78
|
path: '/',
|
|
72
79
|
secure: process.env.NODE_ENV !== 'development',
|
|
73
80
|
httpOnly: true,
|
|
74
81
|
signed: true,
|
|
75
82
|
sameSite: 'Lax'
|
|
76
|
-
};
|
|
83
|
+
}, this.options.cookieOption);
|
|
77
84
|
this.middlewares = [];
|
|
78
85
|
this.controllers = [];
|
|
79
|
-
this.whiteList = [];
|
|
80
|
-
this.debug = process.env.NODE_ENV === 'development';
|
|
81
86
|
this.initController(currentDir);
|
|
82
87
|
}
|
|
83
88
|
_createClass(Server, [{
|
|
84
|
-
key: "setRedis",
|
|
85
|
-
value: function setRedis(redis) {
|
|
86
|
-
this.redis = redis;
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
}, {
|
|
90
|
-
key: "setCookieOption",
|
|
91
|
-
value: function setCookieOption(cookieOption) {
|
|
92
|
-
this.cookieOption = _objectSpread(_objectSpread({}, this.cookieOption), cookieOption);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
}, {
|
|
96
89
|
key: "setCallbackError",
|
|
97
90
|
value: function setCallbackError() {
|
|
98
91
|
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
99
92
|
this.callbackError = callback;
|
|
100
93
|
return this;
|
|
101
94
|
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "setWhiteList",
|
|
104
|
-
value: function setWhiteList(whiteList) {
|
|
105
|
-
this.whiteList = whiteList;
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
}, {
|
|
109
|
-
key: "setDebug",
|
|
110
|
-
value: function setDebug(debug) {
|
|
111
|
-
this.debug = debug;
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
95
|
}, {
|
|
115
96
|
key: "addController",
|
|
116
97
|
value: function addController(name, version, controller) {
|
|
@@ -155,7 +136,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
155
136
|
if (!_lodash["default"].isEmpty(this.controllers)) {
|
|
156
137
|
var WHITE_LIST = this.whiteList;
|
|
157
138
|
var COOKIE_OPTION = this.cookieOption;
|
|
158
|
-
var
|
|
139
|
+
var IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
|
|
159
140
|
var app = (0, _express["default"])();
|
|
160
141
|
app.use((0, _helmet["default"])({
|
|
161
142
|
frameguard: false
|
|
@@ -178,7 +159,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
178
159
|
var error = null;
|
|
179
160
|
if (!authorization && !appSecret && !agent.startsWith('toda')) {
|
|
180
161
|
if (!origin) {
|
|
181
|
-
if (!
|
|
162
|
+
if (!IS_ALLOW_EMPTY) {
|
|
182
163
|
error = new _error.ErrorException(_error.CORS, "Not allowed by CORS");
|
|
183
164
|
}
|
|
184
165
|
} else if (!WHITE_LIST.some(function (re) {
|
|
@@ -229,7 +210,7 @@ var Server = /*#__PURE__*/function () {
|
|
|
229
210
|
var responseGuard = guard;
|
|
230
211
|
var responseAllows = allow;
|
|
231
212
|
if (_lodash["default"].isArray(guard)) {
|
|
232
|
-
responseGuard = [].concat(_toConsumableArray(guard), ['__v', '_id', '
|
|
213
|
+
responseGuard = [].concat(_toConsumableArray(guard), ['__v', '_id', 'created_at', 'created_id', 'modified_at', 'modified_id', 'deleted_at', 'deleted_id', 'restored_id', 'resource', 'is_processing', 'priority']);
|
|
233
214
|
}
|
|
234
215
|
if (resType === RES_TYPE.DOCS) {
|
|
235
216
|
guardData.docs = _lodash["default"].map(data.docs, function (item) {
|
package/package.json
CHANGED
package/src/AdminController.js
CHANGED
|
@@ -6,7 +6,18 @@ import {rulesId, schemaBoolean, schemaEnum, schemaNumber} from './validate';
|
|
|
6
6
|
import {adminRoleMiddleware, paginateMiddleware, validateMiddleware} from './middleware';
|
|
7
7
|
import Controller from './Controller';
|
|
8
8
|
|
|
9
|
-
const ALLOW_FIELDS = [
|
|
9
|
+
const ALLOW_FIELDS = [
|
|
10
|
+
'created_at',
|
|
11
|
+
'created_id',
|
|
12
|
+
'modified_at',
|
|
13
|
+
'modified_id',
|
|
14
|
+
'deleted_at',
|
|
15
|
+
'deleted_id',
|
|
16
|
+
'restored_id',
|
|
17
|
+
'resource',
|
|
18
|
+
'priority',
|
|
19
|
+
'is_processing',
|
|
20
|
+
];
|
|
10
21
|
|
|
11
22
|
class AdminController extends Controller {
|
|
12
23
|
constructor(pathName, repository, options = {}) {
|
package/src/Server.js
CHANGED
|
@@ -41,12 +41,20 @@ function omitItem(item, guard, allow) {
|
|
|
41
41
|
|
|
42
42
|
class Server {
|
|
43
43
|
constructor(currentDir = '', options = {}) {
|
|
44
|
-
this.redis = null;
|
|
45
44
|
this.options = {
|
|
45
|
+
redis: null,
|
|
46
46
|
isAllowEmptyOrigin: true,
|
|
47
|
+
whiteList: [],
|
|
48
|
+
cookieOption: {},
|
|
49
|
+
debug: process.env.NODE_ENV === 'development',
|
|
47
50
|
...options,
|
|
48
51
|
};
|
|
49
52
|
|
|
53
|
+
this.redis = this.options.redis;
|
|
54
|
+
this.isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
|
|
55
|
+
this.whiteList = this.options.whiteList;
|
|
56
|
+
this.debug = this.options.debug;
|
|
57
|
+
|
|
50
58
|
this.cookieOption = {
|
|
51
59
|
domain: null,
|
|
52
60
|
path: '/',
|
|
@@ -54,44 +62,20 @@ class Server {
|
|
|
54
62
|
httpOnly: true,
|
|
55
63
|
signed: true,
|
|
56
64
|
sameSite: 'Lax',
|
|
65
|
+
...this.options.cookieOption,
|
|
57
66
|
};
|
|
58
67
|
|
|
59
68
|
this.middlewares = [];
|
|
60
69
|
this.controllers = [];
|
|
61
|
-
this.whiteList = [];
|
|
62
|
-
this.debug = process.env.NODE_ENV === 'development';
|
|
63
70
|
|
|
64
71
|
this.initController(currentDir);
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
setRedis(redis) {
|
|
68
|
-
this.redis = redis;
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
setCookieOption(cookieOption) {
|
|
73
|
-
this.cookieOption = {
|
|
74
|
-
...this.cookieOption,
|
|
75
|
-
...cookieOption,
|
|
76
|
-
};
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
setCallbackError(callback = null) {
|
|
81
75
|
this.callbackError = callback;
|
|
82
76
|
return this;
|
|
83
77
|
}
|
|
84
78
|
|
|
85
|
-
setWhiteList(whiteList) {
|
|
86
|
-
this.whiteList = whiteList;
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
setDebug(debug) {
|
|
91
|
-
this.debug = debug;
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
79
|
addController(name, version, controller) {
|
|
96
80
|
this.controllers.push({
|
|
97
81
|
name,
|
|
@@ -132,7 +116,7 @@ class Server {
|
|
|
132
116
|
if (!_.isEmpty(this.controllers)) {
|
|
133
117
|
const WHITE_LIST = this.whiteList;
|
|
134
118
|
const COOKIE_OPTION = this.cookieOption;
|
|
135
|
-
const
|
|
119
|
+
const IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
|
|
136
120
|
|
|
137
121
|
const app = express();
|
|
138
122
|
app.use(
|
|
@@ -159,7 +143,7 @@ class Server {
|
|
|
159
143
|
let error = null;
|
|
160
144
|
if (!authorization && !appSecret && !agent.startsWith('toda')) {
|
|
161
145
|
if (!origin) {
|
|
162
|
-
if (!
|
|
146
|
+
if (!IS_ALLOW_EMPTY) {
|
|
163
147
|
error = new ErrorException(CORS, `Not allowed by CORS`);
|
|
164
148
|
}
|
|
165
149
|
} else if (!WHITE_LIST.some((re) => origin.endsWith(re))) {
|
|
@@ -214,10 +198,18 @@ class Server {
|
|
|
214
198
|
...guard,
|
|
215
199
|
'__v',
|
|
216
200
|
'_id',
|
|
217
|
-
|
|
218
|
-
'
|
|
201
|
+
|
|
202
|
+
'created_at',
|
|
219
203
|
'created_id',
|
|
204
|
+
|
|
205
|
+
'modified_at',
|
|
220
206
|
'modified_id',
|
|
207
|
+
|
|
208
|
+
'deleted_at',
|
|
209
|
+
'deleted_id',
|
|
210
|
+
|
|
211
|
+
'restored_id',
|
|
212
|
+
|
|
221
213
|
'resource',
|
|
222
214
|
'is_processing',
|
|
223
215
|
'priority',
|