not-node 6.5.45 → 6.5.47
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/bin/not-builder.js
CHANGED
package/package.json
CHANGED
package/src/auth/exceptions.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
const { notError } = require("not-error");
|
|
2
2
|
|
|
3
|
+
class UserIdentityExceptionUserIdIsNotString extends notError {
|
|
4
|
+
constructor(typeofUserId) {
|
|
5
|
+
super("not-node:auth_user_identity_user_id_is_not_string", {
|
|
6
|
+
typeofUserId,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
module.exports.UserIdentityExceptionUserIdIsNotString =
|
|
11
|
+
UserIdentityExceptionUserIdIsNotString;
|
|
12
|
+
|
|
3
13
|
class RolesExceptionRoleSetIsNotValid extends notError {
|
|
4
14
|
constructor(name) {
|
|
5
15
|
super("not-node:auth_roles_role_set_is_not_valid", { name });
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const CONST = require("../../auth/const");
|
|
2
2
|
const ROLES = require("../../auth/roles");
|
|
3
|
+
const EXCEPTIONS = require("../../auth/exceptions");
|
|
3
4
|
|
|
4
5
|
module.exports = class IdentityProviderSession {
|
|
5
6
|
static #options = {};
|
|
6
7
|
|
|
7
8
|
static setOptions(options = {}) {
|
|
8
|
-
this.#options = {...this.#options, ...options};
|
|
9
|
+
this.#options = { ...this.#options, ...options };
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
static #getOptions() {
|
|
@@ -20,6 +21,15 @@ module.exports = class IdentityProviderSession {
|
|
|
20
21
|
IdentityProviderSession.#getOptions().secondaryRoles = [...list];
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
_idToString(_id) {
|
|
25
|
+
if (typeof _id === "string") {
|
|
26
|
+
return _id;
|
|
27
|
+
} else if (_id.toString && typeof _id.toString === "function") {
|
|
28
|
+
return _id.toString();
|
|
29
|
+
}
|
|
30
|
+
throw new EXCEPTIONS.UserIdentityExceptionUserIdIsNotString(typeof _id);
|
|
31
|
+
}
|
|
32
|
+
|
|
23
33
|
constructor(req) {
|
|
24
34
|
this.req = req;
|
|
25
35
|
return this;
|
|
@@ -93,7 +103,8 @@ module.exports = class IdentityProviderSession {
|
|
|
93
103
|
setUserId(_id) {
|
|
94
104
|
const req = this.req;
|
|
95
105
|
if (req && req.session) {
|
|
96
|
-
|
|
106
|
+
const stringId = this._idToString(_id);
|
|
107
|
+
req.session.user = stringId;
|
|
97
108
|
req.session.save();
|
|
98
109
|
}
|
|
99
110
|
}
|
package/src/init/lib/static.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = class InitStatic {
|
|
|
30
30
|
return (req, res, next) => {
|
|
31
31
|
try {
|
|
32
32
|
const frontApp = InitStatic.selectVersion(config, req, ext);
|
|
33
|
-
|
|
33
|
+
const pathTo = path.resolve(options.pathToApp, frontApp);
|
|
34
34
|
return InitStatic.serveStatic(pathTo)(req, res, next);
|
|
35
35
|
} catch (e) {
|
|
36
36
|
next(e);
|
|
@@ -41,7 +41,7 @@ module.exports = class InitStatic {
|
|
|
41
41
|
async run({ config, options, master, emit }) {
|
|
42
42
|
await emit("static.pre", { config, options, master });
|
|
43
43
|
master.getServer().use(
|
|
44
|
-
|
|
44
|
+
'/front/:"role".js',
|
|
45
45
|
InitStatic.createStaticFrontServer("js", {
|
|
46
46
|
config,
|
|
47
47
|
options,
|
|
@@ -49,7 +49,7 @@ module.exports = class InitStatic {
|
|
|
49
49
|
})
|
|
50
50
|
);
|
|
51
51
|
master.getServer().use(
|
|
52
|
-
|
|
52
|
+
'/front/:"role".css',
|
|
53
53
|
InitStatic.createStaticFrontServer("css", {
|
|
54
54
|
config,
|
|
55
55
|
options,
|
|
@@ -110,7 +110,7 @@ module.exports = ({ expect }) => {
|
|
|
110
110
|
};
|
|
111
111
|
const id = new mongoose.Types.ObjectId();
|
|
112
112
|
new Provider(t).setUserId(id);
|
|
113
|
-
expect(t.session.user).to.eql(id);
|
|
113
|
+
expect(t.session.user).to.eql(id.toString());
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
it("session not exist, set _id", function () {
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
"mongoose": {
|
|
15
15
|
"uri": "mongodb://<%- db.mongoose.hostname %>/<%- db.mongoose.db %>?authSource=<%- db.mongoose.authSource %>",
|
|
16
16
|
"options": {
|
|
17
|
-
"useNewUrlParser": true,
|
|
18
|
-
"useUnifiedTopology": true,
|
|
19
17
|
"db": "<%- db.mongoose.db %>",
|
|
20
18
|
"host": "<%- db.mongoose.hostname %>",
|
|
21
19
|
"autoIndex": false
|