@grandlinex/kernel 0.30.2 → 0.31.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/CHANGELOG.md +6 -0
- package/dist/cjs/Kernel.js +45 -0
- package/dist/cjs/KernelModule.js +24 -0
- package/dist/cjs/actions/ApiAuthTestAction.js +18 -0
- package/dist/cjs/actions/ApiVersionAction.js +19 -0
- package/dist/cjs/actions/GetTokenAction.d.ts +11 -0
- package/dist/cjs/actions/GetTokenAction.js +39 -0
- package/dist/cjs/actions/index.js +12 -0
- package/dist/cjs/api/KernelEndpoint.js +9 -0
- package/dist/cjs/api/index.js +8 -0
- package/dist/{classes → cjs/classes}/BaseAction.d.ts +1 -0
- package/dist/cjs/classes/BaseAction.js +66 -0
- package/dist/cjs/classes/BaseApiAction.js +49 -0
- package/dist/cjs/classes/BaseAuthProvider.d.ts +23 -0
- package/dist/cjs/classes/BaseAuthProvider.js +8 -0
- package/dist/cjs/classes/BaseEndpoint.d.ts +19 -0
- package/dist/cjs/classes/BaseEndpoint.js +63 -0
- package/dist/cjs/classes/BaseKernelModule.js +6 -0
- package/dist/{classes → cjs/classes}/index.d.ts +2 -2
- package/dist/cjs/classes/index.js +54 -0
- package/dist/cjs/classes/timing/ExpressServerTiming.js +53 -0
- package/dist/cjs/classes/timing/ServerTiming.js +26 -0
- package/dist/cjs/classes/timing/ServerTimingElement.js +23 -0
- package/dist/cjs/classes/timing/index.js +12 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/lib/express.js +2 -0
- package/dist/{lib → cjs/lib}/index.d.ts +8 -8
- package/dist/cjs/lib/index.js +2 -0
- package/dist/cjs/modules/crypto/CryptoClient.d.ts +20 -0
- package/dist/cjs/modules/crypto/CryptoClient.js +117 -0
- package/dist/cjs/modules/crypto/index.js +23 -0
- package/dist/cjs/modules/crypto/utils/cors.js +10 -0
- package/dist/cjs/package.json +3 -0
- package/dist/mjs/Kernel.d.ts +28 -0
- package/dist/mjs/KernelModule.d.ts +8 -0
- package/dist/mjs/actions/ApiAuthTestAction.d.ts +11 -0
- package/dist/mjs/actions/ApiVersionAction.d.ts +11 -0
- package/dist/mjs/actions/GetTokenAction.d.ts +11 -0
- package/dist/{actions → mjs/actions}/GetTokenAction.js +1 -33
- package/dist/mjs/actions/index.js +4 -0
- package/dist/mjs/api/KernelEndpoint.js +3 -0
- package/dist/mjs/api/index.d.ts +2 -0
- package/dist/mjs/classes/BaseAction.d.ts +20 -0
- package/dist/{classes → mjs/classes}/BaseAction.js +2 -1
- package/dist/mjs/classes/BaseApiAction.d.ts +9 -0
- package/dist/mjs/classes/BaseAuthProvider.d.ts +23 -0
- package/dist/mjs/classes/BaseAuthProvider.js +5 -0
- package/dist/mjs/classes/BaseKernelModule.d.ts +4 -0
- package/dist/mjs/classes/index.d.ts +10 -0
- package/dist/{classes → mjs/classes}/index.js +2 -2
- package/dist/mjs/classes/timing/ExpressServerTiming.d.ts +17 -0
- package/dist/{classes → mjs/classes}/timing/ExpressServerTiming.js +2 -1
- package/dist/mjs/classes/timing/ServerTiming.d.ts +8 -0
- package/dist/mjs/classes/timing/ServerTimingElement.d.ts +12 -0
- package/dist/mjs/classes/timing/index.d.ts +4 -0
- package/dist/mjs/index.js +15 -0
- package/dist/mjs/lib/express.d.ts +6 -0
- package/dist/mjs/lib/index.d.ts +36 -0
- package/dist/mjs/modules/crypto/CryptoClient.d.ts +20 -0
- package/dist/{modules → mjs/modules}/crypto/CryptoClient.js +14 -3
- package/dist/mjs/modules/crypto/index.js +3 -0
- package/dist/mjs/modules/crypto/utils/cors.d.ts +3 -0
- package/dist/mjs/package.json +3 -0
- package/package.json +33 -24
- package/tsconfig-cjs.json +92 -0
- package/dist/actions/GetTokenAction.d.ts +0 -43
- package/dist/classes/BaseAuthProvider.d.ts +0 -20
- package/dist/classes/BaseAuthProvider.js +0 -2
- package/dist/modules/crypto/CryptoClient.d.ts +0 -21
- /package/dist/{Kernel.d.ts → cjs/Kernel.d.ts} +0 -0
- /package/dist/{KernelModule.d.ts → cjs/KernelModule.d.ts} +0 -0
- /package/dist/{actions → cjs/actions}/ApiAuthTestAction.d.ts +0 -0
- /package/dist/{actions → cjs/actions}/ApiVersionAction.d.ts +0 -0
- /package/dist/{actions → cjs/actions}/index.d.ts +0 -0
- /package/dist/{api → cjs/api}/KernelEndpoint.d.ts +0 -0
- /package/dist/{api → cjs/api}/index.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/BaseApiAction.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/BaseKernelModule.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/timing/ExpressServerTiming.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/timing/ServerTiming.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/timing/ServerTimingElement.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/timing/index.d.ts +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{lib → cjs/lib}/express.d.ts +0 -0
- /package/dist/{modules → cjs/modules}/crypto/index.d.ts +0 -0
- /package/dist/{modules → cjs/modules}/crypto/utils/cors.d.ts +0 -0
- /package/dist/{Kernel.js → mjs/Kernel.js} +0 -0
- /package/dist/{KernelModule.js → mjs/KernelModule.js} +0 -0
- /package/dist/{actions → mjs/actions}/ApiAuthTestAction.js +0 -0
- /package/dist/{actions → mjs/actions}/ApiVersionAction.js +0 -0
- /package/dist/{actions/index.js → mjs/actions/index.d.ts} +0 -0
- /package/dist/{api/KernelEndpoint.js → mjs/api/KernelEndpoint.d.ts} +0 -0
- /package/dist/{api → mjs/api}/index.js +0 -0
- /package/dist/{classes → mjs/classes}/BaseApiAction.js +0 -0
- /package/dist/{classes → mjs/classes}/BaseEndpoint.d.ts +0 -0
- /package/dist/{classes → mjs/classes}/BaseEndpoint.js +0 -0
- /package/dist/{classes → mjs/classes}/BaseKernelModule.js +0 -0
- /package/dist/{classes → mjs/classes}/timing/ServerTiming.js +0 -0
- /package/dist/{classes → mjs/classes}/timing/ServerTimingElement.js +0 -0
- /package/dist/{classes → mjs/classes}/timing/index.js +0 -0
- /package/dist/{index.js → mjs/index.d.ts} +0 -0
- /package/dist/{lib → mjs/lib}/express.js +0 -0
- /package/dist/{lib → mjs/lib}/index.js +0 -0
- /package/dist/{modules/crypto/index.js → mjs/modules/crypto/index.d.ts} +0 -0
- /package/dist/{modules → mjs/modules}/crypto/utils/cors.js +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Kernel = exports.KernelModule = void 0;
|
|
21
|
+
/**
|
|
22
|
+
* @name Kernel Main Module
|
|
23
|
+
* @author David Nagy
|
|
24
|
+
*/
|
|
25
|
+
const Kernel_js_1 = __importDefault(require("./Kernel.js"));
|
|
26
|
+
exports.Kernel = Kernel_js_1.default;
|
|
27
|
+
const KernelModule_js_1 = __importDefault(require("./KernelModule.js"));
|
|
28
|
+
exports.KernelModule = KernelModule_js_1.default;
|
|
29
|
+
__exportStar(require("./actions/index.js"), exports);
|
|
30
|
+
__exportStar(require("./api/index.js"), exports);
|
|
31
|
+
__exportStar(require("./classes/index.js"), exports);
|
|
32
|
+
__exportStar(require("./modules/crypto/index.js"), exports);
|
|
33
|
+
__exportStar(require("./lib/index.js"), exports);
|
|
34
|
+
__exportStar(require("./lib/express.js"), exports);
|
|
35
|
+
__exportStar(require("@grandlinex/core"), exports);
|
|
36
|
+
exports.default = Kernel_js_1.default;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { ICoreAction, ICoreBridge, ICoreCache, ICoreCClient, ICoreClient, ICoreElement, ICoreKernel, ICoreKernelModule, ICorePresenter, ICoreService, IDataBase } from '@grandlinex/core';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import * as jwt from 'jsonwebtoken';
|
|
4
|
-
import { IAuthProvider, JwtToken, IExtensionInterface } from '../classes/index.js';
|
|
4
|
+
import { IAuthProvider, JwtToken, IExtensionInterface, JwtExtend } from '../classes/index.js';
|
|
5
5
|
import { XNextFc, XRequest, XResponse } from './express.js';
|
|
6
6
|
export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
|
|
7
|
-
export interface ICClient extends ICoreCClient {
|
|
8
|
-
setAuthProvider(provider: IAuthProvider): boolean;
|
|
9
|
-
jwtVerifyAccessToken(token: string): Promise<JwtToken | number>;
|
|
7
|
+
export interface ICClient<T extends JwtExtend = JwtExtend> extends ICoreCClient {
|
|
8
|
+
setAuthProvider(provider: IAuthProvider<T>): boolean;
|
|
9
|
+
jwtVerifyAccessToken(token: string): Promise<JwtToken<T> | number>;
|
|
10
10
|
jwtDecodeAccessToken(token: string): jwt.JwtPayload | null;
|
|
11
|
-
jwtGenerateAccessToken(data: JwtToken
|
|
11
|
+
jwtGenerateAccessToken(data: JwtToken<T>, expire?: string | number): Promise<string>;
|
|
12
12
|
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
13
13
|
valid: boolean;
|
|
14
14
|
userId: string | null;
|
|
15
15
|
}>;
|
|
16
|
-
permissionValidation(token: JwtToken
|
|
17
|
-
bearerTokenValidation(req: XRequest): Promise<JwtToken | number>;
|
|
16
|
+
permissionValidation(token: JwtToken<T>, requestType: string): Promise<boolean>;
|
|
17
|
+
bearerTokenValidation(req: XRequest): Promise<JwtToken<T> | number>;
|
|
18
18
|
}
|
|
19
|
-
export interface IKernel extends ICoreKernel<ICClient
|
|
19
|
+
export interface IKernel<T extends JwtExtend = JwtExtend> extends ICoreKernel<ICClient<T>> {
|
|
20
20
|
getAppServerPort(): number;
|
|
21
21
|
setAppServerPort(port: number): void;
|
|
22
22
|
responseCodeFunction(data: {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CoreCryptoClient } from '@grandlinex/core';
|
|
2
|
+
import { ICClient, IKernel } from '../../lib/index.js';
|
|
3
|
+
import { IAuthProvider, JwtExtend, JwtToken } from '../../classes/index.js';
|
|
4
|
+
import { XRequest } from '../../lib/express.js';
|
|
5
|
+
export default class CryptoClient<T extends JwtExtend = JwtExtend> extends CoreCryptoClient implements ICClient<T> {
|
|
6
|
+
protected authProvider: IAuthProvider<T> | null;
|
|
7
|
+
protected kernel: IKernel;
|
|
8
|
+
protected expiresIn: string;
|
|
9
|
+
constructor(key: string, kernel: IKernel);
|
|
10
|
+
setAuthProvider(provider: IAuthProvider<T>): boolean;
|
|
11
|
+
jwtVerifyAccessToken(token: string): Promise<JwtToken<T> | number>;
|
|
12
|
+
jwtDecodeAccessToken(token: string): JwtToken<T> | null;
|
|
13
|
+
jwtGenerateAccessToken(data: JwtToken<T>, expire?: string | number): Promise<string>;
|
|
14
|
+
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
15
|
+
valid: boolean;
|
|
16
|
+
userId: string | null;
|
|
17
|
+
}>;
|
|
18
|
+
permissionValidation(token: JwtToken<T>, requestType: string): Promise<boolean>;
|
|
19
|
+
bearerTokenValidation(req: XRequest): Promise<JwtToken<T> | number>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const core_1 = require("@grandlinex/core");
|
|
27
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
28
|
+
class CryptoClient extends core_1.CoreCryptoClient {
|
|
29
|
+
constructor(key, kernel) {
|
|
30
|
+
super(kernel, key);
|
|
31
|
+
this.kernel = kernel;
|
|
32
|
+
this.authProvider = null;
|
|
33
|
+
this.expiresIn = kernel.getConfigStore().get('JWT_EXPIRE') || '1 days';
|
|
34
|
+
}
|
|
35
|
+
setAuthProvider(provider) {
|
|
36
|
+
if (this.authProvider) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
this.authProvider = provider;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
jwtVerifyAccessToken(token) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
jwt.verify(token, this.AesKey, (err, user) => {
|
|
45
|
+
if (err instanceof jwt.TokenExpiredError) {
|
|
46
|
+
resolve(498);
|
|
47
|
+
}
|
|
48
|
+
else if (err || user === null) {
|
|
49
|
+
resolve(403);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
resolve(user);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
jwtDecodeAccessToken(token) {
|
|
58
|
+
// MSJ-CJS SWITCH
|
|
59
|
+
const mod = jwt.default || jwt;
|
|
60
|
+
return mod.decode(token, { json: true });
|
|
61
|
+
}
|
|
62
|
+
async jwtGenerateAccessToken(data, expire) {
|
|
63
|
+
let sData;
|
|
64
|
+
if (this.authProvider) {
|
|
65
|
+
sData = await this.authProvider.jwtAddData(data);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
sData = data;
|
|
69
|
+
}
|
|
70
|
+
return jwt.sign(sData, this.AesKey, {
|
|
71
|
+
expiresIn: expire ?? this.expiresIn,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async apiTokenValidation(username, token, requestType) {
|
|
75
|
+
if (this.authProvider) {
|
|
76
|
+
return this.authProvider.authorizeToken(username, token, requestType);
|
|
77
|
+
}
|
|
78
|
+
const store = this.kernel.getConfigStore();
|
|
79
|
+
const cc = this.kernel.getCryptoClient();
|
|
80
|
+
if (!store.has('SERVER_PASSWORD')) {
|
|
81
|
+
return { valid: false, userId: null };
|
|
82
|
+
}
|
|
83
|
+
if (cc?.timeSavePWValidation(token, store.get('SERVER_PASSWORD') || '') ||
|
|
84
|
+
(token === store.get('SERVER_PASSWORD') && username === 'admin')) {
|
|
85
|
+
return {
|
|
86
|
+
valid: true,
|
|
87
|
+
userId: 'admin',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
valid: false,
|
|
92
|
+
userId: null,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async permissionValidation(token, requestType) {
|
|
96
|
+
if (this.authProvider) {
|
|
97
|
+
return this.authProvider.validateAccess(token, requestType);
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
async bearerTokenValidation(req) {
|
|
102
|
+
if (this.authProvider) {
|
|
103
|
+
return this.authProvider.bearerTokenValidation(req);
|
|
104
|
+
}
|
|
105
|
+
const authHeader = req.headers.authorization;
|
|
106
|
+
const token = authHeader && authHeader.split(' ')[1];
|
|
107
|
+
if (!token) {
|
|
108
|
+
return 401;
|
|
109
|
+
}
|
|
110
|
+
const tokenData = await this.jwtVerifyAccessToken(token);
|
|
111
|
+
if (tokenData) {
|
|
112
|
+
return tokenData;
|
|
113
|
+
}
|
|
114
|
+
return 403;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.default = CryptoClient;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.CryptoClient = void 0;
|
|
21
|
+
const CryptoClient_js_1 = __importDefault(require("./CryptoClient.js"));
|
|
22
|
+
exports.CryptoClient = CryptoClient_js_1.default;
|
|
23
|
+
__exportStar(require("./utils/cors.js"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cors = void 0;
|
|
4
|
+
const cors = (req, res, next) => {
|
|
5
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
6
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
7
|
+
res.setHeader('Access-Control-Allow-Methods', '*');
|
|
8
|
+
next();
|
|
9
|
+
};
|
|
10
|
+
exports.cors = cors;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CoreLogger, CoreKernel } from '@grandlinex/core';
|
|
2
|
+
import { ICClient, IKernel } from './lib/index.js';
|
|
3
|
+
import { XRequest } from './lib/express.js';
|
|
4
|
+
/**
|
|
5
|
+
* @class Kernel
|
|
6
|
+
*/
|
|
7
|
+
export default class Kernel extends CoreKernel<ICClient> implements IKernel {
|
|
8
|
+
private expressPort;
|
|
9
|
+
/**
|
|
10
|
+
* Default Constructor
|
|
11
|
+
* @param options App Name
|
|
12
|
+
*/
|
|
13
|
+
constructor(options: {
|
|
14
|
+
appName: string;
|
|
15
|
+
appCode: string;
|
|
16
|
+
pathOverride?: string;
|
|
17
|
+
portOverride?: number;
|
|
18
|
+
envFilePath?: string;
|
|
19
|
+
loadFromLocalEnv?: boolean;
|
|
20
|
+
logger?: (k: CoreKernel<any>) => CoreLogger;
|
|
21
|
+
});
|
|
22
|
+
getAppServerPort(): number;
|
|
23
|
+
setAppServerPort(port: number): void;
|
|
24
|
+
responseCodeFunction(data: {
|
|
25
|
+
code: number;
|
|
26
|
+
req: XRequest;
|
|
27
|
+
}): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InMemCache } from '@grandlinex/core';
|
|
2
|
+
import BaseKernelModule from './classes/BaseKernelModule.js';
|
|
3
|
+
import { IKernel } from './lib/index.js';
|
|
4
|
+
import KernelEndpoint from './api/KernelEndpoint.js';
|
|
5
|
+
export default class KernelModule extends BaseKernelModule<IKernel, null, null, InMemCache, KernelEndpoint> {
|
|
6
|
+
constructor(kernel: IKernel);
|
|
7
|
+
initModule(): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IBaseKernelModule } from '../lib/index.js';
|
|
2
|
+
import { BaseApiAction, JwtToken } from '../classes/index.js';
|
|
3
|
+
import { XRequest, XResponse } from '../lib/express.js';
|
|
4
|
+
/**
|
|
5
|
+
* @name ApiAuthTestAction
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export default class ApiAuthTestAction extends BaseApiAction {
|
|
9
|
+
constructor(module: IBaseKernelModule<any, any, any, any>);
|
|
10
|
+
handler(req: XRequest, res: XResponse, next: () => void, data: JwtToken): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IBaseKernelModule } from '../lib/index.js';
|
|
2
|
+
import { BaseApiAction, IExtensionInterface } from '../classes/index.js';
|
|
3
|
+
import { XRequest, XResponse } from '../lib/express.js';
|
|
4
|
+
/**
|
|
5
|
+
* @name ApiVersionAction
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export default class ApiVersionAction extends BaseApiAction {
|
|
9
|
+
constructor(module: IBaseKernelModule);
|
|
10
|
+
handler(req: XRequest, res: XResponse, next: () => void, data: any, ex: IExtensionInterface): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IBaseKernelModule } from '../lib/index.js';
|
|
2
|
+
import { BaseApiAction, IExtensionInterface } from '../classes/index.js';
|
|
3
|
+
import { XRequest, XResponse } from '../lib/express.js';
|
|
4
|
+
export default class GetTokenAction extends BaseApiAction {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param module Parent Module
|
|
8
|
+
*/
|
|
9
|
+
constructor(module: IBaseKernelModule<any, any, any, any>);
|
|
10
|
+
handler(req: XRequest, res: XResponse, next: () => void, data: any, ex: IExtensionInterface): Promise<void>;
|
|
11
|
+
}
|
|
@@ -1,36 +1,4 @@
|
|
|
1
1
|
import { BaseApiAction, ActionMode, } from '../classes/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* @openapi
|
|
4
|
-
* /token:
|
|
5
|
-
* post:
|
|
6
|
-
* summary: Get Bearer for user.
|
|
7
|
-
* tags:
|
|
8
|
-
* - Kernel
|
|
9
|
-
* description: Returns JWT.
|
|
10
|
-
* responses:
|
|
11
|
-
* '200':
|
|
12
|
-
* description: OK
|
|
13
|
-
* content:
|
|
14
|
-
* application/json:
|
|
15
|
-
* schema:
|
|
16
|
-
* type: object
|
|
17
|
-
* properties:
|
|
18
|
-
* token:
|
|
19
|
-
* type: string
|
|
20
|
-
* '403':
|
|
21
|
-
* description: Not Authorized
|
|
22
|
-
* requestBody:
|
|
23
|
-
* required: true
|
|
24
|
-
* content:
|
|
25
|
-
* application/json:
|
|
26
|
-
* schema:
|
|
27
|
-
* type: object
|
|
28
|
-
* properties:
|
|
29
|
-
* username:
|
|
30
|
-
* type: string
|
|
31
|
-
* token:
|
|
32
|
-
* type: string
|
|
33
|
-
*/
|
|
34
2
|
export default class GetTokenAction extends BaseApiAction {
|
|
35
3
|
/**
|
|
36
4
|
*
|
|
@@ -54,7 +22,7 @@ export default class GetTokenAction extends BaseApiAction {
|
|
|
54
22
|
const { username, token } = req.body;
|
|
55
23
|
const valid = await ex.timing.startFunc('validation', () => cc.apiTokenValidation(username, token, 'api'));
|
|
56
24
|
if (valid.valid && valid.userId) {
|
|
57
|
-
const jwt = cc.jwtGenerateAccessToken({
|
|
25
|
+
const jwt = await cc.jwtGenerateAccessToken({
|
|
58
26
|
userid: valid.userId,
|
|
59
27
|
username,
|
|
60
28
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CoreAction, IDataBase } from '@grandlinex/core';
|
|
2
|
+
import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
|
+
import { JwtToken } from './BaseAuthProvider.js';
|
|
4
|
+
import { IExtensionInterface } from './timing/index.js';
|
|
5
|
+
import { XNextFc, XRequest, XResponse } from '../lib/express.js';
|
|
6
|
+
export declare enum ActionMode {
|
|
7
|
+
'DEFAULT' = 0,
|
|
8
|
+
'DMZ' = 1,
|
|
9
|
+
'DMZ_WITH_USER' = 2
|
|
10
|
+
}
|
|
11
|
+
export default abstract class BaseAction<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 CoreAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
|
|
12
|
+
mode: ActionMode;
|
|
13
|
+
forceDebug: boolean;
|
|
14
|
+
constructor(chanel: string, module: IBaseKernelModule<K, T, P, C, E>);
|
|
15
|
+
abstract handler(req: XRequest, res: XResponse, next: XNextFc, data: JwtToken | null, extension: IExtensionInterface): Promise<void>;
|
|
16
|
+
secureHandler(req: XRequest, res: XResponse, next: () => void): Promise<void>;
|
|
17
|
+
setMode(mode: ActionMode): void;
|
|
18
|
+
abstract register(): void;
|
|
19
|
+
private initExtension;
|
|
20
|
+
}
|
|
@@ -5,12 +5,13 @@ export var ActionMode;
|
|
|
5
5
|
ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
|
|
6
6
|
ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
|
|
7
7
|
ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
|
|
8
|
-
})(ActionMode
|
|
8
|
+
})(ActionMode || (ActionMode = {}));
|
|
9
9
|
export default class BaseAction extends CoreAction {
|
|
10
10
|
constructor(chanel, module) {
|
|
11
11
|
super(chanel, module);
|
|
12
12
|
this.secureHandler = this.secureHandler.bind(this);
|
|
13
13
|
this.mode = ActionMode.DEFAULT;
|
|
14
|
+
this.forceDebug = false;
|
|
14
15
|
}
|
|
15
16
|
async secureHandler(req, res, next) {
|
|
16
17
|
const extension = this.initExtension(res);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IDataBase } from '@grandlinex/core';
|
|
2
|
+
import { ActionTypes, IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
|
+
import BaseAction from './BaseAction.js';
|
|
4
|
+
export default abstract class BaseApiAction<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 BaseAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
|
|
5
|
+
exmod: undefined | IBaseKernelModule<K>;
|
|
6
|
+
type: ActionTypes;
|
|
7
|
+
constructor(type: ActionTypes, chanel: string, module: IBaseKernelModule<K, T, P, C, E>, extMod?: IBaseKernelModule<K>);
|
|
8
|
+
register(): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
2
|
+
import { XRequest } from '../lib/express.js';
|
|
3
|
+
export type JwtExtend = {
|
|
4
|
+
username: string;
|
|
5
|
+
userid: string;
|
|
6
|
+
} & Partial<Record<string, string | number | number[] | string[]>>;
|
|
7
|
+
export type JwtToken<T extends JwtExtend = JwtExtend> = T & jwt.JwtPayload;
|
|
8
|
+
export type AuthResult = {
|
|
9
|
+
valid: boolean;
|
|
10
|
+
userId: string | null;
|
|
11
|
+
};
|
|
12
|
+
export interface IAuthProvider<T extends JwtExtend> {
|
|
13
|
+
authorizeToken(userid: string, token: string, requestType: string): Promise<AuthResult>;
|
|
14
|
+
validateAccess(token: JwtToken<T>, requestType: string): Promise<boolean>;
|
|
15
|
+
bearerTokenValidation(req: XRequest): Promise<JwtToken<T> | number>;
|
|
16
|
+
jwtAddData(token: JwtToken<T>): Promise<JwtToken<T>>;
|
|
17
|
+
}
|
|
18
|
+
export default abstract class BaseAuthProvider<T extends JwtExtend = JwtExtend> implements IAuthProvider<T> {
|
|
19
|
+
abstract authorizeToken(username: string, token: string, requestType: string): Promise<AuthResult>;
|
|
20
|
+
abstract validateAccess(token: JwtToken<T>, requestType: string): Promise<boolean>;
|
|
21
|
+
abstract bearerTokenValidation(req: XRequest): Promise<JwtToken<T> | number>;
|
|
22
|
+
jwtAddData(token: JwtToken<T>): Promise<JwtToken<T>>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CoreKernelModule, IDataBase } from '@grandlinex/core';
|
|
2
|
+
import { IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
|
+
export default abstract class BaseKernelModule<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 CoreKernelModule<K, T, P, C, E> implements IBaseKernelModule<K, T, P, C, E> {
|
|
4
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CoreBridge as BaseBridge, CoreCache as BaseCache, CoreClient as BaseClient, CoreElement as BaseElement, CoreLoopService as BaseLoopService, CoreService as BaseService } from '@grandlinex/core';
|
|
2
|
+
import BaseAction, { ActionMode } from './BaseAction.js';
|
|
3
|
+
import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
|
|
4
|
+
import BaseKernelModule from './BaseKernelModule.js';
|
|
5
|
+
import BaseApiAction from './BaseApiAction.js';
|
|
6
|
+
import BaseAuthProvider from './BaseAuthProvider.js';
|
|
7
|
+
export * from './BaseAction.js';
|
|
8
|
+
export * from './BaseAuthProvider.js';
|
|
9
|
+
export * from './timing/index.js';
|
|
10
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoreBridge as BaseBridge, CoreCache as BaseCache, CoreClient as BaseClient, CoreElement as BaseElement, CoreLoopService as BaseLoopService, CoreService as BaseService, } from '@grandlinex/core';
|
|
2
|
-
import BaseAction from './BaseAction.js';
|
|
2
|
+
import BaseAction, { ActionMode } from './BaseAction.js';
|
|
3
3
|
import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
|
|
4
4
|
import BaseKernelModule from './BaseKernelModule.js';
|
|
5
5
|
import BaseApiAction from './BaseApiAction.js';
|
|
@@ -7,4 +7,4 @@ import BaseAuthProvider from './BaseAuthProvider.js';
|
|
|
7
7
|
export * from './BaseAction.js';
|
|
8
8
|
export * from './BaseAuthProvider.js';
|
|
9
9
|
export * from './timing/index.js';
|
|
10
|
-
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
|
|
10
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CoreElement } from '@grandlinex/core';
|
|
2
|
+
import { XResponse } from '../../lib/express.js';
|
|
3
|
+
export type IExtensionInterface = {
|
|
4
|
+
done: () => void;
|
|
5
|
+
timing: ExpressServerTiming;
|
|
6
|
+
};
|
|
7
|
+
export default class ExpressServerTiming {
|
|
8
|
+
private timing;
|
|
9
|
+
private baseApiAction;
|
|
10
|
+
constructor(baseApiAction: CoreElement<any>);
|
|
11
|
+
start(chanel: string): import("./ServerTimingElement.js").default;
|
|
12
|
+
startFunc<T>(chanel: string, fc: () => Promise<T>): Promise<T>;
|
|
13
|
+
dbQuery<T>(fc: () => Promise<T>): Promise<T>;
|
|
14
|
+
getHeader(): string;
|
|
15
|
+
addHeader(res: XResponse): void;
|
|
16
|
+
static init(baseApiAction: CoreElement<any>, res: XResponse): [ExpressServerTiming, () => void];
|
|
17
|
+
}
|
|
@@ -26,7 +26,8 @@ export default class ExpressServerTiming {
|
|
|
26
26
|
}
|
|
27
27
|
addHeader(res) {
|
|
28
28
|
if (this.timing.map.size > 0 &&
|
|
29
|
-
this.baseApiAction.getKernel().getDevMode()
|
|
29
|
+
(this.baseApiAction.getKernel().getDevMode() ||
|
|
30
|
+
this.baseApiAction.forceDebug)) {
|
|
30
31
|
const a = ['Server-Timing', this.getHeader()];
|
|
31
32
|
res.setHeader(a[0], a[1]);
|
|
32
33
|
this.baseApiAction.debug(a);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ServerTimingElement, { IServerElement } from './ServerTimingElement.js';
|
|
2
|
+
export default class ServerTiming implements IServerElement {
|
|
3
|
+
map: Map<string, ServerTimingElement[]>;
|
|
4
|
+
constructor();
|
|
5
|
+
start(chanel: string): ServerTimingElement;
|
|
6
|
+
startFunc<T>(chanel: string, fc: () => Promise<T>): Promise<T>;
|
|
7
|
+
completeElement(e: ServerTimingElement): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type IServerElement = {
|
|
2
|
+
completeElement: (e: ServerTimingElement) => void;
|
|
3
|
+
};
|
|
4
|
+
export default class ServerTimingElement {
|
|
5
|
+
private el;
|
|
6
|
+
readonly chanel: string;
|
|
7
|
+
private readonly start;
|
|
8
|
+
private end;
|
|
9
|
+
constructor(el: IServerElement, chanel: string);
|
|
10
|
+
stop(): void;
|
|
11
|
+
getDuration(): number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import ExpressServerTiming, { IExtensionInterface } from './ExpressServerTiming.js';
|
|
2
|
+
import ServerTiming from './ServerTiming.js';
|
|
3
|
+
import ServerTimingElement from './ServerTimingElement.js';
|
|
4
|
+
export { ExpressServerTiming, ServerTimingElement, ServerTiming, IExtensionInterface, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name Kernel Main Module
|
|
3
|
+
* @author David Nagy
|
|
4
|
+
*/
|
|
5
|
+
import Kernel from './Kernel.js';
|
|
6
|
+
import KernelModule from './KernelModule.js';
|
|
7
|
+
export * from './actions/index.js';
|
|
8
|
+
export * from './api/index.js';
|
|
9
|
+
export * from './classes/index.js';
|
|
10
|
+
export * from './modules/crypto/index.js';
|
|
11
|
+
export * from './lib/index.js';
|
|
12
|
+
export * from './lib/express.js';
|
|
13
|
+
export * from '@grandlinex/core';
|
|
14
|
+
export { KernelModule, Kernel };
|
|
15
|
+
export default Kernel;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ICoreAction, ICoreBridge, ICoreCache, ICoreCClient, ICoreClient, ICoreElement, ICoreKernel, ICoreKernelModule, ICorePresenter, ICoreService, IDataBase } from '@grandlinex/core';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import * as jwt from 'jsonwebtoken';
|
|
4
|
+
import { IAuthProvider, JwtToken, IExtensionInterface, JwtExtend } from '../classes/index.js';
|
|
5
|
+
import { XNextFc, XRequest, XResponse } from './express.js';
|
|
6
|
+
export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
|
|
7
|
+
export interface ICClient<T extends JwtExtend = JwtExtend> extends ICoreCClient {
|
|
8
|
+
setAuthProvider(provider: IAuthProvider<T>): boolean;
|
|
9
|
+
jwtVerifyAccessToken(token: string): Promise<JwtToken<T> | number>;
|
|
10
|
+
jwtDecodeAccessToken(token: string): jwt.JwtPayload | null;
|
|
11
|
+
jwtGenerateAccessToken(data: JwtToken<T>, expire?: string | number): Promise<string>;
|
|
12
|
+
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
13
|
+
valid: boolean;
|
|
14
|
+
userId: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
permissionValidation(token: JwtToken<T>, requestType: string): Promise<boolean>;
|
|
17
|
+
bearerTokenValidation(req: XRequest): Promise<JwtToken<T> | number>;
|
|
18
|
+
}
|
|
19
|
+
export interface IKernel<T extends JwtExtend = JwtExtend> extends ICoreKernel<ICClient<T>> {
|
|
20
|
+
getAppServerPort(): number;
|
|
21
|
+
setAppServerPort(port: number): void;
|
|
22
|
+
responseCodeFunction(data: {
|
|
23
|
+
code: number;
|
|
24
|
+
req: XRequest;
|
|
25
|
+
}): void;
|
|
26
|
+
}
|
|
27
|
+
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>;
|
|
28
|
+
export type IBasePresenter = ICorePresenter<express.Express>;
|
|
29
|
+
export type IBaseService<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> = ICoreService<K, T, P, C, E>;
|
|
30
|
+
export type IBaseClient<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> = ICoreClient;
|
|
31
|
+
export type IBaseBrige = ICoreBridge;
|
|
32
|
+
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
|
+
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
|
+
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: XRequest, res: XResponse, next: XNextFc, data: JwtToken | null, extension: IExtensionInterface): Promise<void>;
|
|
36
|
+
}
|