@grandlinex/kernel 0.26.0 → 0.27.0
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/dist/Kernel.js +20 -49
- package/dist/KernelModule.js +18 -72
- package/dist/actions/ApiAuthTestAction.js +11 -59
- package/dist/actions/ApiVersionAction.js +13 -61
- package/dist/actions/GetTokenAction.js +33 -89
- package/dist/actions/index.js +3 -3
- package/dist/api/KernelEndpoint.js +3 -23
- package/dist/api/index.js +1 -1
- package/dist/classes/BaseAction.js +45 -106
- package/dist/classes/BaseApiAction.js +14 -32
- package/dist/classes/BaseAuthProvider.js +2 -5
- package/dist/classes/BaseEndpoint.js +29 -49
- package/dist/classes/BaseKernelModule.js +3 -23
- package/dist/classes/index.js +6 -6
- package/dist/classes/timing/ExpressServerTiming.js +29 -61
- package/dist/classes/timing/ServerTiming.js +16 -52
- package/dist/classes/timing/ServerTimingElement.js +7 -8
- package/dist/classes/timing/index.js +3 -3
- package/dist/index.js +2 -2
- package/dist/modules/crypto/CryptoClient.js +60 -119
- package/dist/modules/crypto/index.js +1 -1
- package/dist/modules/crypto/utils/cors.js +1 -1
- package/package.json +2 -2
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ServerTiming = exports.ServerTimingElement = exports.ExpressServerTiming = void 0;
|
|
7
|
-
|
|
7
|
+
const ExpressServerTiming_1 = __importDefault(require("./ExpressServerTiming"));
|
|
8
8
|
exports.ExpressServerTiming = ExpressServerTiming_1.default;
|
|
9
|
-
|
|
9
|
+
const ServerTiming_1 = __importDefault(require("./ServerTiming"));
|
|
10
10
|
exports.ServerTiming = ServerTiming_1.default;
|
|
11
|
-
|
|
11
|
+
const ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
|
|
12
12
|
exports.ServerTimingElement = ServerTimingElement_1.default;
|
package/dist/index.js
CHANGED
|
@@ -22,9 +22,9 @@ exports.Kernel = exports.KernelModule = void 0;
|
|
|
22
22
|
* @name Kernel Main Module
|
|
23
23
|
* @author David Nagy
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
const Kernel_1 = __importDefault(require("./Kernel"));
|
|
26
26
|
exports.Kernel = Kernel_1.default;
|
|
27
|
-
|
|
27
|
+
const KernelModule_1 = __importDefault(require("./KernelModule"));
|
|
28
28
|
exports.KernelModule = KernelModule_1.default;
|
|
29
29
|
__exportStar(require("./actions"), exports);
|
|
30
30
|
__exportStar(require("./api"), exports);
|
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23,59 +8,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
9
|
});
|
|
25
10
|
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
13
|
};
|
|
56
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_this.expiresIn = kernel.getConfigStore().get('JWT_EXPIRE') || '1 days';
|
|
66
|
-
return _this;
|
|
15
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
16
|
+
const core_1 = require("@grandlinex/core");
|
|
17
|
+
class CryptoClient extends core_1.CoreCryptoClient {
|
|
18
|
+
constructor(key, kernel) {
|
|
19
|
+
super(kernel, key);
|
|
20
|
+
this.kernel = kernel;
|
|
21
|
+
this.authProvider = null;
|
|
22
|
+
this.expiresIn = kernel.getConfigStore().get('JWT_EXPIRE') || '1 days';
|
|
67
23
|
}
|
|
68
|
-
|
|
24
|
+
setAuthProvider(provider) {
|
|
69
25
|
if (this.authProvider) {
|
|
70
26
|
return false;
|
|
71
27
|
}
|
|
72
28
|
this.authProvider = provider;
|
|
73
29
|
return true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
jsonwebtoken_1.default.verify(token, _this.AesKey, function (err, user) {
|
|
30
|
+
}
|
|
31
|
+
jwtVerifyAccessToken(token) {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
jsonwebtoken_1.default.verify(token, this.AesKey, (err, user) => {
|
|
79
34
|
if (err || user === null) {
|
|
80
35
|
resolve(null);
|
|
81
36
|
}
|
|
@@ -84,69 +39,55 @@ var CryptoClient = /** @class */ (function (_super) {
|
|
|
84
39
|
}
|
|
85
40
|
});
|
|
86
41
|
});
|
|
87
|
-
}
|
|
88
|
-
|
|
42
|
+
}
|
|
43
|
+
jwtGenerateAccessToken(data) {
|
|
89
44
|
return jsonwebtoken_1.default.sign(data, this.AesKey, { expiresIn: this.expiresIn });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
userId: null,
|
|
111
|
-
}];
|
|
112
|
-
});
|
|
45
|
+
}
|
|
46
|
+
apiTokenValidation(username, token, requestType) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
if (this.authProvider) {
|
|
49
|
+
return this.authProvider.authorizeToken(username, token, requestType);
|
|
50
|
+
}
|
|
51
|
+
const store = this.kernel.getConfigStore();
|
|
52
|
+
if (!store.has('SERVER_PASSWORD')) {
|
|
53
|
+
return { valid: false, userId: null };
|
|
54
|
+
}
|
|
55
|
+
if (token === store.get('SERVER_PASSWORD') && username === 'admin') {
|
|
56
|
+
return {
|
|
57
|
+
valid: true,
|
|
58
|
+
userId: 'admin',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
valid: false,
|
|
63
|
+
userId: null,
|
|
64
|
+
};
|
|
113
65
|
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return [2 /*return*/, false];
|
|
122
|
-
});
|
|
66
|
+
}
|
|
67
|
+
permissionValidation(token, requestType) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (this.authProvider) {
|
|
70
|
+
return this.authProvider.validateAccess(token, requestType);
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
123
73
|
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
case 1:
|
|
141
|
-
tokenData = _a.sent();
|
|
142
|
-
if (tokenData) {
|
|
143
|
-
return [2 /*return*/, tokenData];
|
|
144
|
-
}
|
|
145
|
-
return [2 /*return*/, null];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
74
|
+
}
|
|
75
|
+
bearerTokenValidation(req) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
if (this.authProvider) {
|
|
78
|
+
return this.authProvider.bearerTokenValidation(req);
|
|
79
|
+
}
|
|
80
|
+
const authHeader = req.headers.authorization;
|
|
81
|
+
const token = authHeader && authHeader.split(' ')[1];
|
|
82
|
+
if (token == null) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const tokenData = yield this.jwtVerifyAccessToken(token);
|
|
86
|
+
if (tokenData) {
|
|
87
|
+
return tokenData;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
148
90
|
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}(core_1.CoreCryptoClient));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
152
93
|
exports.default = CryptoClient;
|
|
@@ -18,6 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.CryptoClient = void 0;
|
|
21
|
-
|
|
21
|
+
const CryptoClient_1 = __importDefault(require("./CryptoClient"));
|
|
22
22
|
exports.CryptoClient = CryptoClient_1.default;
|
|
23
23
|
__exportStar(require("./utils/cors"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cors = void 0;
|
|
4
|
-
|
|
4
|
+
const cors = (req, res, next) => {
|
|
5
5
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
6
6
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
7
7
|
res.setHeader('Access-Control-Allow-Methods', '*');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "GrandLineX is an out-of-the-box server framework on top of ExpressJs.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "BSD-3-Clause",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@grandlinex/core": "^0.
|
|
30
|
+
"@grandlinex/core": "^0.27.0",
|
|
31
31
|
"axios": "^0.27.2",
|
|
32
32
|
"body-parser": "^1.20.1",
|
|
33
33
|
"express": "^4.18.2",
|