@grandlinex/kernel 0.26.0 → 0.27.1
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/CHANGELOG.md +5 -0
- package/dist/Kernel.d.ts +2 -2
- package/dist/Kernel.js +20 -49
- package/dist/KernelModule.js +18 -72
- package/dist/actions/ApiAuthTestAction.d.ts +2 -2
- package/dist/actions/ApiAuthTestAction.js +11 -59
- package/dist/actions/ApiVersionAction.d.ts +2 -2
- package/dist/actions/ApiVersionAction.js +13 -61
- package/dist/actions/GetTokenAction.d.ts +2 -2
- 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.d.ts +3 -3
- package/dist/classes/BaseAction.js +45 -106
- package/dist/classes/BaseApiAction.js +14 -32
- package/dist/classes/BaseAuthProvider.d.ts +3 -3
- package/dist/classes/BaseAuthProvider.js +2 -5
- package/dist/classes/BaseEndpoint.d.ts +6 -3
- package/dist/classes/BaseEndpoint.js +41 -49
- package/dist/classes/BaseKernelModule.js +3 -23
- package/dist/classes/index.d.ts +2 -2
- package/dist/classes/index.js +20 -7
- package/dist/classes/timing/ExpressServerTiming.d.ts +3 -3
- 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.d.ts +1 -0
- package/dist/index.js +3 -2
- package/dist/lib/express.d.ts +6 -0
- package/dist/lib/express.js +2 -0
- package/dist/lib/index.d.ts +5 -4
- package/dist/modules/crypto/CryptoClient.d.ts +2 -2
- package/dist/modules/crypto/CryptoClient.js +60 -119
- package/dist/modules/crypto/index.js +1 -1
- package/dist/modules/crypto/utils/cors.d.ts +2 -2
- package/dist/modules/crypto/utils/cors.js +1 -1
- package/package.json +6 -6
|
@@ -8,90 +8,58 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
15
|
+
const ServerTiming_1 = __importDefault(require("./ServerTiming"));
|
|
16
|
+
class ExpressServerTiming {
|
|
17
|
+
constructor(baseApiAction) {
|
|
45
18
|
this.timing = new ServerTiming_1.default();
|
|
46
19
|
this.baseApiAction = baseApiAction;
|
|
47
20
|
}
|
|
48
|
-
|
|
21
|
+
start(chanel) {
|
|
49
22
|
return this.timing.start(chanel);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
return
|
|
54
|
-
return [2 /*return*/, this.timing.startFunc(chanel, fc)];
|
|
55
|
-
});
|
|
23
|
+
}
|
|
24
|
+
startFunc(chanel, fc) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return this.timing.startFunc(chanel, fc);
|
|
56
27
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
return
|
|
61
|
-
return [2 /*return*/, this.timing.startFunc('db', fc)];
|
|
62
|
-
});
|
|
28
|
+
}
|
|
29
|
+
dbQuery(fc) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return this.timing.startFunc('db', fc);
|
|
63
32
|
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.timing.map.forEach(
|
|
68
|
-
|
|
69
|
-
element.forEach(
|
|
33
|
+
}
|
|
34
|
+
getHeader() {
|
|
35
|
+
const out = [];
|
|
36
|
+
this.timing.map.forEach((element, key) => {
|
|
37
|
+
let dur = 0;
|
|
38
|
+
element.forEach((el) => {
|
|
70
39
|
dur += el.getDuration();
|
|
71
40
|
});
|
|
72
|
-
out.push(
|
|
41
|
+
out.push(`${key};dur=${dur}`);
|
|
73
42
|
});
|
|
74
43
|
return out.join(', ');
|
|
75
|
-
}
|
|
76
|
-
|
|
44
|
+
}
|
|
45
|
+
addHeader(res) {
|
|
77
46
|
if (this.timing.map.size > 0 &&
|
|
78
47
|
this.baseApiAction.getKernel().getDevMode()) {
|
|
79
|
-
|
|
48
|
+
const a = ['Server-Timing', this.getHeader()];
|
|
80
49
|
res.setHeader(a[0], a[1]);
|
|
81
50
|
this.baseApiAction.debug(a);
|
|
82
51
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
}
|
|
53
|
+
static init(baseApiAction, res) {
|
|
54
|
+
const el = new ExpressServerTiming(baseApiAction);
|
|
55
|
+
const total = el.start('total');
|
|
87
56
|
return [
|
|
88
57
|
el,
|
|
89
|
-
|
|
58
|
+
() => {
|
|
90
59
|
total.stop();
|
|
91
60
|
el.addHeader(res);
|
|
92
61
|
},
|
|
93
62
|
];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
97
65
|
exports.default = ExpressServerTiming;
|
|
@@ -8,66 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
15
|
+
const ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
|
|
16
|
+
class ServerTiming {
|
|
17
|
+
constructor() {
|
|
45
18
|
this.map = new Map();
|
|
46
19
|
}
|
|
47
|
-
|
|
20
|
+
start(chanel) {
|
|
48
21
|
return new ServerTimingElement_1.default(this, chanel);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
el = new ServerTimingElement_1.default(this, chanel);
|
|
57
|
-
return [4 /*yield*/, fc()];
|
|
58
|
-
case 1:
|
|
59
|
-
content = _a.sent();
|
|
60
|
-
el.stop();
|
|
61
|
-
return [2 /*return*/, content];
|
|
62
|
-
}
|
|
63
|
-
});
|
|
22
|
+
}
|
|
23
|
+
startFunc(chanel, fc) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const el = new ServerTimingElement_1.default(this, chanel);
|
|
26
|
+
const content = yield fc();
|
|
27
|
+
el.stop();
|
|
28
|
+
return content;
|
|
64
29
|
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
30
|
+
}
|
|
31
|
+
completeElement(e) {
|
|
32
|
+
const cur = this.map.get(e.chanel) || [];
|
|
68
33
|
cur.push(e);
|
|
69
34
|
this.map.set(e.chanel, cur);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
73
37
|
exports.default = ServerTiming;
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
class ServerTimingElement {
|
|
4
|
+
constructor(el, chanel) {
|
|
5
5
|
this.el = el;
|
|
6
6
|
this.chanel = chanel;
|
|
7
7
|
this.start = new Date().getTime();
|
|
8
8
|
this.end = -1;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
stop() {
|
|
11
11
|
if (this.end === -1) {
|
|
12
12
|
this.end = new Date().getTime();
|
|
13
13
|
this.el.completeElement(this);
|
|
14
14
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
}
|
|
16
|
+
getDuration() {
|
|
17
17
|
if (this.end === -1) {
|
|
18
18
|
return 0;
|
|
19
19
|
}
|
|
20
20
|
return this.end - this.start;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
24
23
|
exports.default = ServerTimingElement;
|
|
@@ -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.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,14 +22,15 @@ 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);
|
|
31
31
|
__exportStar(require("./classes"), exports);
|
|
32
32
|
__exportStar(require("./modules/crypto"), exports);
|
|
33
33
|
__exportStar(require("./lib"), exports);
|
|
34
|
+
__exportStar(require("./lib/express"), exports);
|
|
34
35
|
__exportStar(require("@grandlinex/core"), exports);
|
|
35
36
|
exports.default = Kernel_1.default;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import express, { Request, Response } from 'express';
|
|
2
1
|
import { ICoreAction, ICoreBridge, ICoreCache, ICoreCClient, ICoreClient, ICoreElement, ICoreKernel, ICoreKernelModule, ICorePresenter, ICoreService, IDataBase } from '@grandlinex/core';
|
|
2
|
+
import express from 'express';
|
|
3
3
|
import { IAuthProvider, JwtToken } from '../classes/BaseAuthProvider';
|
|
4
4
|
import { IExtensionInterface } from '../classes/timing/ExpressServerTiming';
|
|
5
|
+
import { XNextFc, XRequest, XResponse } from './express';
|
|
5
6
|
export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
|
|
6
7
|
export interface ICClient extends ICoreCClient {
|
|
7
8
|
setAuthProvider(provider: IAuthProvider): boolean;
|
|
@@ -14,14 +15,14 @@ export interface ICClient extends ICoreCClient {
|
|
|
14
15
|
userId: string | null;
|
|
15
16
|
}>;
|
|
16
17
|
permissionValidation(token: JwtToken, requestType: string): Promise<boolean>;
|
|
17
|
-
bearerTokenValidation(req:
|
|
18
|
+
bearerTokenValidation(req: XRequest): Promise<JwtToken | null>;
|
|
18
19
|
}
|
|
19
20
|
export interface IKernel extends ICoreKernel<ICClient> {
|
|
20
21
|
getAppServerPort(): number;
|
|
21
22
|
setAppServerPort(port: number): void;
|
|
22
23
|
responseCodeFunction(data: {
|
|
23
24
|
code: number;
|
|
24
|
-
req:
|
|
25
|
+
req: XRequest;
|
|
25
26
|
}): void;
|
|
26
27
|
}
|
|
27
28
|
export type IBaseKernelModule<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> = ICoreKernelModule<K, T, P, C, E>;
|
|
@@ -32,5 +33,5 @@ export type IBaseBrige = ICoreBridge;
|
|
|
32
33
|
export type IBaseCache<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> = ICoreCache<K, T, P, C, E>;
|
|
33
34
|
export type IBaseElement<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> = ICoreElement<K, T, P, C, E>;
|
|
34
35
|
export interface IBaseAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends ICoreAction<K, T, P, C, E> {
|
|
35
|
-
handler(req:
|
|
36
|
+
handler(req: XRequest, res: XResponse, next: XNextFc, data: JwtToken | null, extension: IExtensionInterface): Promise<void>;
|
|
36
37
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Request } from 'express';
|
|
2
1
|
import { CoreCryptoClient } from '@grandlinex/core';
|
|
3
2
|
import { ICClient, IKernel } from '../../lib';
|
|
4
3
|
import { IAuthProvider, JwtToken, JwtTokenData } from '../../classes/BaseAuthProvider';
|
|
4
|
+
import { XRequest } from '../../lib/express';
|
|
5
5
|
export default class CryptoClient extends CoreCryptoClient implements ICClient {
|
|
6
6
|
protected authProvider: IAuthProvider | null;
|
|
7
7
|
protected kernel: IKernel;
|
|
@@ -15,5 +15,5 @@ export default class CryptoClient extends CoreCryptoClient implements ICClient {
|
|
|
15
15
|
userId: string | null;
|
|
16
16
|
}>;
|
|
17
17
|
permissionValidation(token: JwtToken, requestType: string): Promise<boolean>;
|
|
18
|
-
bearerTokenValidation(req:
|
|
18
|
+
bearerTokenValidation(req: XRequest): Promise<JwtToken | null>;
|
|
19
19
|
}
|
|
@@ -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,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type CorsMiddleWare = (req:
|
|
1
|
+
import { XNextFc, XRequest, XResponse } from '../../../lib/express';
|
|
2
|
+
export type CorsMiddleWare = (req: XRequest, res: XResponse, next: XNextFc) => void;
|
|
3
3
|
export declare const cors: CorsMiddleWare;
|
|
@@ -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.1",
|
|
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,11 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "BSD-3-Clause",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@grandlinex/core": "
|
|
31
|
-
"axios": "
|
|
32
|
-
"body-parser": "
|
|
33
|
-
"express": "
|
|
34
|
-
"jsonwebtoken": "
|
|
30
|
+
"@grandlinex/core": "0.27.0",
|
|
31
|
+
"axios": "0.27.2",
|
|
32
|
+
"body-parser": "1.20.1",
|
|
33
|
+
"express": "4.18.2",
|
|
34
|
+
"jsonwebtoken": "9.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/express": "^4.17.14",
|