@grandlinex/kernel 0.30.2 → 0.30.5
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/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.js +71 -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/cjs/classes/BaseAction.js +65 -0
- package/dist/cjs/classes/BaseApiAction.js +49 -0
- package/dist/cjs/classes/BaseAuthProvider.js +5 -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 +52 -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/cjs/lib/index.js +2 -0
- package/dist/cjs/modules/crypto/CryptoClient.js +108 -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 +43 -0
- 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 +19 -0
- package/dist/mjs/classes/BaseApiAction.d.ts +9 -0
- package/dist/mjs/classes/BaseAuthProvider.d.ts +20 -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/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 +21 -0
- package/dist/{modules → mjs/modules}/crypto/CryptoClient.js +3 -1
- 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 +16 -7
- package/tsconfig-cjs.json +92 -0
- /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}/GetTokenAction.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}/BaseAction.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/BaseApiAction.d.ts +0 -0
- /package/dist/{classes → cjs/classes}/BaseAuthProvider.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/{lib → cjs/lib}/index.d.ts +0 -0
- /package/dist/{modules → cjs/modules}/crypto/CryptoClient.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 → mjs/actions}/GetTokenAction.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}/BaseAction.js +0 -0
- /package/dist/{classes → mjs/classes}/BaseApiAction.js +0 -0
- /package/dist/{classes → mjs/classes}/BaseAuthProvider.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/ExpressServerTiming.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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@grandlinex/core");
|
|
7
|
+
const CryptoClient_js_1 = __importDefault(require("./modules/crypto/CryptoClient.js"));
|
|
8
|
+
const KernelModule_js_1 = __importDefault(require("./KernelModule.js"));
|
|
9
|
+
/**
|
|
10
|
+
* @class Kernel
|
|
11
|
+
*/
|
|
12
|
+
class Kernel extends core_1.CoreKernel {
|
|
13
|
+
/**
|
|
14
|
+
* Default Constructor
|
|
15
|
+
* @param options App Name
|
|
16
|
+
*/
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super({ ...options });
|
|
19
|
+
this.setBaseModule(new KernelModule_js_1.default(this));
|
|
20
|
+
if (options.portOverride) {
|
|
21
|
+
this.debug(`use custiom api port @ ${options.portOverride}`);
|
|
22
|
+
this.expressPort = options.portOverride;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.expressPort = 9257;
|
|
26
|
+
}
|
|
27
|
+
const store = this.getConfigStore();
|
|
28
|
+
if (store.has('SERVER_PASSWORD')) {
|
|
29
|
+
this.setCryptoClient(new CryptoClient_js_1.default(CryptoClient_js_1.default.fromPW(store.get('SERVER_PASSWORD')), this));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
getAppServerPort() {
|
|
33
|
+
return this.expressPort;
|
|
34
|
+
}
|
|
35
|
+
setAppServerPort(port) {
|
|
36
|
+
this.expressPort = port;
|
|
37
|
+
}
|
|
38
|
+
responseCodeFunction(data) {
|
|
39
|
+
const { code } = data;
|
|
40
|
+
if (code < 200 || code >= 300) {
|
|
41
|
+
this.debug(data.req.path, data.req.ip, data.code);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = Kernel;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@grandlinex/core");
|
|
7
|
+
const BaseKernelModule_js_1 = __importDefault(require("./classes/BaseKernelModule.js"));
|
|
8
|
+
const KernelEndpoint_js_1 = __importDefault(require("./api/KernelEndpoint.js"));
|
|
9
|
+
const ApiVersionAction_js_1 = __importDefault(require("./actions/ApiVersionAction.js"));
|
|
10
|
+
const GetTokenAction_js_1 = __importDefault(require("./actions/GetTokenAction.js"));
|
|
11
|
+
const ApiAuthTestAction_js_1 = __importDefault(require("./actions/ApiAuthTestAction.js"));
|
|
12
|
+
class KernelModule extends BaseKernelModule_js_1.default {
|
|
13
|
+
constructor(kernel) {
|
|
14
|
+
super('base-mod', kernel);
|
|
15
|
+
this.addAction(new ApiVersionAction_js_1.default(this), new ApiAuthTestAction_js_1.default(this), new GetTokenAction_js_1.default(this));
|
|
16
|
+
}
|
|
17
|
+
async initModule() {
|
|
18
|
+
this.addService(new core_1.OfflineService(this));
|
|
19
|
+
const endpoint = new KernelEndpoint_js_1.default('api', this, this.getKernel().getAppServerPort());
|
|
20
|
+
this.setPresenter(endpoint);
|
|
21
|
+
await this.getKernel().triggerFunction('load');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = KernelModule;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_js_1 = require("../classes/index.js");
|
|
4
|
+
/**
|
|
5
|
+
* @name ApiAuthTestAction
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
class ApiAuthTestAction extends index_js_1.BaseApiAction {
|
|
9
|
+
constructor(module) {
|
|
10
|
+
super('GET', '/test/auth', module);
|
|
11
|
+
this.handler = this.handler.bind(this);
|
|
12
|
+
}
|
|
13
|
+
async handler(req, res, next, data) {
|
|
14
|
+
this.debug(data.userid);
|
|
15
|
+
res.status(200).send("It work's");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = ApiAuthTestAction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_js_1 = require("../classes/index.js");
|
|
4
|
+
/**
|
|
5
|
+
* @name ApiVersionAction
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
class ApiVersionAction extends index_js_1.BaseApiAction {
|
|
9
|
+
constructor(module) {
|
|
10
|
+
super('GET', '/version', module);
|
|
11
|
+
this.handler = this.handler.bind(this);
|
|
12
|
+
this.setMode(index_js_1.ActionMode.DMZ);
|
|
13
|
+
}
|
|
14
|
+
async handler(req, res, next, data, ex) {
|
|
15
|
+
ex.done();
|
|
16
|
+
res.status(200).send({ api: 1 });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = ApiVersionAction;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_js_1 = require("../classes/index.js");
|
|
4
|
+
/**
|
|
5
|
+
* @openapi
|
|
6
|
+
* /token:
|
|
7
|
+
* post:
|
|
8
|
+
* summary: Get Bearer for user.
|
|
9
|
+
* tags:
|
|
10
|
+
* - Kernel
|
|
11
|
+
* description: Returns JWT.
|
|
12
|
+
* responses:
|
|
13
|
+
* '200':
|
|
14
|
+
* description: OK
|
|
15
|
+
* content:
|
|
16
|
+
* application/json:
|
|
17
|
+
* schema:
|
|
18
|
+
* type: object
|
|
19
|
+
* properties:
|
|
20
|
+
* token:
|
|
21
|
+
* type: string
|
|
22
|
+
* '403':
|
|
23
|
+
* description: Not Authorized
|
|
24
|
+
* requestBody:
|
|
25
|
+
* required: true
|
|
26
|
+
* content:
|
|
27
|
+
* application/json:
|
|
28
|
+
* schema:
|
|
29
|
+
* type: object
|
|
30
|
+
* properties:
|
|
31
|
+
* username:
|
|
32
|
+
* type: string
|
|
33
|
+
* token:
|
|
34
|
+
* type: string
|
|
35
|
+
*/
|
|
36
|
+
class GetTokenAction extends index_js_1.BaseApiAction {
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param module Parent Module
|
|
40
|
+
*/
|
|
41
|
+
constructor(module) {
|
|
42
|
+
super('POST', '/token', module);
|
|
43
|
+
this.handler = this.handler.bind(this);
|
|
44
|
+
this.setMode(index_js_1.ActionMode.DMZ);
|
|
45
|
+
}
|
|
46
|
+
async handler(req, res, next, data, ex) {
|
|
47
|
+
const cc = this.getKernel().getCryptoClient();
|
|
48
|
+
if (!req.body.token) {
|
|
49
|
+
res.status(400).send('no token');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!req.body.username) {
|
|
53
|
+
res.status(401).send('no username');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { username, token } = req.body;
|
|
57
|
+
const valid = await ex.timing.startFunc('validation', () => cc.apiTokenValidation(username, token, 'api'));
|
|
58
|
+
if (valid.valid && valid.userId) {
|
|
59
|
+
const jwt = cc.jwtGenerateAccessToken({
|
|
60
|
+
userid: valid.userId,
|
|
61
|
+
username,
|
|
62
|
+
});
|
|
63
|
+
ex.done();
|
|
64
|
+
res.status(200).send({ token: jwt });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
res.status(403).send('no no no ...');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = GetTokenAction;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GetTokenAction = exports.ApiAuthTestAction = exports.ApiVersionAction = void 0;
|
|
7
|
+
const ApiAuthTestAction_js_1 = __importDefault(require("./ApiAuthTestAction.js"));
|
|
8
|
+
exports.ApiAuthTestAction = ApiAuthTestAction_js_1.default;
|
|
9
|
+
const ApiVersionAction_js_1 = __importDefault(require("./ApiVersionAction.js"));
|
|
10
|
+
exports.ApiVersionAction = ApiVersionAction_js_1.default;
|
|
11
|
+
const GetTokenAction_js_1 = __importDefault(require("./GetTokenAction.js"));
|
|
12
|
+
exports.GetTokenAction = GetTokenAction_js_1.default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const BaseEndpoint_js_1 = __importDefault(require("../classes/BaseEndpoint.js"));
|
|
7
|
+
class KernelEndpoint extends BaseEndpoint_js_1.default {
|
|
8
|
+
}
|
|
9
|
+
exports.default = KernelEndpoint;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.KernelEndpoint = void 0;
|
|
7
|
+
const KernelEndpoint_js_1 = __importDefault(require("./KernelEndpoint.js"));
|
|
8
|
+
exports.KernelEndpoint = KernelEndpoint_js_1.default;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionMode = void 0;
|
|
4
|
+
const core_1 = require("@grandlinex/core");
|
|
5
|
+
const index_js_1 = require("./timing/index.js");
|
|
6
|
+
var ActionMode;
|
|
7
|
+
(function (ActionMode) {
|
|
8
|
+
ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
|
|
9
|
+
ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
|
|
10
|
+
ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
|
|
11
|
+
})(ActionMode = exports.ActionMode || (exports.ActionMode = {}));
|
|
12
|
+
class BaseAction extends core_1.CoreAction {
|
|
13
|
+
constructor(chanel, module) {
|
|
14
|
+
super(chanel, module);
|
|
15
|
+
this.secureHandler = this.secureHandler.bind(this);
|
|
16
|
+
this.mode = ActionMode.DEFAULT;
|
|
17
|
+
}
|
|
18
|
+
async secureHandler(req, res, next) {
|
|
19
|
+
const extension = this.initExtension(res);
|
|
20
|
+
const auth = extension.timing.start('auth');
|
|
21
|
+
res.on('finish', () => {
|
|
22
|
+
this.getKernel().responseCodeFunction({
|
|
23
|
+
code: res.statusCode,
|
|
24
|
+
req,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
const cc = this.getKernel().getCryptoClient();
|
|
28
|
+
if (!cc) {
|
|
29
|
+
res.status(504).send('internal server error');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (this.mode === ActionMode.DMZ) {
|
|
33
|
+
auth.stop();
|
|
34
|
+
await this.handler(req, res, next, null, extension);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const dat = await cc.bearerTokenValidation(req);
|
|
38
|
+
auth.stop();
|
|
39
|
+
if (dat && typeof dat !== 'number') {
|
|
40
|
+
await this.handler(req, res, next, dat, extension);
|
|
41
|
+
}
|
|
42
|
+
else if (this.mode === ActionMode.DMZ_WITH_USER) {
|
|
43
|
+
await this.handler(req, res, next, null, extension);
|
|
44
|
+
}
|
|
45
|
+
else if (dat) {
|
|
46
|
+
res.sendStatus(dat);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
res.status(401).send('no no no ...');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
setMode(mode) {
|
|
53
|
+
this.mode = mode;
|
|
54
|
+
}
|
|
55
|
+
initExtension(res) {
|
|
56
|
+
const [el, fx] = index_js_1.ExpressServerTiming.init(this, res);
|
|
57
|
+
return {
|
|
58
|
+
done: () => {
|
|
59
|
+
fx();
|
|
60
|
+
},
|
|
61
|
+
timing: el,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.default = BaseAction;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const BaseAction_js_1 = __importDefault(require("./BaseAction.js"));
|
|
7
|
+
class BaseApiAction extends BaseAction_js_1.default {
|
|
8
|
+
constructor(type, chanel, module, extMod) {
|
|
9
|
+
super(chanel, module);
|
|
10
|
+
this.exmod = extMod;
|
|
11
|
+
this.type = type;
|
|
12
|
+
}
|
|
13
|
+
register() {
|
|
14
|
+
let endpoint;
|
|
15
|
+
if (this.exmod) {
|
|
16
|
+
endpoint = this.exmod.getPresenter();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
endpoint = this.getModule().getPresenter();
|
|
20
|
+
}
|
|
21
|
+
if (endpoint) {
|
|
22
|
+
this.debug(`register ${this.type} ${this.getName()}`);
|
|
23
|
+
const app = endpoint.getApp();
|
|
24
|
+
switch (this.type) {
|
|
25
|
+
case 'POST':
|
|
26
|
+
app.post(this.getName(), this.secureHandler);
|
|
27
|
+
break;
|
|
28
|
+
case 'USE':
|
|
29
|
+
app.use(this.getName(), this.secureHandler);
|
|
30
|
+
break;
|
|
31
|
+
case 'PATCH':
|
|
32
|
+
app.patch(this.getName(), this.secureHandler);
|
|
33
|
+
break;
|
|
34
|
+
case 'DELETE':
|
|
35
|
+
app.delete(this.getName(), this.secureHandler);
|
|
36
|
+
break;
|
|
37
|
+
case 'GET':
|
|
38
|
+
default:
|
|
39
|
+
app.get(this.getName(), this.secureHandler);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.error(`on register -> ${this.getName()}`);
|
|
45
|
+
this.error(`No Endpoint found`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = BaseApiAction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import express, { Express } from 'express';
|
|
4
|
+
import http from 'http';
|
|
5
|
+
import { CorePresenter, IDataBase } from '@grandlinex/core';
|
|
6
|
+
import { IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
7
|
+
import { XRequest, XResponse } from '../lib/express.js';
|
|
8
|
+
export declare function keepRawBody(req: XRequest, res: XResponse, buf: Buffer, encoding: string): void;
|
|
9
|
+
export default abstract class BaseEndpoint<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 CorePresenter<express.Express, K, T, P, C, E> implements IBasePresenter {
|
|
10
|
+
protected appServer: express.Express;
|
|
11
|
+
protected httpServer: http.Server;
|
|
12
|
+
protected port: number;
|
|
13
|
+
constructor(chanel: string, module: IBaseKernelModule<any, any, any, any>, port: number);
|
|
14
|
+
appServerOverride(app: Express): void;
|
|
15
|
+
start(): Promise<boolean>;
|
|
16
|
+
stop(): Promise<boolean>;
|
|
17
|
+
getApp(): express.Express;
|
|
18
|
+
getServer(): http.Server;
|
|
19
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.keepRawBody = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const http_1 = __importDefault(require("http"));
|
|
9
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
10
|
+
const core_1 = require("@grandlinex/core");
|
|
11
|
+
function keepRawBody(req, res, buf, encoding) {
|
|
12
|
+
if (req.headers['content-type']?.startsWith('application/json') &&
|
|
13
|
+
buf &&
|
|
14
|
+
buf.length) {
|
|
15
|
+
try {
|
|
16
|
+
req.rawBody = buf.toString(encoding || 'utf8');
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
req.rawBody = null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.keepRawBody = keepRawBody;
|
|
24
|
+
class BaseEndpoint extends core_1.CorePresenter {
|
|
25
|
+
constructor(chanel, module, port) {
|
|
26
|
+
super(`endpoint-${chanel}`, module);
|
|
27
|
+
this.port = port;
|
|
28
|
+
this.appServer = (0, express_1.default)();
|
|
29
|
+
this.appServer.use(body_parser_1.default.json({ verify: keepRawBody }));
|
|
30
|
+
this.httpServer = http_1.default.createServer(this.appServer);
|
|
31
|
+
}
|
|
32
|
+
appServerOverride(app) {
|
|
33
|
+
this.appServer = app;
|
|
34
|
+
this.httpServer = http_1.default.createServer(this.appServer);
|
|
35
|
+
}
|
|
36
|
+
start() {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
this.httpServer
|
|
39
|
+
.listen(this.port, () => {
|
|
40
|
+
this.info(`Endpoint listen on ${this.port}`);
|
|
41
|
+
resolve(true);
|
|
42
|
+
})
|
|
43
|
+
.on('error', (err) => {
|
|
44
|
+
this.error(err);
|
|
45
|
+
resolve(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
stop() {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
if (this.httpServer) {
|
|
52
|
+
this.httpServer.close((err) => (err ? resolve(false) : resolve(true)));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getApp() {
|
|
57
|
+
return this.appServer;
|
|
58
|
+
}
|
|
59
|
+
getServer() {
|
|
60
|
+
return this.httpServer;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.default = BaseEndpoint;
|
|
@@ -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,54 @@
|
|
|
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
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.ActionMode = exports.keepRawBody = exports.BaseBridge = exports.BaseClient = exports.BaseAction = exports.BaseCache = exports.BaseElement = exports.BaseEndpoint = exports.BaseApiAction = exports.BaseService = exports.BaseKernelModule = exports.BaseAuthProvider = exports.BaseLoopService = void 0;
|
|
33
|
+
const core_1 = require("@grandlinex/core");
|
|
34
|
+
Object.defineProperty(exports, "BaseBridge", { enumerable: true, get: function () { return core_1.CoreBridge; } });
|
|
35
|
+
Object.defineProperty(exports, "BaseCache", { enumerable: true, get: function () { return core_1.CoreCache; } });
|
|
36
|
+
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return core_1.CoreClient; } });
|
|
37
|
+
Object.defineProperty(exports, "BaseElement", { enumerable: true, get: function () { return core_1.CoreElement; } });
|
|
38
|
+
Object.defineProperty(exports, "BaseLoopService", { enumerable: true, get: function () { return core_1.CoreLoopService; } });
|
|
39
|
+
Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return core_1.CoreService; } });
|
|
40
|
+
const BaseAction_js_1 = __importStar(require("./BaseAction.js"));
|
|
41
|
+
exports.BaseAction = BaseAction_js_1.default;
|
|
42
|
+
Object.defineProperty(exports, "ActionMode", { enumerable: true, get: function () { return BaseAction_js_1.ActionMode; } });
|
|
43
|
+
const BaseEndpoint_js_1 = __importStar(require("./BaseEndpoint.js"));
|
|
44
|
+
exports.BaseEndpoint = BaseEndpoint_js_1.default;
|
|
45
|
+
Object.defineProperty(exports, "keepRawBody", { enumerable: true, get: function () { return BaseEndpoint_js_1.keepRawBody; } });
|
|
46
|
+
const BaseKernelModule_js_1 = __importDefault(require("./BaseKernelModule.js"));
|
|
47
|
+
exports.BaseKernelModule = BaseKernelModule_js_1.default;
|
|
48
|
+
const BaseApiAction_js_1 = __importDefault(require("./BaseApiAction.js"));
|
|
49
|
+
exports.BaseApiAction = BaseApiAction_js_1.default;
|
|
50
|
+
const BaseAuthProvider_js_1 = __importDefault(require("./BaseAuthProvider.js"));
|
|
51
|
+
exports.BaseAuthProvider = BaseAuthProvider_js_1.default;
|
|
52
|
+
__exportStar(require("./BaseAction.js"), exports);
|
|
53
|
+
__exportStar(require("./BaseAuthProvider.js"), exports);
|
|
54
|
+
__exportStar(require("./timing/index.js"), exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ServerTiming_js_1 = __importDefault(require("./ServerTiming.js"));
|
|
7
|
+
class ExpressServerTiming {
|
|
8
|
+
constructor(baseApiAction) {
|
|
9
|
+
this.timing = new ServerTiming_js_1.default();
|
|
10
|
+
this.baseApiAction = baseApiAction;
|
|
11
|
+
}
|
|
12
|
+
start(chanel) {
|
|
13
|
+
return this.timing.start(chanel);
|
|
14
|
+
}
|
|
15
|
+
async startFunc(chanel, fc) {
|
|
16
|
+
return this.timing.startFunc(chanel, fc);
|
|
17
|
+
}
|
|
18
|
+
async dbQuery(fc) {
|
|
19
|
+
return this.timing.startFunc('db', fc);
|
|
20
|
+
}
|
|
21
|
+
getHeader() {
|
|
22
|
+
const out = [];
|
|
23
|
+
this.timing.map.forEach((element, key) => {
|
|
24
|
+
let dur = 0;
|
|
25
|
+
element.forEach((el) => {
|
|
26
|
+
dur += el.getDuration();
|
|
27
|
+
});
|
|
28
|
+
out.push(`${key};dur=${dur}`);
|
|
29
|
+
});
|
|
30
|
+
return out.join(', ');
|
|
31
|
+
}
|
|
32
|
+
addHeader(res) {
|
|
33
|
+
if (this.timing.map.size > 0 &&
|
|
34
|
+
this.baseApiAction.getKernel().getDevMode()) {
|
|
35
|
+
const a = ['Server-Timing', this.getHeader()];
|
|
36
|
+
res.setHeader(a[0], a[1]);
|
|
37
|
+
this.baseApiAction.debug(a);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static init(baseApiAction, res) {
|
|
41
|
+
const el = new ExpressServerTiming(baseApiAction);
|
|
42
|
+
const total = el.start('total');
|
|
43
|
+
return [
|
|
44
|
+
el,
|
|
45
|
+
() => {
|
|
46
|
+
total.stop();
|
|
47
|
+
el.addHeader(res);
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = ExpressServerTiming;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ServerTimingElement_js_1 = __importDefault(require("./ServerTimingElement.js"));
|
|
7
|
+
class ServerTiming {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.map = new Map();
|
|
10
|
+
}
|
|
11
|
+
start(chanel) {
|
|
12
|
+
return new ServerTimingElement_js_1.default(this, chanel);
|
|
13
|
+
}
|
|
14
|
+
async startFunc(chanel, fc) {
|
|
15
|
+
const el = new ServerTimingElement_js_1.default(this, chanel);
|
|
16
|
+
const content = await fc();
|
|
17
|
+
el.stop();
|
|
18
|
+
return content;
|
|
19
|
+
}
|
|
20
|
+
completeElement(e) {
|
|
21
|
+
const cur = this.map.get(e.chanel) || [];
|
|
22
|
+
cur.push(e);
|
|
23
|
+
this.map.set(e.chanel, cur);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = ServerTiming;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ServerTimingElement {
|
|
4
|
+
constructor(el, chanel) {
|
|
5
|
+
this.el = el;
|
|
6
|
+
this.chanel = chanel;
|
|
7
|
+
this.start = new Date().getTime();
|
|
8
|
+
this.end = -1;
|
|
9
|
+
}
|
|
10
|
+
stop() {
|
|
11
|
+
if (this.end === -1) {
|
|
12
|
+
this.end = new Date().getTime();
|
|
13
|
+
this.el.completeElement(this);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
getDuration() {
|
|
17
|
+
if (this.end === -1) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
return this.end - this.start;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = ServerTimingElement;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ServerTiming = exports.ServerTimingElement = exports.ExpressServerTiming = void 0;
|
|
7
|
+
const ExpressServerTiming_js_1 = __importDefault(require("./ExpressServerTiming.js"));
|
|
8
|
+
exports.ExpressServerTiming = ExpressServerTiming_js_1.default;
|
|
9
|
+
const ServerTiming_js_1 = __importDefault(require("./ServerTiming.js"));
|
|
10
|
+
exports.ServerTiming = ServerTiming_js_1.default;
|
|
11
|
+
const ServerTimingElement_js_1 = __importDefault(require("./ServerTimingElement.js"));
|
|
12
|
+
exports.ServerTimingElement = ServerTimingElement_js_1.default;
|
|
@@ -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;
|