@grandlinex/kernel 0.21.0 → 0.23.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.d.ts +2 -1
- package/dist/Kernel.js +13 -5
- package/dist/KernelModule.d.ts +1 -3
- package/dist/KernelModule.js +2 -18
- package/dist/actions/ApiAuthTestAction.d.ts +2 -2
- package/dist/actions/ApiAuthTestAction.js +2 -1
- package/dist/actions/GetTokenAction.js +4 -2
- package/dist/classes/BaseApiAction.js +7 -1
- package/dist/classes/BaseAuthProvider.d.ts +13 -6
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.js +15 -0
- package/dist/index.d.ts +1 -8
- package/dist/index.js +6 -25
- package/dist/lib/index.d.ts +6 -13
- package/dist/modules/crypto/CryptoClient.d.ts +8 -8
- package/dist/modules/crypto/CryptoClient.js +16 -34
- package/dist/modules/crypto/index.js +5 -1
- package/package.json +2 -5
- package/dist/database/KernelDB.d.ts +0 -14
- package/dist/database/KernelDB.js +0 -115
- package/dist/database/entity/GKey.d.ts +0 -8
- package/dist/database/entity/GKey.js +0 -61
package/dist/Kernel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import CoreKernel from '@grandlinex/core';
|
|
1
|
+
import CoreKernel, { CoreLogger } from '@grandlinex/core';
|
|
2
2
|
import { ICClient, IKernel } from './lib';
|
|
3
3
|
/**
|
|
4
4
|
* @class Kernel
|
|
@@ -15,6 +15,7 @@ export default class Kernel extends CoreKernel<ICClient> implements IKernel {
|
|
|
15
15
|
pathOverride?: string;
|
|
16
16
|
portOverride?: number;
|
|
17
17
|
envFilePath?: string;
|
|
18
|
+
logger?: (k: CoreKernel<any>) => CoreLogger;
|
|
18
19
|
});
|
|
19
20
|
getAppServerPort(): number;
|
|
20
21
|
setAppServerPort(port: number): void;
|
package/dist/Kernel.js
CHANGED
|
@@ -14,14 +14,24 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
30
|
};
|
|
20
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
32
|
var core_1 = __importDefault(require("@grandlinex/core"));
|
|
22
|
-
var bundle_elogger_1 = __importDefault(require("@grandlinex/bundle-elogger"));
|
|
23
|
-
var KernelModule_1 = __importDefault(require("./KernelModule"));
|
|
24
33
|
var CryptoClient_1 = __importDefault(require("./modules/crypto/CryptoClient"));
|
|
34
|
+
var KernelModule_1 = __importDefault(require("./KernelModule"));
|
|
25
35
|
/**
|
|
26
36
|
* @class Kernel
|
|
27
37
|
*/
|
|
@@ -32,9 +42,7 @@ var Kernel = /** @class */ (function (_super) {
|
|
|
32
42
|
* @param options App Name
|
|
33
43
|
*/
|
|
34
44
|
function Kernel(options) {
|
|
35
|
-
var _this = _super.call(this, options) || this;
|
|
36
|
-
_this.globalLogger = new bundle_elogger_1.default(_this);
|
|
37
|
-
_this.setLogger(_this.globalLogger);
|
|
45
|
+
var _this = _super.call(this, __assign({}, options)) || this;
|
|
38
46
|
_this.setBaseModule(new KernelModule_1.default(_this));
|
|
39
47
|
if (options.portOverride) {
|
|
40
48
|
_this.debug("use custiom api port @ ".concat(options.portOverride));
|
package/dist/KernelModule.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { InMemCache } from '@grandlinex/core';
|
|
2
2
|
import BaseKernelModule from './classes/BaseKernelModule';
|
|
3
|
-
import KernelDB from './database/KernelDB';
|
|
4
3
|
import { IKernel } from './lib';
|
|
5
4
|
import KernelEndpoint from './api/KernelEndpoint';
|
|
6
|
-
export default class KernelModule extends BaseKernelModule<
|
|
7
|
-
useLightDB: boolean;
|
|
5
|
+
export default class KernelModule extends BaseKernelModule<null, null, InMemCache, KernelEndpoint> {
|
|
8
6
|
constructor(kernel: IKernel);
|
|
9
7
|
initModule(): Promise<void>;
|
|
10
8
|
}
|
package/dist/KernelModule.js
CHANGED
|
@@ -54,42 +54,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
54
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
55
|
};
|
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
// eslint-disable-next-line max-classes-per-file
|
|
58
57
|
var core_1 = require("@grandlinex/core");
|
|
59
|
-
var bundle_sqlight_1 = __importDefault(require("@grandlinex/bundle-sqlight"));
|
|
60
|
-
var bundle_postgresql_1 = __importDefault(require("@grandlinex/bundle-postgresql"));
|
|
61
58
|
var BaseKernelModule_1 = __importDefault(require("./classes/BaseKernelModule"));
|
|
62
|
-
var KernelDB_1 = __importDefault(require("./database/KernelDB"));
|
|
63
59
|
var KernelEndpoint_1 = __importDefault(require("./api/KernelEndpoint"));
|
|
64
60
|
var ApiVersionAction_1 = __importDefault(require("./actions/ApiVersionAction"));
|
|
65
61
|
var GetTokenAction_1 = __importDefault(require("./actions/GetTokenAction"));
|
|
66
62
|
var ApiAuthTestAction_1 = __importDefault(require("./actions/ApiAuthTestAction"));
|
|
67
|
-
var GKey_1 = __importDefault(require("./database/entity/GKey"));
|
|
68
63
|
var KernelModule = /** @class */ (function (_super) {
|
|
69
64
|
__extends(KernelModule, _super);
|
|
70
65
|
function KernelModule(kernel) {
|
|
71
|
-
var _this = _super.call(this, '
|
|
72
|
-
_this.useLightDB = false;
|
|
66
|
+
var _this = _super.call(this, 'base-mod', kernel) || this;
|
|
73
67
|
_this.addAction(new ApiVersionAction_1.default(_this), new ApiAuthTestAction_1.default(_this), new GetTokenAction_1.default(_this));
|
|
74
68
|
_this.addService(new core_1.OfflineService(_this));
|
|
75
69
|
return _this;
|
|
76
70
|
}
|
|
77
71
|
KernelModule.prototype.initModule = function () {
|
|
78
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
-
var
|
|
73
|
+
var endpoint;
|
|
80
74
|
return __generator(this, function (_a) {
|
|
81
75
|
switch (_a.label) {
|
|
82
76
|
case 0:
|
|
83
|
-
this.setCache(new core_1.InMemCache(this, 480000));
|
|
84
|
-
if (this.useLightDB) {
|
|
85
|
-
db = new KernelDB_1.default(new bundle_sqlight_1.default(this, '0'));
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
db = new KernelDB_1.default(new bundle_postgresql_1.default(this, '0'));
|
|
89
|
-
}
|
|
90
|
-
db.setEntityCache(true);
|
|
91
|
-
db.registerEntity(new GKey_1.default());
|
|
92
|
-
this.setDb(db);
|
|
93
77
|
endpoint = new KernelEndpoint_1.default('api', this, this.getKernel().getAppServerPort());
|
|
94
78
|
this.setPresenter(endpoint);
|
|
95
79
|
return [4 /*yield*/, this.getKernel().triggerFunction('load')];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import e from 'express';
|
|
2
2
|
import { IBaseKernelModule } from '../lib';
|
|
3
|
-
import { BaseApiAction } from '../classes';
|
|
3
|
+
import { BaseApiAction, JwtToken } from '../classes';
|
|
4
4
|
/**
|
|
5
5
|
* @name ApiAuthTestAction
|
|
6
6
|
*
|
|
@@ -23,5 +23,5 @@ import { BaseApiAction } from '../classes';
|
|
|
23
23
|
*/
|
|
24
24
|
export default class ApiAuthTestAction extends BaseApiAction {
|
|
25
25
|
constructor(module: IBaseKernelModule<any, any, any, any>);
|
|
26
|
-
handler(req: e.Request, res: e.Response, next: () => void): Promise<void>;
|
|
26
|
+
handler(req: e.Request, res: e.Response, next: () => void, data: JwtToken): Promise<void>;
|
|
27
27
|
}
|
|
@@ -79,9 +79,10 @@ var ApiAuthTestAction = /** @class */ (function (_super) {
|
|
|
79
79
|
_this.handler = _this.handler.bind(_this);
|
|
80
80
|
return _this;
|
|
81
81
|
}
|
|
82
|
-
ApiAuthTestAction.prototype.handler = function (req, res, next) {
|
|
82
|
+
ApiAuthTestAction.prototype.handler = function (req, res, next, data) {
|
|
83
83
|
return __awaiter(this, void 0, void 0, function () {
|
|
84
84
|
return __generator(this, function (_a) {
|
|
85
|
+
this.debug(data.userid);
|
|
85
86
|
res.status(200).send("It work's");
|
|
86
87
|
return [2 /*return*/];
|
|
87
88
|
});
|
|
@@ -98,7 +98,7 @@ var GetTokenAction = /** @class */ (function (_super) {
|
|
|
98
98
|
}
|
|
99
99
|
GetTokenAction.prototype.handler = function (req, res, next) {
|
|
100
100
|
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var cc, _a, username, token, jwt;
|
|
101
|
+
var cc, _a, username, token, valid, jwt;
|
|
102
102
|
return __generator(this, function (_b) {
|
|
103
103
|
switch (_b.label) {
|
|
104
104
|
case 0:
|
|
@@ -114,8 +114,10 @@ var GetTokenAction = /** @class */ (function (_super) {
|
|
|
114
114
|
_a = req.body, username = _a.username, token = _a.token;
|
|
115
115
|
return [4 /*yield*/, cc.apiTokenValidation(username, token, 'api')];
|
|
116
116
|
case 1:
|
|
117
|
-
|
|
117
|
+
valid = _b.sent();
|
|
118
|
+
if (valid.valid && valid.userId) {
|
|
118
119
|
jwt = cc.jwtGenerateAccessToken({
|
|
120
|
+
userid: valid.userId,
|
|
119
121
|
username: username,
|
|
120
122
|
});
|
|
121
123
|
res.status(200).send({ token: jwt });
|
|
@@ -36,7 +36,7 @@ var BaseApiAction = /** @class */ (function (_super) {
|
|
|
36
36
|
endpoint = this.getModule().getPresenter();
|
|
37
37
|
}
|
|
38
38
|
if (endpoint) {
|
|
39
|
-
this.log("register ".concat(this.getName()));
|
|
39
|
+
this.log("register ".concat(this.type, " ").concat(this.getName()));
|
|
40
40
|
var app = endpoint.getApp();
|
|
41
41
|
switch (this.type) {
|
|
42
42
|
case 'POST':
|
|
@@ -45,6 +45,12 @@ var BaseApiAction = /** @class */ (function (_super) {
|
|
|
45
45
|
case 'USE':
|
|
46
46
|
app.use(this.getName(), this.secureHandler);
|
|
47
47
|
break;
|
|
48
|
+
case 'PATCH':
|
|
49
|
+
app.patch(this.getName(), this.secureHandler);
|
|
50
|
+
break;
|
|
51
|
+
case 'DELETE':
|
|
52
|
+
app.delete(this.getName(), this.secureHandler);
|
|
53
|
+
break;
|
|
48
54
|
case 'GET':
|
|
49
55
|
default:
|
|
50
56
|
app.get(this.getName(), this.secureHandler);
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
-
export interface
|
|
2
|
+
export interface JwtTokenData {
|
|
3
|
+
username: string;
|
|
4
|
+
userid: string;
|
|
5
|
+
}
|
|
6
|
+
export interface JwtToken extends JwtTokenData {
|
|
3
7
|
exp: number;
|
|
4
8
|
iat: number;
|
|
5
|
-
username: string;
|
|
6
9
|
}
|
|
10
|
+
export declare type AuthResult = {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
userId: string | null;
|
|
13
|
+
};
|
|
7
14
|
export interface IAuthProvider {
|
|
8
|
-
authorizeToken(
|
|
9
|
-
|
|
15
|
+
authorizeToken(userid: string, token: string, requestType: string): Promise<AuthResult>;
|
|
16
|
+
validateAccess(token: JwtToken, requestType: string): Promise<boolean>;
|
|
10
17
|
bearerTokenValidation(req: Request): Promise<JwtToken | null>;
|
|
11
18
|
}
|
|
12
19
|
export default abstract class BaseAuthProvider implements IAuthProvider {
|
|
13
|
-
abstract authorizeToken(username: string, token:
|
|
14
|
-
abstract
|
|
20
|
+
abstract authorizeToken(username: string, token: string, requestType: string): Promise<AuthResult>;
|
|
21
|
+
abstract validateAccess(token: JwtToken, requestType: string): Promise<boolean>;
|
|
15
22
|
abstract bearerTokenValidation(req: Request): Promise<JwtToken | null>;
|
|
16
23
|
}
|
package/dist/classes/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import BaseEndpoint from './BaseEndpoint';
|
|
|
4
4
|
import BaseKernelModule from './BaseKernelModule';
|
|
5
5
|
import BaseApiAction from './BaseApiAction';
|
|
6
6
|
import BaseAuthProvider from './BaseAuthProvider';
|
|
7
|
+
export * from './BaseAuthProvider';
|
|
7
8
|
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, };
|
package/dist/classes/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
@@ -21,3 +35,4 @@ var BaseApiAction_1 = __importDefault(require("./BaseApiAction"));
|
|
|
21
35
|
exports.BaseApiAction = BaseApiAction_1.default;
|
|
22
36
|
var BaseAuthProvider_1 = __importDefault(require("./BaseAuthProvider"));
|
|
23
37
|
exports.BaseAuthProvider = BaseAuthProvider_1.default;
|
|
38
|
+
__exportStar(require("./BaseAuthProvider"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -4,18 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import Kernel from './Kernel';
|
|
6
6
|
import KernelModule from './KernelModule';
|
|
7
|
-
import KernelDB from './database/KernelDB';
|
|
8
|
-
import GKey from './database/entity/GKey';
|
|
9
7
|
export * from './actions';
|
|
10
8
|
export * from './api';
|
|
11
9
|
export * from './classes';
|
|
12
10
|
export * from './modules/crypto';
|
|
13
11
|
export * from './lib';
|
|
14
12
|
export * from '@grandlinex/core';
|
|
15
|
-
export
|
|
16
|
-
export * as bundleSQLight from '@grandlinex/bundle-sqlight';
|
|
17
|
-
export * as bundleELogger from '@grandlinex/bundle-elogger';
|
|
18
|
-
export { SQLCon } from '@grandlinex/bundle-sqlight';
|
|
19
|
-
export { PGCon } from '@grandlinex/bundle-postgresql';
|
|
20
|
-
export { KernelModule, Kernel, KernelDB, GKey };
|
|
13
|
+
export { KernelModule, Kernel };
|
|
21
14
|
export default Kernel;
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
15
|
};
|
|
17
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
-
if (mod && mod.__esModule) return mod;
|
|
19
|
-
var result = {};
|
|
20
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
-
__setModuleDefault(result, mod);
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
18
|
};
|
|
27
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.
|
|
20
|
+
exports.Kernel = exports.KernelModule = void 0;
|
|
29
21
|
/**
|
|
30
22
|
* @name Kernel Main Module
|
|
31
23
|
* @author David Nagy
|
|
@@ -34,21 +26,10 @@ var Kernel_1 = __importDefault(require("./Kernel"));
|
|
|
34
26
|
exports.Kernel = Kernel_1.default;
|
|
35
27
|
var KernelModule_1 = __importDefault(require("./KernelModule"));
|
|
36
28
|
exports.KernelModule = KernelModule_1.default;
|
|
37
|
-
var KernelDB_1 = __importDefault(require("./database/KernelDB"));
|
|
38
|
-
exports.KernelDB = KernelDB_1.default;
|
|
39
|
-
var GKey_1 = __importDefault(require("./database/entity/GKey"));
|
|
40
|
-
exports.GKey = GKey_1.default;
|
|
41
29
|
__exportStar(require("./actions"), exports);
|
|
42
30
|
__exportStar(require("./api"), exports);
|
|
43
31
|
__exportStar(require("./classes"), exports);
|
|
44
32
|
__exportStar(require("./modules/crypto"), exports);
|
|
45
33
|
__exportStar(require("./lib"), exports);
|
|
46
34
|
__exportStar(require("@grandlinex/core"), exports);
|
|
47
|
-
exports.bundlePostgreSQL = __importStar(require("@grandlinex/bundle-postgresql"));
|
|
48
|
-
exports.bundleSQLight = __importStar(require("@grandlinex/bundle-sqlight"));
|
|
49
|
-
exports.bundleELogger = __importStar(require("@grandlinex/bundle-elogger"));
|
|
50
|
-
var bundle_sqlight_1 = require("@grandlinex/bundle-sqlight");
|
|
51
|
-
Object.defineProperty(exports, "SQLCon", { enumerable: true, get: function () { return bundle_sqlight_1.SQLCon; } });
|
|
52
|
-
var bundle_postgresql_1 = require("@grandlinex/bundle-postgresql");
|
|
53
|
-
Object.defineProperty(exports, "PGCon", { enumerable: true, get: function () { return bundle_postgresql_1.PGCon; } });
|
|
54
35
|
exports.default = Kernel_1.default;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import express, { Request, Response } from 'express';
|
|
3
2
|
import { ICoreAction, ICoreBridge, ICoreCache, ICoreCClient, ICoreElement, ICoreKernel, ICoreKernelModule, ICorePresenter, ICoreService, IDataBase } from '@grandlinex/core';
|
|
4
3
|
import { BaseClient } from 'classes';
|
|
5
4
|
import { IAuthProvider, JwtToken } from '../classes/BaseAuthProvider';
|
|
6
|
-
|
|
7
|
-
export declare type ActionTypes = 'POST' | 'GET' | 'USE';
|
|
5
|
+
export declare type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
|
|
8
6
|
export interface ICClient extends ICoreCClient {
|
|
9
7
|
setAuthProvider(provider: IAuthProvider): boolean;
|
|
10
8
|
jwtVerifyAccessToken(token: string): Promise<JwtToken | null>;
|
|
11
9
|
jwtGenerateAccessToken(data: {
|
|
12
10
|
username: string;
|
|
13
11
|
}): string;
|
|
14
|
-
apiTokenValidation(username: string, token: string, requestType: string): Promise<
|
|
15
|
-
|
|
12
|
+
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
13
|
+
valid: boolean;
|
|
14
|
+
userId: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
permissionValidation(token: JwtToken, requestType: string): Promise<boolean>;
|
|
16
17
|
bearerTokenValidation(req: Request): Promise<JwtToken | null>;
|
|
17
|
-
keyStoreSave(data: string): Promise<number>;
|
|
18
|
-
keyStoreLoad(id: number): Promise<string | null>;
|
|
19
18
|
}
|
|
20
19
|
export interface IKernel extends ICoreKernel<ICClient> {
|
|
21
20
|
getAppServerPort(): number;
|
|
22
21
|
setAppServerPort(port: number): void;
|
|
23
22
|
}
|
|
24
|
-
export interface IKernelDb {
|
|
25
|
-
initNewDB(): Promise<void>;
|
|
26
|
-
setKey(secret: string, iv: Buffer, auth: Buffer): Promise<number>;
|
|
27
|
-
getKey(id: number): Promise<GKey | null>;
|
|
28
|
-
deleteKey(id: number): Promise<void>;
|
|
29
|
-
}
|
|
30
23
|
export declare type IBaseKernelModule<T extends IDataBase<any, any> | null, P extends BaseClient | null, C extends IBaseCache | null, E extends IBasePresenter | null> = ICoreKernelModule<IKernel, T, P, C, E>;
|
|
31
24
|
export declare type IBasePresenter = ICorePresenter<express.Express>;
|
|
32
25
|
export interface IBaseAction extends ICoreAction {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
2
|
import { CoreCryptoClient } from '@grandlinex/core';
|
|
3
3
|
import { ICClient, IKernel } from '../../lib';
|
|
4
|
-
import { IAuthProvider, JwtToken } from '../../classes/BaseAuthProvider';
|
|
4
|
+
import { IAuthProvider, JwtToken, JwtTokenData } from '../../classes/BaseAuthProvider';
|
|
5
5
|
export default class CryptoClient extends CoreCryptoClient implements ICClient {
|
|
6
6
|
protected authProvider: IAuthProvider | null;
|
|
7
7
|
protected kernel: IKernel;
|
|
8
|
+
protected expiresIn: string;
|
|
8
9
|
constructor(key: string, kernel: IKernel);
|
|
9
10
|
setAuthProvider(provider: IAuthProvider): boolean;
|
|
10
11
|
jwtVerifyAccessToken(token: string): Promise<JwtToken | null>;
|
|
11
|
-
jwtGenerateAccessToken(data:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
jwtGenerateAccessToken(data: JwtTokenData): string;
|
|
13
|
+
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
14
|
+
valid: boolean;
|
|
15
|
+
userId: string | null;
|
|
16
|
+
}>;
|
|
17
|
+
permissionValidation(token: JwtToken, requestType: string): Promise<boolean>;
|
|
16
18
|
bearerTokenValidation(req: Request): Promise<JwtToken | null>;
|
|
17
|
-
keyStoreSave(data: string): Promise<number>;
|
|
18
|
-
keyStoreLoad(id: number): Promise<string | null>;
|
|
19
19
|
}
|
|
@@ -59,9 +59,10 @@ var core_1 = require("@grandlinex/core");
|
|
|
59
59
|
var CryptoClient = /** @class */ (function (_super) {
|
|
60
60
|
__extends(CryptoClient, _super);
|
|
61
61
|
function CryptoClient(key, kernel) {
|
|
62
|
-
var _this = _super.call(this, key) || this;
|
|
62
|
+
var _this = _super.call(this, kernel, key) || this;
|
|
63
63
|
_this.kernel = kernel;
|
|
64
64
|
_this.authProvider = null;
|
|
65
|
+
_this.expiresIn = kernel.getConfigStore().get('JWT_EXPIRE') || '1 days';
|
|
65
66
|
return _this;
|
|
66
67
|
}
|
|
67
68
|
CryptoClient.prototype.setAuthProvider = function (provider) {
|
|
@@ -85,7 +86,7 @@ var CryptoClient = /** @class */ (function (_super) {
|
|
|
85
86
|
});
|
|
86
87
|
};
|
|
87
88
|
CryptoClient.prototype.jwtGenerateAccessToken = function (data) {
|
|
88
|
-
return jsonwebtoken_1.default.sign(data, this.AesKey, { expiresIn:
|
|
89
|
+
return jsonwebtoken_1.default.sign(data, this.AesKey, { expiresIn: this.expiresIn });
|
|
89
90
|
};
|
|
90
91
|
CryptoClient.prototype.apiTokenValidation = function (username, token, requestType) {
|
|
91
92
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -96,17 +97,26 @@ var CryptoClient = /** @class */ (function (_super) {
|
|
|
96
97
|
}
|
|
97
98
|
store = this.kernel.getConfigStore();
|
|
98
99
|
if (!store.has('SERVER_PASSWORD')) {
|
|
99
|
-
return [2 /*return*/, false];
|
|
100
|
+
return [2 /*return*/, { valid: false, userId: null }];
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
+
if (token === store.get('SERVER_PASSWORD') && username === 'admin') {
|
|
103
|
+
return [2 /*return*/, {
|
|
104
|
+
valid: true,
|
|
105
|
+
userId: 'admin',
|
|
106
|
+
}];
|
|
107
|
+
}
|
|
108
|
+
return [2 /*return*/, {
|
|
109
|
+
valid: false,
|
|
110
|
+
userId: null,
|
|
111
|
+
}];
|
|
102
112
|
});
|
|
103
113
|
});
|
|
104
114
|
};
|
|
105
|
-
CryptoClient.prototype.
|
|
115
|
+
CryptoClient.prototype.permissionValidation = function (token, requestType) {
|
|
106
116
|
return __awaiter(this, void 0, void 0, function () {
|
|
107
117
|
return __generator(this, function (_a) {
|
|
108
118
|
if (this.authProvider) {
|
|
109
|
-
return [2 /*return*/, this.authProvider.
|
|
119
|
+
return [2 /*return*/, this.authProvider.validateAccess(token, requestType)];
|
|
110
120
|
}
|
|
111
121
|
return [2 /*return*/, false];
|
|
112
122
|
});
|
|
@@ -137,34 +147,6 @@ var CryptoClient = /** @class */ (function (_super) {
|
|
|
137
147
|
});
|
|
138
148
|
});
|
|
139
149
|
};
|
|
140
|
-
CryptoClient.prototype.keyStoreSave = function (data) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
-
var db, keyCrypt;
|
|
143
|
-
return __generator(this, function (_a) {
|
|
144
|
-
db = this.kernel.getDb();
|
|
145
|
-
keyCrypt = this.encrypt(data);
|
|
146
|
-
return [2 /*return*/, db.setKey(keyCrypt.enc, keyCrypt.iv, keyCrypt.auth)];
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
CryptoClient.prototype.keyStoreLoad = function (id) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
var db, key;
|
|
153
|
-
return __generator(this, function (_a) {
|
|
154
|
-
switch (_a.label) {
|
|
155
|
-
case 0:
|
|
156
|
-
db = this.kernel.getDb();
|
|
157
|
-
return [4 /*yield*/, db.getKey(id)];
|
|
158
|
-
case 1:
|
|
159
|
-
key = _a.sent();
|
|
160
|
-
if (!key) {
|
|
161
|
-
return [2 /*return*/, null];
|
|
162
|
-
}
|
|
163
|
-
return [2 /*return*/, this.decrypt(key.secret, key.iv, key.auth)];
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
150
|
return CryptoClient;
|
|
169
151
|
}(core_1.CoreCryptoClient));
|
|
170
152
|
exports.default = CryptoClient;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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,10 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "BSD-3-Clause",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@grandlinex/
|
|
31
|
-
"@grandlinex/bundle-postgresql": "^0.21.0",
|
|
32
|
-
"@grandlinex/bundle-sqlight": "^0.21.0",
|
|
33
|
-
"@grandlinex/core": "^0.21.0",
|
|
30
|
+
"@grandlinex/core": "^0.23.1",
|
|
34
31
|
"axios": "^0.24.0",
|
|
35
32
|
"body-parser": "^1.19.1",
|
|
36
33
|
"express": "^4.17.2",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { CoreDBCon } from '@grandlinex/core';
|
|
3
|
-
import CoreDBPrefab from '@grandlinex/core/dist/classes/CoreDBPrefab';
|
|
4
|
-
import { IKernelDb } from '../lib';
|
|
5
|
-
import GKey from './entity/GKey';
|
|
6
|
-
export declare const KERNEL_DB_VERSION = "1";
|
|
7
|
-
export default class KernelDB extends CoreDBPrefab<any> implements IKernelDb {
|
|
8
|
-
private gKey;
|
|
9
|
-
constructor(db: CoreDBCon<any, any>);
|
|
10
|
-
initPrefabDB(): Promise<void>;
|
|
11
|
-
deleteKey(id: number): Promise<void>;
|
|
12
|
-
getKey(id: number): Promise<GKey | null>;
|
|
13
|
-
setKey(secret: string, iv: Buffer, auth: Buffer): Promise<number>;
|
|
14
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
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 (_) 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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
-
};
|
|
56
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
-
exports.KERNEL_DB_VERSION = void 0;
|
|
58
|
-
var core_1 = require("@grandlinex/core");
|
|
59
|
-
var CoreDBPrefab_1 = __importDefault(require("@grandlinex/core/dist/classes/CoreDBPrefab"));
|
|
60
|
-
var crypto_1 = require("crypto");
|
|
61
|
-
var GKey_1 = __importDefault(require("./entity/GKey"));
|
|
62
|
-
exports.KERNEL_DB_VERSION = '1';
|
|
63
|
-
var KernelDB = /** @class */ (function (_super) {
|
|
64
|
-
__extends(KernelDB, _super);
|
|
65
|
-
function KernelDB(db) {
|
|
66
|
-
var _this = _super.call(this, db) || this;
|
|
67
|
-
_this.gKey = _this.registerEntity(new GKey_1.default());
|
|
68
|
-
return _this;
|
|
69
|
-
}
|
|
70
|
-
KernelDB.prototype.initPrefabDB = function () {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var seed;
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
seed = (0, core_1.generateSeed)();
|
|
77
|
-
return [4 /*yield*/, this.setConfig('seed', seed)];
|
|
78
|
-
case 1:
|
|
79
|
-
_a.sent();
|
|
80
|
-
return [4 /*yield*/, this.setConfig('uid', (0, crypto_1.randomUUID)())];
|
|
81
|
-
case 2:
|
|
82
|
-
_a.sent();
|
|
83
|
-
return [2 /*return*/];
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
KernelDB.prototype.deleteKey = function (id) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
return __generator(this, function (_a) {
|
|
91
|
-
switch (_a.label) {
|
|
92
|
-
case 0: return [4 /*yield*/, this.gKey.delete(id)];
|
|
93
|
-
case 1:
|
|
94
|
-
_a.sent();
|
|
95
|
-
return [2 /*return*/];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
KernelDB.prototype.getKey = function (id) {
|
|
101
|
-
return this.gKey.getObjById(id);
|
|
102
|
-
};
|
|
103
|
-
KernelDB.prototype.setKey = function (secret, iv, auth) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
-
return __generator(this, function (_a) {
|
|
106
|
-
switch (_a.label) {
|
|
107
|
-
case 0: return [4 /*yield*/, this.gKey.createObject({ secret: secret, iv: iv, auth: auth })];
|
|
108
|
-
case 1: return [2 /*return*/, (_a.sent()).e_id];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
return KernelDB;
|
|
114
|
-
}(CoreDBPrefab_1.default));
|
|
115
|
-
exports.default = KernelDB;
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
var core_1 = require("@grandlinex/core");
|
|
28
|
-
var GKey = /** @class */ (function (_super) {
|
|
29
|
-
__extends(GKey, _super);
|
|
30
|
-
function GKey(props) {
|
|
31
|
-
var _this = _super.call(this) || this;
|
|
32
|
-
_this.secret = (props === null || props === void 0 ? void 0 : props.secret) || '';
|
|
33
|
-
_this.iv = (props === null || props === void 0 ? void 0 : props.iv) || Buffer.from('');
|
|
34
|
-
_this.auth = (props === null || props === void 0 ? void 0 : props.auth) || Buffer.from('');
|
|
35
|
-
return _this;
|
|
36
|
-
}
|
|
37
|
-
__decorate([
|
|
38
|
-
(0, core_1.Column)({
|
|
39
|
-
dataType: 'text',
|
|
40
|
-
}),
|
|
41
|
-
__metadata("design:type", String)
|
|
42
|
-
], GKey.prototype, "secret", void 0);
|
|
43
|
-
__decorate([
|
|
44
|
-
(0, core_1.Column)({
|
|
45
|
-
dataType: 'blob',
|
|
46
|
-
}),
|
|
47
|
-
__metadata("design:type", Buffer)
|
|
48
|
-
], GKey.prototype, "iv", void 0);
|
|
49
|
-
__decorate([
|
|
50
|
-
(0, core_1.Column)({
|
|
51
|
-
dataType: 'blob',
|
|
52
|
-
}),
|
|
53
|
-
__metadata("design:type", Buffer)
|
|
54
|
-
], GKey.prototype, "auth", void 0);
|
|
55
|
-
GKey = __decorate([
|
|
56
|
-
(0, core_1.Entity)('GKey', 0),
|
|
57
|
-
__metadata("design:paramtypes", [Object])
|
|
58
|
-
], GKey);
|
|
59
|
-
return GKey;
|
|
60
|
-
}(core_1.CoreEntity));
|
|
61
|
-
exports.default = GKey;
|