@grandlinex/kernel 0.28.1 → 0.30.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 +5 -0
- package/dist/Kernel.js +7 -13
- package/dist/KernelModule.js +13 -30
- package/dist/actions/ApiAuthTestAction.js +5 -19
- package/dist/actions/ApiVersionAction.js +7 -21
- package/dist/actions/GetTokenAction.js +27 -41
- package/dist/actions/index.js +4 -12
- package/dist/api/KernelEndpoint.js +2 -8
- package/dist/api/index.js +3 -8
- package/dist/classes/BaseAction.js +37 -52
- package/dist/classes/BaseApiAction.js +2 -8
- package/dist/classes/BaseAuthProvider.js +1 -4
- package/dist/classes/BaseEndpoint.js +11 -20
- package/dist/classes/BaseKernelModule.js +2 -5
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.js +10 -52
- package/dist/classes/timing/ExpressServerTiming.js +7 -26
- package/dist/classes/timing/ServerTiming.js +8 -25
- package/dist/classes/timing/ServerTimingElement.js +1 -4
- package/dist/classes/timing/index.js +4 -12
- package/dist/index.js +11 -32
- package/dist/lib/express.js +1 -2
- package/dist/lib/index.js +1 -2
- package/dist/modules/crypto/CryptoClient.js +44 -85
- package/dist/modules/crypto/index.js +3 -23
- package/dist/modules/crypto/utils/cors.js +1 -5
- package/package.json +24 -22
package/CHANGELOG.md
CHANGED
package/dist/Kernel.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const core_1 = __importDefault(require("@grandlinex/core"));
|
|
7
|
-
const CryptoClient_1 = __importDefault(require("./modules/crypto/CryptoClient"));
|
|
8
|
-
const KernelModule_1 = __importDefault(require("./KernelModule"));
|
|
1
|
+
import CoreKernel from '@grandlinex/core';
|
|
2
|
+
import CryptoClient from './modules/crypto/CryptoClient';
|
|
3
|
+
import KernelModule from './KernelModule';
|
|
9
4
|
/**
|
|
10
5
|
* @class Kernel
|
|
11
6
|
*/
|
|
12
|
-
class Kernel extends
|
|
7
|
+
export default class Kernel extends CoreKernel {
|
|
13
8
|
/**
|
|
14
9
|
* Default Constructor
|
|
15
10
|
* @param options App Name
|
|
16
11
|
*/
|
|
17
12
|
constructor(options) {
|
|
18
|
-
super(
|
|
19
|
-
this.setBaseModule(new
|
|
13
|
+
super({ ...options });
|
|
14
|
+
this.setBaseModule(new KernelModule(this));
|
|
20
15
|
if (options.portOverride) {
|
|
21
16
|
this.debug(`use custiom api port @ ${options.portOverride}`);
|
|
22
17
|
this.expressPort = options.portOverride;
|
|
@@ -26,7 +21,7 @@ class Kernel extends core_1.default {
|
|
|
26
21
|
}
|
|
27
22
|
const store = this.getConfigStore();
|
|
28
23
|
if (store.has('SERVER_PASSWORD')) {
|
|
29
|
-
this.setCryptoClient(new
|
|
24
|
+
this.setCryptoClient(new CryptoClient(CryptoClient.fromPW(store.get('SERVER_PASSWORD')), this));
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
getAppServerPort() {
|
|
@@ -42,4 +37,3 @@ class Kernel extends core_1.default {
|
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
39
|
}
|
|
45
|
-
exports.default = Kernel;
|
package/dist/KernelModule.js
CHANGED
|
@@ -1,35 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const core_1 = require("@grandlinex/core");
|
|
16
|
-
const BaseKernelModule_1 = __importDefault(require("./classes/BaseKernelModule"));
|
|
17
|
-
const KernelEndpoint_1 = __importDefault(require("./api/KernelEndpoint"));
|
|
18
|
-
const ApiVersionAction_1 = __importDefault(require("./actions/ApiVersionAction"));
|
|
19
|
-
const GetTokenAction_1 = __importDefault(require("./actions/GetTokenAction"));
|
|
20
|
-
const ApiAuthTestAction_1 = __importDefault(require("./actions/ApiAuthTestAction"));
|
|
21
|
-
class KernelModule extends BaseKernelModule_1.default {
|
|
1
|
+
import { OfflineService } from '@grandlinex/core';
|
|
2
|
+
import BaseKernelModule from './classes/BaseKernelModule';
|
|
3
|
+
import KernelEndpoint from './api/KernelEndpoint';
|
|
4
|
+
import ApiVersionAction from './actions/ApiVersionAction';
|
|
5
|
+
import GetTokenAction from './actions/GetTokenAction';
|
|
6
|
+
import ApiAuthTestAction from './actions/ApiAuthTestAction';
|
|
7
|
+
export default class KernelModule extends BaseKernelModule {
|
|
22
8
|
constructor(kernel) {
|
|
23
9
|
super('base-mod', kernel);
|
|
24
|
-
this.addAction(new
|
|
25
|
-
this.addService(new core_1.OfflineService(this));
|
|
26
|
-
const endpoint = new KernelEndpoint_1.default('api', this, this.getKernel().getAppServerPort());
|
|
27
|
-
this.setPresenter(endpoint);
|
|
10
|
+
this.addAction(new ApiVersionAction(this), new ApiAuthTestAction(this), new GetTokenAction(this));
|
|
28
11
|
}
|
|
29
|
-
initModule() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
async initModule() {
|
|
13
|
+
this.addService(new OfflineService(this));
|
|
14
|
+
const endpoint = new KernelEndpoint('api', this, this.getKernel().getAppServerPort());
|
|
15
|
+
this.setPresenter(endpoint);
|
|
16
|
+
await this.getKernel().triggerFunction('load');
|
|
33
17
|
}
|
|
34
18
|
}
|
|
35
|
-
exports.default = KernelModule;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const classes_1 = require("../classes");
|
|
1
|
+
import { BaseApiAction } from '../classes';
|
|
13
2
|
/**
|
|
14
3
|
* @name ApiAuthTestAction
|
|
15
4
|
*
|
|
@@ -30,16 +19,13 @@ const classes_1 = require("../classes");
|
|
|
30
19
|
* description: invalid token / not authorized
|
|
31
20
|
*
|
|
32
21
|
*/
|
|
33
|
-
class ApiAuthTestAction extends
|
|
22
|
+
export default class ApiAuthTestAction extends BaseApiAction {
|
|
34
23
|
constructor(module) {
|
|
35
24
|
super('GET', '/test/auth', module);
|
|
36
25
|
this.handler = this.handler.bind(this);
|
|
37
26
|
}
|
|
38
|
-
handler(req, res, next, data) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
res.status(200).send("It work's");
|
|
42
|
-
});
|
|
27
|
+
async handler(req, res, next, data) {
|
|
28
|
+
this.debug(data.userid);
|
|
29
|
+
res.status(200).send("It work's");
|
|
43
30
|
}
|
|
44
31
|
}
|
|
45
|
-
exports.default = ApiAuthTestAction;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const classes_1 = require("../classes");
|
|
13
|
-
const BaseAction_1 = require("../classes/BaseAction");
|
|
1
|
+
import { BaseApiAction } from '../classes';
|
|
2
|
+
import { ActionMode } from '../classes/BaseAction';
|
|
14
3
|
/**
|
|
15
4
|
* @name ApiVersionAction
|
|
16
5
|
*
|
|
@@ -34,17 +23,14 @@ const BaseAction_1 = require("../classes/BaseAction");
|
|
|
34
23
|
* description: invalid token / not authorized
|
|
35
24
|
*
|
|
36
25
|
*/
|
|
37
|
-
class ApiVersionAction extends
|
|
26
|
+
export default class ApiVersionAction extends BaseApiAction {
|
|
38
27
|
constructor(module) {
|
|
39
28
|
super('GET', '/version', module);
|
|
40
29
|
this.handler = this.handler.bind(this);
|
|
41
|
-
this.setMode(
|
|
30
|
+
this.setMode(ActionMode.DMZ);
|
|
42
31
|
}
|
|
43
|
-
handler(req, res, next, data, ex) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
res.status(200).send({ api: 1 });
|
|
47
|
-
});
|
|
32
|
+
async handler(req, res, next, data, ex) {
|
|
33
|
+
ex.done();
|
|
34
|
+
res.status(200).send({ api: 1 });
|
|
48
35
|
}
|
|
49
36
|
}
|
|
50
|
-
exports.default = ApiVersionAction;
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const classes_1 = require("../classes");
|
|
13
|
-
const BaseAction_1 = require("../classes/BaseAction");
|
|
1
|
+
import { BaseApiAction } from '../classes';
|
|
2
|
+
import { ActionMode } from '../classes/BaseAction';
|
|
14
3
|
/**
|
|
15
4
|
* @openapi
|
|
16
5
|
* /token:
|
|
@@ -43,7 +32,7 @@ const BaseAction_1 = require("../classes/BaseAction");
|
|
|
43
32
|
* token:
|
|
44
33
|
* type: string
|
|
45
34
|
*/
|
|
46
|
-
class GetTokenAction extends
|
|
35
|
+
export default class GetTokenAction extends BaseApiAction {
|
|
47
36
|
/**
|
|
48
37
|
*
|
|
49
38
|
* @param module Parent Module
|
|
@@ -51,33 +40,30 @@ class GetTokenAction extends classes_1.BaseApiAction {
|
|
|
51
40
|
constructor(module) {
|
|
52
41
|
super('POST', '/token', module);
|
|
53
42
|
this.handler = this.handler.bind(this);
|
|
54
|
-
this.setMode(
|
|
43
|
+
this.setMode(ActionMode.DMZ);
|
|
55
44
|
}
|
|
56
|
-
handler(req, res, next, data, ex) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
});
|
|
45
|
+
async handler(req, res, next, data, ex) {
|
|
46
|
+
const cc = this.getKernel().getCryptoClient();
|
|
47
|
+
if (!req.body.token) {
|
|
48
|
+
res.status(400).send('no token');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!req.body.username) {
|
|
52
|
+
res.status(401).send('no username');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const { username, token } = req.body;
|
|
56
|
+
const valid = await ex.timing.startFunc('validation', () => cc.apiTokenValidation(username, token, 'api'));
|
|
57
|
+
if (valid.valid && valid.userId) {
|
|
58
|
+
const jwt = cc.jwtGenerateAccessToken({
|
|
59
|
+
userid: valid.userId,
|
|
60
|
+
username,
|
|
61
|
+
});
|
|
62
|
+
ex.done();
|
|
63
|
+
res.status(200).send({ token: jwt });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
res.status(403).send('no no no ...');
|
|
67
|
+
}
|
|
81
68
|
}
|
|
82
69
|
}
|
|
83
|
-
exports.default = GetTokenAction;
|
package/dist/actions/index.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GetTokenAction = exports.ApiAuthTestAction = exports.ApiVersionAction = void 0;
|
|
7
|
-
const ApiAuthTestAction_1 = __importDefault(require("./ApiAuthTestAction"));
|
|
8
|
-
exports.ApiAuthTestAction = ApiAuthTestAction_1.default;
|
|
9
|
-
const ApiVersionAction_1 = __importDefault(require("./ApiVersionAction"));
|
|
10
|
-
exports.ApiVersionAction = ApiVersionAction_1.default;
|
|
11
|
-
const GetTokenAction_1 = __importDefault(require("./GetTokenAction"));
|
|
12
|
-
exports.GetTokenAction = GetTokenAction_1.default;
|
|
1
|
+
import ApiAuthTestAction from './ApiAuthTestAction';
|
|
2
|
+
import ApiVersionAction from './ApiVersionAction';
|
|
3
|
+
import GetTokenAction from './GetTokenAction';
|
|
4
|
+
export { ApiVersionAction, ApiAuthTestAction, GetTokenAction };
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const BaseEndpoint_1 = __importDefault(require("../classes/BaseEndpoint"));
|
|
7
|
-
class KernelEndpoint extends BaseEndpoint_1.default {
|
|
1
|
+
import BaseEndpoint from '../classes/BaseEndpoint';
|
|
2
|
+
export default class KernelEndpoint extends BaseEndpoint {
|
|
8
3
|
}
|
|
9
|
-
exports.default = KernelEndpoint;
|
package/dist/api/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.KernelEndpoint = void 0;
|
|
7
|
-
const KernelEndpoint_1 = __importDefault(require("./KernelEndpoint"));
|
|
8
|
-
exports.KernelEndpoint = KernelEndpoint_1.default;
|
|
1
|
+
import KernelEndpoint from './KernelEndpoint';
|
|
2
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
3
|
+
export { KernelEndpoint };
|
|
@@ -1,70 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ActionMode = void 0;
|
|
13
|
-
const core_1 = require("@grandlinex/core");
|
|
14
|
-
const timing_1 = require("./timing");
|
|
15
|
-
var ActionMode;
|
|
1
|
+
import { CoreAction } from '@grandlinex/core';
|
|
2
|
+
import { ExpressServerTiming } from './timing';
|
|
3
|
+
export var ActionMode;
|
|
16
4
|
(function (ActionMode) {
|
|
17
5
|
ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
|
|
18
6
|
ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
|
|
19
7
|
ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
|
|
20
|
-
})(ActionMode
|
|
21
|
-
class BaseAction extends
|
|
8
|
+
})(ActionMode || (ActionMode = {}));
|
|
9
|
+
export default class BaseAction extends CoreAction {
|
|
22
10
|
constructor(chanel, module) {
|
|
23
11
|
super(chanel, module);
|
|
24
12
|
this.secureHandler = this.secureHandler.bind(this);
|
|
25
13
|
this.mode = ActionMode.DEFAULT;
|
|
26
14
|
}
|
|
27
|
-
secureHandler(req, res, next) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
req,
|
|
35
|
-
});
|
|
15
|
+
async secureHandler(req, res, next) {
|
|
16
|
+
const extension = this.initExtension(res);
|
|
17
|
+
const auth = extension.timing.start('auth');
|
|
18
|
+
res.on('finish', () => {
|
|
19
|
+
this.getKernel().responseCodeFunction({
|
|
20
|
+
code: res.statusCode,
|
|
21
|
+
req,
|
|
36
22
|
});
|
|
37
|
-
const cc = this.getKernel().getCryptoClient();
|
|
38
|
-
if (!cc) {
|
|
39
|
-
res.status(504).send('internal server error');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (this.mode === ActionMode.DMZ) {
|
|
43
|
-
auth.stop();
|
|
44
|
-
yield this.handler(req, res, next, null, extension);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const dat = yield cc.bearerTokenValidation(req);
|
|
48
|
-
auth.stop();
|
|
49
|
-
if (dat && typeof dat !== 'number') {
|
|
50
|
-
yield this.handler(req, res, next, dat, extension);
|
|
51
|
-
}
|
|
52
|
-
else if (this.mode === ActionMode.DMZ_WITH_USER) {
|
|
53
|
-
yield this.handler(req, res, next, null, extension);
|
|
54
|
-
}
|
|
55
|
-
else if (dat) {
|
|
56
|
-
res.sendStatus(dat);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
res.status(401).send('no no no ...');
|
|
60
|
-
}
|
|
61
23
|
});
|
|
24
|
+
const cc = this.getKernel().getCryptoClient();
|
|
25
|
+
if (!cc) {
|
|
26
|
+
res.status(504).send('internal server error');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (this.mode === ActionMode.DMZ) {
|
|
30
|
+
auth.stop();
|
|
31
|
+
await this.handler(req, res, next, null, extension);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const dat = await cc.bearerTokenValidation(req);
|
|
35
|
+
auth.stop();
|
|
36
|
+
if (dat && typeof dat !== 'number') {
|
|
37
|
+
await this.handler(req, res, next, dat, extension);
|
|
38
|
+
}
|
|
39
|
+
else if (this.mode === ActionMode.DMZ_WITH_USER) {
|
|
40
|
+
await this.handler(req, res, next, null, extension);
|
|
41
|
+
}
|
|
42
|
+
else if (dat) {
|
|
43
|
+
res.sendStatus(dat);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
res.status(401).send('no no no ...');
|
|
47
|
+
}
|
|
62
48
|
}
|
|
63
49
|
setMode(mode) {
|
|
64
50
|
this.mode = mode;
|
|
65
51
|
}
|
|
66
52
|
initExtension(res) {
|
|
67
|
-
const [el, fx] =
|
|
53
|
+
const [el, fx] = ExpressServerTiming.init(this, res);
|
|
68
54
|
return {
|
|
69
55
|
done: () => {
|
|
70
56
|
fx();
|
|
@@ -73,4 +59,3 @@ class BaseAction extends core_1.CoreAction {
|
|
|
73
59
|
};
|
|
74
60
|
}
|
|
75
61
|
}
|
|
76
|
-
exports.default = BaseAction;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const BaseAction_1 = __importDefault(require("./BaseAction"));
|
|
7
|
-
class BaseApiAction extends BaseAction_1.default {
|
|
1
|
+
import BaseAction from './BaseAction';
|
|
2
|
+
export default class BaseApiAction extends BaseAction {
|
|
8
3
|
constructor(type, chanel, module, extMod) {
|
|
9
4
|
super(chanel, module);
|
|
10
5
|
this.exmod = extMod;
|
|
@@ -46,4 +41,3 @@ class BaseApiAction extends BaseAction_1.default {
|
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
|
-
exports.default = BaseApiAction;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const http_1 = __importDefault(require("http"));
|
|
9
|
-
const body_parser_1 = require("body-parser");
|
|
10
|
-
const core_1 = require("@grandlinex/core");
|
|
11
|
-
function keepRawBody(req, res, buf, encoding) {
|
|
12
|
-
var _a;
|
|
13
|
-
if (((_a = req.headers['content-type']) === null || _a === void 0 ? void 0 : _a.startsWith('application/json')) &&
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { json } from 'body-parser';
|
|
4
|
+
import { CorePresenter } from '@grandlinex/core';
|
|
5
|
+
export function keepRawBody(req, res, buf, encoding) {
|
|
6
|
+
if (req.headers['content-type']?.startsWith('application/json') &&
|
|
14
7
|
buf &&
|
|
15
8
|
buf.length) {
|
|
16
9
|
try {
|
|
@@ -21,18 +14,17 @@ function keepRawBody(req, res, buf, encoding) {
|
|
|
21
14
|
}
|
|
22
15
|
}
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
class BaseEndpoint extends core_1.CorePresenter {
|
|
17
|
+
export default class BaseEndpoint extends CorePresenter {
|
|
26
18
|
constructor(chanel, module, port) {
|
|
27
19
|
super(`endpoint-${chanel}`, module);
|
|
28
20
|
this.port = port;
|
|
29
|
-
this.appServer = (
|
|
30
|
-
this.appServer.use(
|
|
31
|
-
this.httpServer =
|
|
21
|
+
this.appServer = express();
|
|
22
|
+
this.appServer.use(json({ verify: keepRawBody }));
|
|
23
|
+
this.httpServer = http.createServer(this.appServer);
|
|
32
24
|
}
|
|
33
25
|
appServerOverride(app) {
|
|
34
26
|
this.appServer = app;
|
|
35
|
-
this.httpServer =
|
|
27
|
+
this.httpServer = http.createServer(this.appServer);
|
|
36
28
|
}
|
|
37
29
|
start() {
|
|
38
30
|
return new Promise((resolve) => {
|
|
@@ -61,4 +53,3 @@ class BaseEndpoint extends core_1.CorePresenter {
|
|
|
61
53
|
return this.httpServer;
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
|
-
exports.default = BaseEndpoint;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const core_1 = require("@grandlinex/core");
|
|
4
|
-
class BaseKernelModule extends core_1.CoreKernelModule {
|
|
1
|
+
import { CoreKernelModule } from '@grandlinex/core';
|
|
2
|
+
export default class BaseKernelModule extends CoreKernelModule {
|
|
5
3
|
}
|
|
6
|
-
exports.default = BaseKernelModule;
|
package/dist/classes/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import BaseEndpoint, { keepRawBody } from './BaseEndpoint';
|
|
|
4
4
|
import BaseKernelModule from './BaseKernelModule';
|
|
5
5
|
import BaseApiAction from './BaseApiAction';
|
|
6
6
|
import BaseAuthProvider from './BaseAuthProvider';
|
|
7
|
+
export * from './BaseAction';
|
|
7
8
|
export * from './BaseAuthProvider';
|
|
8
9
|
export * from './timing';
|
|
9
10
|
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
|
package/dist/classes/index.js
CHANGED
|
@@ -1,52 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.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_1 = __importDefault(require("./BaseAction"));
|
|
41
|
-
exports.BaseAction = BaseAction_1.default;
|
|
42
|
-
const BaseEndpoint_1 = __importStar(require("./BaseEndpoint"));
|
|
43
|
-
exports.BaseEndpoint = BaseEndpoint_1.default;
|
|
44
|
-
Object.defineProperty(exports, "keepRawBody", { enumerable: true, get: function () { return BaseEndpoint_1.keepRawBody; } });
|
|
45
|
-
const BaseKernelModule_1 = __importDefault(require("./BaseKernelModule"));
|
|
46
|
-
exports.BaseKernelModule = BaseKernelModule_1.default;
|
|
47
|
-
const BaseApiAction_1 = __importDefault(require("./BaseApiAction"));
|
|
48
|
-
exports.BaseApiAction = BaseApiAction_1.default;
|
|
49
|
-
const BaseAuthProvider_1 = __importDefault(require("./BaseAuthProvider"));
|
|
50
|
-
exports.BaseAuthProvider = BaseAuthProvider_1.default;
|
|
51
|
-
__exportStar(require("./BaseAuthProvider"), exports);
|
|
52
|
-
__exportStar(require("./timing"), exports);
|
|
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';
|
|
3
|
+
import BaseEndpoint, { keepRawBody } from './BaseEndpoint';
|
|
4
|
+
import BaseKernelModule from './BaseKernelModule';
|
|
5
|
+
import BaseApiAction from './BaseApiAction';
|
|
6
|
+
import BaseAuthProvider from './BaseAuthProvider';
|
|
7
|
+
export * from './BaseAction';
|
|
8
|
+
export * from './BaseAuthProvider';
|
|
9
|
+
export * from './timing';
|
|
10
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
|
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const ServerTiming_1 = __importDefault(require("./ServerTiming"));
|
|
16
|
-
class ExpressServerTiming {
|
|
1
|
+
import ServerTiming from './ServerTiming';
|
|
2
|
+
export default class ExpressServerTiming {
|
|
17
3
|
constructor(baseApiAction) {
|
|
18
|
-
this.timing = new
|
|
4
|
+
this.timing = new ServerTiming();
|
|
19
5
|
this.baseApiAction = baseApiAction;
|
|
20
6
|
}
|
|
21
7
|
start(chanel) {
|
|
22
8
|
return this.timing.start(chanel);
|
|
23
9
|
}
|
|
24
|
-
startFunc(chanel, fc) {
|
|
25
|
-
return
|
|
26
|
-
return this.timing.startFunc(chanel, fc);
|
|
27
|
-
});
|
|
10
|
+
async startFunc(chanel, fc) {
|
|
11
|
+
return this.timing.startFunc(chanel, fc);
|
|
28
12
|
}
|
|
29
|
-
dbQuery(fc) {
|
|
30
|
-
return
|
|
31
|
-
return this.timing.startFunc('db', fc);
|
|
32
|
-
});
|
|
13
|
+
async dbQuery(fc) {
|
|
14
|
+
return this.timing.startFunc('db', fc);
|
|
33
15
|
}
|
|
34
16
|
getHeader() {
|
|
35
17
|
const out = [];
|
|
@@ -62,4 +44,3 @@ class ExpressServerTiming {
|
|
|
62
44
|
];
|
|
63
45
|
}
|
|
64
46
|
}
|
|
65
|
-
exports.default = ExpressServerTiming;
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
|
|
16
|
-
class ServerTiming {
|
|
1
|
+
import ServerTimingElement from './ServerTimingElement';
|
|
2
|
+
export default class ServerTiming {
|
|
17
3
|
constructor() {
|
|
18
4
|
this.map = new Map();
|
|
19
5
|
}
|
|
20
6
|
start(chanel) {
|
|
21
|
-
return new
|
|
7
|
+
return new ServerTimingElement(this, chanel);
|
|
22
8
|
}
|
|
23
|
-
startFunc(chanel, fc) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return content;
|
|
29
|
-
});
|
|
9
|
+
async startFunc(chanel, fc) {
|
|
10
|
+
const el = new ServerTimingElement(this, chanel);
|
|
11
|
+
const content = await fc();
|
|
12
|
+
el.stop();
|
|
13
|
+
return content;
|
|
30
14
|
}
|
|
31
15
|
completeElement(e) {
|
|
32
16
|
const cur = this.map.get(e.chanel) || [];
|
|
@@ -34,4 +18,3 @@ class ServerTiming {
|
|
|
34
18
|
this.map.set(e.chanel, cur);
|
|
35
19
|
}
|
|
36
20
|
}
|
|
37
|
-
exports.default = ServerTiming;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class ServerTimingElement {
|
|
1
|
+
export default class ServerTimingElement {
|
|
4
2
|
constructor(el, chanel) {
|
|
5
3
|
this.el = el;
|
|
6
4
|
this.chanel = chanel;
|
|
@@ -20,4 +18,3 @@ class ServerTimingElement {
|
|
|
20
18
|
return this.end - this.start;
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
exports.default = ServerTimingElement;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ServerTiming = exports.ServerTimingElement = exports.ExpressServerTiming = void 0;
|
|
7
|
-
const ExpressServerTiming_1 = __importDefault(require("./ExpressServerTiming"));
|
|
8
|
-
exports.ExpressServerTiming = ExpressServerTiming_1.default;
|
|
9
|
-
const ServerTiming_1 = __importDefault(require("./ServerTiming"));
|
|
10
|
-
exports.ServerTiming = ServerTiming_1.default;
|
|
11
|
-
const ServerTimingElement_1 = __importDefault(require("./ServerTimingElement"));
|
|
12
|
-
exports.ServerTimingElement = ServerTimingElement_1.default;
|
|
1
|
+
import ExpressServerTiming from './ExpressServerTiming';
|
|
2
|
+
import ServerTiming from './ServerTiming';
|
|
3
|
+
import ServerTimingElement from './ServerTimingElement';
|
|
4
|
+
export { ExpressServerTiming, ServerTimingElement, ServerTiming, };
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,15 @@
|
|
|
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
1
|
/**
|
|
22
2
|
* @name Kernel Main Module
|
|
23
3
|
* @author David Nagy
|
|
24
4
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
exports.default = Kernel_1.default;
|
|
5
|
+
import Kernel from './Kernel';
|
|
6
|
+
import KernelModule from './KernelModule';
|
|
7
|
+
export * from './actions';
|
|
8
|
+
export * from './api';
|
|
9
|
+
export * from './classes';
|
|
10
|
+
export * from './modules/crypto';
|
|
11
|
+
export * from './lib';
|
|
12
|
+
export * from './lib/express';
|
|
13
|
+
export * from '@grandlinex/core';
|
|
14
|
+
export { KernelModule, Kernel };
|
|
15
|
+
export default Kernel;
|
package/dist/lib/express.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/lib/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
const jsonwebtoken_1 = __importStar(require("jsonwebtoken"));
|
|
36
|
-
const core_1 = require("@grandlinex/core");
|
|
37
|
-
class CryptoClient extends core_1.CoreCryptoClient {
|
|
1
|
+
import jwt, { TokenExpiredError } from 'jsonwebtoken';
|
|
2
|
+
import { CoreCryptoClient } from '@grandlinex/core';
|
|
3
|
+
export default class CryptoClient extends CoreCryptoClient {
|
|
38
4
|
constructor(key, kernel) {
|
|
39
5
|
super(kernel, key);
|
|
40
6
|
this.kernel = kernel;
|
|
@@ -50,8 +16,8 @@ class CryptoClient extends core_1.CoreCryptoClient {
|
|
|
50
16
|
}
|
|
51
17
|
jwtVerifyAccessToken(token) {
|
|
52
18
|
return new Promise((resolve) => {
|
|
53
|
-
|
|
54
|
-
if (err instanceof
|
|
19
|
+
jwt.verify(token, this.AesKey, (err, user) => {
|
|
20
|
+
if (err instanceof TokenExpiredError) {
|
|
55
21
|
resolve(498);
|
|
56
22
|
}
|
|
57
23
|
else if (err || user === null) {
|
|
@@ -64,58 +30,51 @@ class CryptoClient extends core_1.CoreCryptoClient {
|
|
|
64
30
|
});
|
|
65
31
|
}
|
|
66
32
|
jwtDecodeAccessToken(token) {
|
|
67
|
-
return
|
|
33
|
+
return jwt.decode(token, { json: true });
|
|
68
34
|
}
|
|
69
35
|
jwtGenerateAccessToken(data, expire) {
|
|
70
|
-
return
|
|
36
|
+
return jwt.sign(data, this.AesKey, { expiresIn: expire ?? this.expiresIn });
|
|
71
37
|
}
|
|
72
|
-
apiTokenValidation(username, token, requestType) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(token === store.get('SERVER_PASSWORD') && username === 'admin')) {
|
|
84
|
-
return {
|
|
85
|
-
valid: true,
|
|
86
|
-
userId: 'admin',
|
|
87
|
-
};
|
|
88
|
-
}
|
|
38
|
+
async apiTokenValidation(username, token, requestType) {
|
|
39
|
+
if (this.authProvider) {
|
|
40
|
+
return this.authProvider.authorizeToken(username, token, requestType);
|
|
41
|
+
}
|
|
42
|
+
const store = this.kernel.getConfigStore();
|
|
43
|
+
const cc = this.kernel.getCryptoClient();
|
|
44
|
+
if (!store.has('SERVER_PASSWORD')) {
|
|
45
|
+
return { valid: false, userId: null };
|
|
46
|
+
}
|
|
47
|
+
if (cc?.timeSavePWValidation(token, store.get('SERVER_PASSWORD') || '') ||
|
|
48
|
+
(token === store.get('SERVER_PASSWORD') && username === 'admin')) {
|
|
89
49
|
return {
|
|
90
|
-
valid:
|
|
91
|
-
userId:
|
|
50
|
+
valid: true,
|
|
51
|
+
userId: 'admin',
|
|
92
52
|
};
|
|
93
|
-
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
valid: false,
|
|
56
|
+
userId: null,
|
|
57
|
+
};
|
|
94
58
|
}
|
|
95
|
-
permissionValidation(token, requestType) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return false;
|
|
101
|
-
});
|
|
59
|
+
async permissionValidation(token, requestType) {
|
|
60
|
+
if (this.authProvider) {
|
|
61
|
+
return this.authProvider.validateAccess(token, requestType);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
102
64
|
}
|
|
103
|
-
bearerTokenValidation(req) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return 403;
|
|
118
|
-
});
|
|
65
|
+
async bearerTokenValidation(req) {
|
|
66
|
+
if (this.authProvider) {
|
|
67
|
+
return this.authProvider.bearerTokenValidation(req);
|
|
68
|
+
}
|
|
69
|
+
const authHeader = req.headers.authorization;
|
|
70
|
+
const token = authHeader && authHeader.split(' ')[1];
|
|
71
|
+
if (!token) {
|
|
72
|
+
return 401;
|
|
73
|
+
}
|
|
74
|
+
const tokenData = await this.jwtVerifyAccessToken(token);
|
|
75
|
+
if (tokenData) {
|
|
76
|
+
return tokenData;
|
|
77
|
+
}
|
|
78
|
+
return 403;
|
|
119
79
|
}
|
|
120
80
|
}
|
|
121
|
-
exports.default = CryptoClient;
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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_1 = __importDefault(require("./CryptoClient"));
|
|
22
|
-
exports.CryptoClient = CryptoClient_1.default;
|
|
23
|
-
__exportStar(require("./utils/cors"), exports);
|
|
1
|
+
import CryptoClient from './CryptoClient';
|
|
2
|
+
export { CryptoClient };
|
|
3
|
+
export * from './utils/cors';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cors = void 0;
|
|
4
|
-
const cors = (req, res, next) => {
|
|
1
|
+
export const cors = (req, res, next) => {
|
|
5
2
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
6
3
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
7
4
|
res.setHeader('Access-Control-Allow-Methods', '*');
|
|
8
5
|
next();
|
|
9
6
|
};
|
|
10
|
-
exports.cors = cors;
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/kernel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "GrandLineX is an out-of-the-box server framework on top of ExpressJs.",
|
|
5
|
-
"
|
|
5
|
+
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"buildprep": "tsc",
|
|
9
10
|
"lint": "eslint src",
|
|
10
11
|
"test": "jest --runInBand ",
|
|
11
12
|
"run": "ts-node tests/run.ts",
|
|
13
|
+
"pack-dev": "npm version -no-git-tag-version prerelease && npm run buildprep && npm pack",
|
|
12
14
|
"test-converage": "jest --runInBand --ci --collectCoverage --coverageDirectory=\"./coverage\" --reporters=default --reporters=jest-junit",
|
|
13
15
|
"makeDocs": "typedoc",
|
|
14
16
|
"openDocs": "npm run makeDocs",
|
|
@@ -27,36 +29,36 @@
|
|
|
27
29
|
},
|
|
28
30
|
"license": "BSD-3-Clause",
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"@grandlinex/core": "0.
|
|
31
|
-
"axios": "
|
|
32
|
-
"body-parser": "1.20.
|
|
32
|
+
"@grandlinex/core": "0.30.0",
|
|
33
|
+
"axios": "1.3.4",
|
|
34
|
+
"body-parser": "1.20.2",
|
|
33
35
|
"express": "4.18.2",
|
|
34
36
|
"jsonwebtoken": "9.0.0"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"@types/express": "^4.17.
|
|
38
|
-
"@types/jest": "^29.
|
|
39
|
-
"@types/jsonwebtoken": "^
|
|
40
|
-
"@types/node": "^
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
42
|
-
"@typescript-eslint/parser": "^5.
|
|
39
|
+
"@types/express": "^4.17.17",
|
|
40
|
+
"@types/jest": "^29.5.0",
|
|
41
|
+
"@types/jsonwebtoken": "^9.0.1",
|
|
42
|
+
"@types/node": "^18.15.11",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
|
44
|
+
"@typescript-eslint/parser": "^5.57.1",
|
|
43
45
|
"cross-env": "^7.0.3",
|
|
44
|
-
"eslint": "^8.
|
|
46
|
+
"eslint": "^8.37.0",
|
|
45
47
|
"eslint-config-airbnb": "^19.0.4",
|
|
46
48
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
47
|
-
"eslint-config-prettier": "^8.
|
|
48
|
-
"eslint-plugin-import": "^2.
|
|
49
|
-
"eslint-plugin-jest": "^27.1
|
|
50
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
49
|
+
"eslint-config-prettier": "^8.8.0",
|
|
50
|
+
"eslint-plugin-import": "^2.27.5",
|
|
51
|
+
"eslint-plugin-jest": "^27.2.1",
|
|
52
|
+
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
51
53
|
"eslint-plugin-prettier": "^4.2.1",
|
|
52
|
-
"jest": "^29.
|
|
54
|
+
"jest": "^29.5.0",
|
|
53
55
|
"jest-junit": "^15.0.0",
|
|
54
|
-
"prettier": "^2.8.
|
|
55
|
-
"ts-jest": "^29.0
|
|
56
|
-
"ts-loader": "^9.4.
|
|
56
|
+
"prettier": "^2.8.7",
|
|
57
|
+
"ts-jest": "^29.1.0",
|
|
58
|
+
"ts-loader": "^9.4.2",
|
|
57
59
|
"ts-node": "^10.9.1",
|
|
58
|
-
"typedoc": "^0.23.
|
|
59
|
-
"typescript": "^
|
|
60
|
+
"typedoc": "^0.23.28",
|
|
61
|
+
"typescript": "^5.0.3"
|
|
60
62
|
},
|
|
61
63
|
"repository": {
|
|
62
64
|
"type": "git",
|