@grandlinex/kernel 0.28.2 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/Kernel.d.ts +3 -3
- package/dist/Kernel.js +7 -13
- package/dist/KernelModule.d.ts +3 -3
- package/dist/KernelModule.js +13 -30
- package/dist/actions/ApiAuthTestAction.d.ts +3 -19
- package/dist/actions/ApiAuthTestAction.js +5 -35
- package/dist/actions/ApiVersionAction.d.ts +3 -23
- package/dist/actions/ApiVersionAction.js +6 -40
- package/dist/actions/GetTokenAction.d.ts +3 -4
- package/dist/actions/GetTokenAction.js +26 -41
- package/dist/actions/index.d.ts +3 -3
- package/dist/actions/index.js +4 -12
- package/dist/api/KernelEndpoint.d.ts +1 -1
- package/dist/api/KernelEndpoint.js +2 -8
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +3 -8
- package/dist/classes/BaseAction.d.ts +4 -4
- package/dist/classes/BaseAction.js +37 -52
- package/dist/classes/BaseApiAction.d.ts +2 -2
- package/dist/classes/BaseApiAction.js +2 -8
- package/dist/classes/BaseAuthProvider.d.ts +3 -3
- package/dist/classes/BaseAuthProvider.js +1 -4
- package/dist/classes/BaseEndpoint.d.ts +4 -4
- package/dist/classes/BaseEndpoint.js +11 -20
- package/dist/classes/BaseKernelModule.d.ts +1 -1
- package/dist/classes/BaseKernelModule.js +2 -5
- package/dist/classes/index.d.ts +8 -7
- package/dist/classes/index.js +10 -52
- package/dist/classes/timing/ExpressServerTiming.d.ts +2 -2
- package/dist/classes/timing/ExpressServerTiming.js +7 -26
- package/dist/classes/timing/ServerTiming.d.ts +1 -1
- package/dist/classes/timing/ServerTiming.js +8 -25
- package/dist/classes/timing/ServerTimingElement.js +1 -4
- package/dist/classes/timing/index.d.ts +3 -3
- package/dist/classes/timing/index.js +4 -12
- package/dist/index.d.ts +8 -8
- package/dist/index.js +11 -32
- package/dist/lib/express.js +1 -2
- package/dist/lib/index.d.ts +4 -5
- package/dist/lib/index.js +1 -2
- package/dist/modules/crypto/CryptoClient.d.ts +5 -5
- package/dist/modules/crypto/CryptoClient.js +44 -85
- package/dist/modules/crypto/index.d.ts +2 -2
- package/dist/modules/crypto/index.js +3 -23
- package/dist/modules/crypto/utils/cors.d.ts +1 -1
- package/dist/modules/crypto/utils/cors.js +1 -5
- package/package.json +24 -23
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import express, { Express } from 'express';
|
|
4
4
|
import http from 'http';
|
|
5
5
|
import { CorePresenter, IDataBase } from '@grandlinex/core';
|
|
6
|
-
import { IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib';
|
|
7
|
-
import { XRequest, XResponse } from '../lib/express';
|
|
6
|
+
import { IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
7
|
+
import { XRequest, XResponse } from '../lib/express.js';
|
|
8
8
|
export declare function keepRawBody(req: XRequest, res: XResponse, buf: Buffer, encoding: string): void;
|
|
9
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
10
|
protected appServer: express.Express;
|
|
@@ -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 parser 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(parser.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,4 +1,4 @@
|
|
|
1
1
|
import { CoreKernelModule, IDataBase } from '@grandlinex/core';
|
|
2
|
-
import { IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib';
|
|
2
|
+
import { IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
3
|
export default abstract class BaseKernelModule<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends CoreKernelModule<K, T, P, C, E> implements IBaseKernelModule<K, T, P, C, E> {
|
|
4
4
|
}
|
|
@@ -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
|
@@ -1,9 +1,10 @@
|
|
|
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';
|
|
3
|
-
import BaseEndpoint, { keepRawBody } from './BaseEndpoint';
|
|
4
|
-
import BaseKernelModule from './BaseKernelModule';
|
|
5
|
-
import BaseApiAction from './BaseApiAction';
|
|
6
|
-
import BaseAuthProvider from './BaseAuthProvider';
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
2
|
+
import BaseAction from './BaseAction.js';
|
|
3
|
+
import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
|
|
4
|
+
import BaseKernelModule from './BaseKernelModule.js';
|
|
5
|
+
import BaseApiAction from './BaseApiAction.js';
|
|
6
|
+
import BaseAuthProvider from './BaseAuthProvider.js';
|
|
7
|
+
export * from './BaseAction.js';
|
|
8
|
+
export * from './BaseAuthProvider.js';
|
|
9
|
+
export * from './timing/index.js';
|
|
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.js';
|
|
3
|
+
import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
|
|
4
|
+
import BaseKernelModule from './BaseKernelModule.js';
|
|
5
|
+
import BaseApiAction from './BaseApiAction.js';
|
|
6
|
+
import BaseAuthProvider from './BaseAuthProvider.js';
|
|
7
|
+
export * from './BaseAction.js';
|
|
8
|
+
export * from './BaseAuthProvider.js';
|
|
9
|
+
export * from './timing/index.js';
|
|
10
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoreElement } from '@grandlinex/core';
|
|
2
|
-
import { XResponse } from '../../lib/express';
|
|
2
|
+
import { XResponse } from '../../lib/express.js';
|
|
3
3
|
export type IExtensionInterface = {
|
|
4
4
|
done: () => void;
|
|
5
5
|
timing: ExpressServerTiming;
|
|
@@ -8,7 +8,7 @@ export default class ExpressServerTiming {
|
|
|
8
8
|
private timing;
|
|
9
9
|
private baseApiAction;
|
|
10
10
|
constructor(baseApiAction: CoreElement<any>);
|
|
11
|
-
start(chanel: string): import("./ServerTimingElement").default;
|
|
11
|
+
start(chanel: string): import("./ServerTimingElement.js").default;
|
|
12
12
|
startFunc<T>(chanel: string, fc: () => Promise<T>): Promise<T>;
|
|
13
13
|
dbQuery<T>(fc: () => Promise<T>): Promise<T>;
|
|
14
14
|
getHeader(): string;
|
|
@@ -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.js';
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import ServerTimingElement, { IServerElement } from './ServerTimingElement';
|
|
1
|
+
import ServerTimingElement, { IServerElement } from './ServerTimingElement.js';
|
|
2
2
|
export default class ServerTiming implements IServerElement {
|
|
3
3
|
map: Map<string, ServerTimingElement[]>;
|
|
4
4
|
constructor();
|
|
@@ -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.js';
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import ExpressServerTiming, { IExtensionInterface } from './ExpressServerTiming';
|
|
2
|
-
import ServerTiming from './ServerTiming';
|
|
3
|
-
import ServerTimingElement from './ServerTimingElement';
|
|
1
|
+
import ExpressServerTiming, { IExtensionInterface } from './ExpressServerTiming.js';
|
|
2
|
+
import ServerTiming from './ServerTiming.js';
|
|
3
|
+
import ServerTimingElement from './ServerTimingElement.js';
|
|
4
4
|
export { ExpressServerTiming, ServerTimingElement, ServerTiming, IExtensionInterface, };
|
|
@@ -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.js';
|
|
2
|
+
import ServerTiming from './ServerTiming.js';
|
|
3
|
+
import ServerTimingElement from './ServerTimingElement.js';
|
|
4
|
+
export { ExpressServerTiming, ServerTimingElement, ServerTiming, };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* @name Kernel Main Module
|
|
3
3
|
* @author David Nagy
|
|
4
4
|
*/
|
|
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';
|
|
5
|
+
import Kernel from './Kernel.js';
|
|
6
|
+
import KernelModule from './KernelModule.js';
|
|
7
|
+
export * from './actions/index.js';
|
|
8
|
+
export * from './api/index.js';
|
|
9
|
+
export * from './classes/index.js';
|
|
10
|
+
export * from './modules/crypto/index.js';
|
|
11
|
+
export * from './lib/index.js';
|
|
12
|
+
export * from './lib/express.js';
|
|
13
13
|
export * from '@grandlinex/core';
|
|
14
14
|
export { KernelModule, Kernel };
|
|
15
15
|
export default Kernel;
|
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.js';
|
|
6
|
+
import KernelModule from './KernelModule.js';
|
|
7
|
+
export * from './actions/index.js';
|
|
8
|
+
export * from './api/index.js';
|
|
9
|
+
export * from './classes/index.js';
|
|
10
|
+
export * from './modules/crypto/index.js';
|
|
11
|
+
export * from './lib/index.js';
|
|
12
|
+
export * from './lib/express.js';
|
|
13
|
+
export * from '@grandlinex/core';
|
|
14
|
+
export { KernelModule, Kernel };
|
|
15
|
+
export default Kernel;
|
package/dist/lib/express.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { ICoreAction, ICoreBridge, ICoreCache, ICoreCClient, ICoreClient, ICoreElement, ICoreKernel, ICoreKernelModule, ICorePresenter, ICoreService, IDataBase } from '@grandlinex/core';
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import
|
|
4
|
-
import { IAuthProvider, JwtToken } from '../classes/
|
|
5
|
-
import {
|
|
6
|
-
import { XNextFc, XRequest, XResponse } from './express';
|
|
3
|
+
import * as jwt from 'jsonwebtoken';
|
|
4
|
+
import { IAuthProvider, JwtToken, IExtensionInterface } from '../classes/index.js';
|
|
5
|
+
import { XNextFc, XRequest, XResponse } from './express.js';
|
|
7
6
|
export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
|
|
8
7
|
export interface ICClient extends ICoreCClient {
|
|
9
8
|
setAuthProvider(provider: IAuthProvider): boolean;
|
|
10
9
|
jwtVerifyAccessToken(token: string): Promise<JwtToken | number>;
|
|
11
|
-
jwtDecodeAccessToken(token: string): JwtPayload | null;
|
|
10
|
+
jwtDecodeAccessToken(token: string): jwt.JwtPayload | null;
|
|
12
11
|
jwtGenerateAccessToken(data: JwtToken, expire?: string | number): string;
|
|
13
12
|
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
14
13
|
valid: boolean;
|
package/dist/lib/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { JwtPayload } from 'jsonwebtoken';
|
|
2
1
|
import { CoreCryptoClient } from '@grandlinex/core';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import * as jwt from 'jsonwebtoken';
|
|
3
|
+
import { ICClient, IKernel } from '../../lib/index.js';
|
|
4
|
+
import { IAuthProvider, JwtToken } from '../../classes/index.js';
|
|
5
|
+
import { XRequest } from '../../lib/express.js';
|
|
6
6
|
export default class CryptoClient extends CoreCryptoClient implements ICClient {
|
|
7
7
|
protected authProvider: IAuthProvider | null;
|
|
8
8
|
protected kernel: IKernel;
|
|
@@ -10,7 +10,7 @@ export default class CryptoClient extends CoreCryptoClient implements ICClient {
|
|
|
10
10
|
constructor(key: string, kernel: IKernel);
|
|
11
11
|
setAuthProvider(provider: IAuthProvider): boolean;
|
|
12
12
|
jwtVerifyAccessToken(token: string): Promise<JwtToken | number>;
|
|
13
|
-
jwtDecodeAccessToken(token: string): JwtPayload | null;
|
|
13
|
+
jwtDecodeAccessToken(token: string): jwt.JwtPayload | null;
|
|
14
14
|
jwtGenerateAccessToken(data: JwtToken, expire?: string | number): string;
|
|
15
15
|
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
16
16
|
valid: boolean;
|
|
@@ -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 { CoreCryptoClient } from '@grandlinex/core';
|
|
2
|
+
import * as jwt from 'jsonwebtoken';
|
|
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 jwt.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.default.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,3 +1,3 @@
|
|
|
1
|
-
import CryptoClient from './CryptoClient';
|
|
1
|
+
import CryptoClient from './CryptoClient.js';
|
|
2
2
|
export { CryptoClient };
|
|
3
|
-
export * from './utils/cors';
|
|
3
|
+
export * from './utils/cors.js';
|