@nocobase/server 0.9.4-alpha.2 → 0.10.0-alpha.2
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/application.d.ts +3 -0
- package/lib/application.js +23 -1
- package/lib/middlewares/data-template.js +22 -7
- package/package.json +9 -8
package/lib/application.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="koa-bodyparser" />
|
|
3
3
|
import { ACL } from '@nocobase/acl';
|
|
4
|
+
import { AuthManager } from '@nocobase/auth';
|
|
4
5
|
import { Cache, ICacheConfig } from '@nocobase/cache';
|
|
5
6
|
import Database, { Collection, CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
6
7
|
import { AppLoggerOptions, Logger } from '@nocobase/logger';
|
|
@@ -85,6 +86,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
85
86
|
protected _pm: PluginManager;
|
|
86
87
|
protected _acl: ACL;
|
|
87
88
|
protected _appManager: AppManager;
|
|
89
|
+
protected _authManager: AuthManager;
|
|
88
90
|
protected _version: ApplicationVersion;
|
|
89
91
|
protected plugins: Map<string, Plugin<any>>;
|
|
90
92
|
listenServer: Server;
|
|
@@ -100,6 +102,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
100
102
|
get pm(): PluginManager;
|
|
101
103
|
get version(): ApplicationVersion;
|
|
102
104
|
get appManager(): AppManager;
|
|
105
|
+
get authManager(): AuthManager;
|
|
103
106
|
get logger(): Logger;
|
|
104
107
|
get log(): Logger;
|
|
105
108
|
get name(): string;
|
package/lib/application.js
CHANGED
|
@@ -11,6 +11,13 @@ function _actions() {
|
|
|
11
11
|
};
|
|
12
12
|
return data;
|
|
13
13
|
}
|
|
14
|
+
function _auth() {
|
|
15
|
+
const data = require("@nocobase/auth");
|
|
16
|
+
_auth = function _auth() {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
14
21
|
function _cache() {
|
|
15
22
|
const data = require("@nocobase/cache");
|
|
16
23
|
_cache = function _cache() {
|
|
@@ -170,6 +177,7 @@ class Application extends _koa().default {
|
|
|
170
177
|
this._pm = void 0;
|
|
171
178
|
this._acl = void 0;
|
|
172
179
|
this._appManager = void 0;
|
|
180
|
+
this._authManager = void 0;
|
|
173
181
|
this._version = void 0;
|
|
174
182
|
this.plugins = new Map();
|
|
175
183
|
this.listenServer = void 0;
|
|
@@ -204,6 +212,9 @@ class Application extends _koa().default {
|
|
|
204
212
|
get appManager() {
|
|
205
213
|
return this._appManager;
|
|
206
214
|
}
|
|
215
|
+
get authManager() {
|
|
216
|
+
return this._authManager;
|
|
217
|
+
}
|
|
207
218
|
get logger() {
|
|
208
219
|
return this._logger;
|
|
209
220
|
}
|
|
@@ -254,10 +265,21 @@ class Application extends _koa().default {
|
|
|
254
265
|
} else {
|
|
255
266
|
this._appManager = new _appManager.AppManager(this);
|
|
256
267
|
}
|
|
268
|
+
this._authManager = new (_auth().AuthManager)({
|
|
269
|
+
authKey: 'X-Authenticator',
|
|
270
|
+
default: 'basic'
|
|
271
|
+
});
|
|
272
|
+
this.resource({
|
|
273
|
+
name: 'auth',
|
|
274
|
+
actions: _auth().actions
|
|
275
|
+
});
|
|
276
|
+
this._resourcer.use(this._authManager.middleware(), {
|
|
277
|
+
tag: 'auth'
|
|
278
|
+
});
|
|
257
279
|
if (this.options.acl !== false) {
|
|
258
280
|
this._resourcer.use(this._acl.middleware(), {
|
|
259
281
|
tag: 'acl',
|
|
260
|
-
after: ['
|
|
282
|
+
after: ['auth']
|
|
261
283
|
});
|
|
262
284
|
}
|
|
263
285
|
(0, _helper.registerMiddlewares)(this, options);
|
|
@@ -19,8 +19,7 @@ const dateTemplate = /*#__PURE__*/function () {
|
|
|
19
19
|
fields = _ctx$action$params.fields;
|
|
20
20
|
yield next();
|
|
21
21
|
if (isTemplate && actionName === 'get' && fields.length > 0) {
|
|
22
|
-
|
|
23
|
-
ctx.body = traverseJSON((_ctx$body = ctx.body) === null || _ctx$body === void 0 ? void 0 : _ctx$body.toJSON(), {
|
|
22
|
+
ctx.body = traverseJSON(JSON.parse(JSON.stringify(ctx.body)), {
|
|
24
23
|
collection: ctx.db.getCollection(resourceName),
|
|
25
24
|
include: fields
|
|
26
25
|
});
|
|
@@ -59,12 +58,15 @@ const traverseBelongsToMany = (arr, {
|
|
|
59
58
|
collection: throughCollection,
|
|
60
59
|
exclude
|
|
61
60
|
});
|
|
62
|
-
if (Object.keys(data).length) {
|
|
61
|
+
if (data && Object.keys(data).length) {
|
|
63
62
|
item[through] = data;
|
|
64
63
|
} else {
|
|
65
64
|
delete item[through];
|
|
66
65
|
}
|
|
67
|
-
return item
|
|
66
|
+
return traverseJSON(item, {
|
|
67
|
+
collection,
|
|
68
|
+
excludePk: false
|
|
69
|
+
});
|
|
68
70
|
});
|
|
69
71
|
};
|
|
70
72
|
const parseInclude = keys => {
|
|
@@ -89,11 +91,16 @@ const parseInclude = keys => {
|
|
|
89
91
|
return map;
|
|
90
92
|
};
|
|
91
93
|
const traverseJSON = (data, options) => {
|
|
94
|
+
if (!data) {
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
92
97
|
const collection = options.collection,
|
|
93
98
|
_options$exclude = options.exclude,
|
|
94
99
|
exclude = _options$exclude === void 0 ? [] : _options$exclude,
|
|
95
100
|
_options$include = options.include,
|
|
96
|
-
include = _options$include === void 0 ? [] : _options$include
|
|
101
|
+
include = _options$include === void 0 ? [] : _options$include,
|
|
102
|
+
_options$excludePk = options.excludePk,
|
|
103
|
+
excludePk = _options$excludePk === void 0 ? true : _options$excludePk;
|
|
97
104
|
const map = parseInclude(include);
|
|
98
105
|
const result = {};
|
|
99
106
|
for (var _i = 0, _Object$keys = Object.keys(data || {}); _i < _Object$keys.length; _i++) {
|
|
@@ -113,7 +120,10 @@ const traverseJSON = (data, options) => {
|
|
|
113
120
|
result[key] = data[key];
|
|
114
121
|
continue;
|
|
115
122
|
}
|
|
116
|
-
if (field.options.primaryKey) {
|
|
123
|
+
if (field.options.primaryKey && excludePk) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (field.options.isForeignKey) {
|
|
117
127
|
continue;
|
|
118
128
|
}
|
|
119
129
|
if (['sort', 'password', 'sequence'].includes(field.type)) {
|
|
@@ -132,7 +142,12 @@ const traverseJSON = (data, options) => {
|
|
|
132
142
|
include: subInclude
|
|
133
143
|
});
|
|
134
144
|
} else if (field.type === 'belongsTo') {
|
|
135
|
-
result[key] = data[key]
|
|
145
|
+
result[key] = traverseJSON(data[key], {
|
|
146
|
+
collection: collection.db.getCollection(field.target),
|
|
147
|
+
// exclude: [field.foreignKey],
|
|
148
|
+
include: subInclude,
|
|
149
|
+
excludePk: false
|
|
150
|
+
});
|
|
136
151
|
} else if (field.type === 'belongsToMany') {
|
|
137
152
|
result[key] = traverseBelongsToMany(data[key], {
|
|
138
153
|
collection: collection.db.getCollection(field.target),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-alpha.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
"@hapi/topo": "^6.0.0",
|
|
9
9
|
"@koa/cors": "^3.1.0",
|
|
10
10
|
"@koa/router": "^9.4.0",
|
|
11
|
-
"@nocobase/acl": "0.
|
|
12
|
-
"@nocobase/actions": "0.
|
|
13
|
-
"@nocobase/
|
|
14
|
-
"@nocobase/
|
|
15
|
-
"@nocobase/
|
|
16
|
-
"@nocobase/
|
|
11
|
+
"@nocobase/acl": "0.10.0-alpha.2",
|
|
12
|
+
"@nocobase/actions": "0.10.0-alpha.2",
|
|
13
|
+
"@nocobase/auth": "0.10.0-alpha.2",
|
|
14
|
+
"@nocobase/database": "0.10.0-alpha.2",
|
|
15
|
+
"@nocobase/logger": "0.10.0-alpha.2",
|
|
16
|
+
"@nocobase/resourcer": "0.10.0-alpha.2",
|
|
17
|
+
"@nocobase/utils": "0.10.0-alpha.2",
|
|
17
18
|
"chalk": "^4.1.1",
|
|
18
19
|
"commander": "^9.2.0",
|
|
19
20
|
"find-package-json": "^1.2.0",
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/semver": "^7.3.9"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "85028ae1733fcbd46ecd5d291dacbdc175f7f073"
|
|
33
34
|
}
|