@grandlinex/kernel 1.1.0-alpha.0 → 1.2.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 +117 -117
- package/LICENSE +29 -29
- package/README.md +30 -30
- package/dist/cjs/actions/ApiAuthTestAction.js +6 -12
- package/dist/cjs/actions/ApiVersionAction.js +14 -18
- package/dist/cjs/actions/GetTokenAction.js +26 -31
- package/dist/cjs/classes/BaseAction.d.ts +3 -7
- package/dist/cjs/classes/BaseAction.js +21 -19
- package/dist/cjs/classes/BaseApiAction.d.ts +2 -1
- package/dist/cjs/classes/RouteApiAction.js +7 -7
- package/dist/cjs/classes/index.d.ts +2 -2
- package/dist/cjs/classes/index.js +2 -3
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/lib/express.d.ts +2 -0
- package/dist/cjs/lib/index.d.ts +0 -1
- package/dist/mjs/actions/ApiAuthTestAction.js +7 -13
- package/dist/mjs/actions/ApiVersionAction.js +16 -20
- package/dist/mjs/actions/GetTokenAction.js +28 -33
- package/dist/mjs/classes/BaseAction.d.ts +3 -7
- package/dist/mjs/classes/BaseAction.js +19 -16
- package/dist/mjs/classes/BaseApiAction.d.ts +2 -1
- package/dist/mjs/classes/RouteApiAction.js +7 -7
- package/dist/mjs/classes/index.d.ts +2 -2
- package/dist/mjs/classes/index.js +2 -2
- package/dist/mjs/index.d.ts +0 -1
- package/dist/mjs/index.js +0 -1
- package/dist/mjs/lib/express.d.ts +2 -0
- package/dist/mjs/lib/index.d.ts +0 -1
- package/package.json +89 -89
- package/dist/cjs/annotation/index.d.ts +0 -13
- package/dist/cjs/annotation/index.js +0 -21
- package/dist/mjs/annotation/index.d.ts +0 -13
- package/dist/mjs/annotation/index.js +0 -16
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActionMode = void 0;
|
|
4
3
|
const core_1 = require("@grandlinex/core");
|
|
5
4
|
const swagger_mate_1 = require("@grandlinex/swagger-mate");
|
|
6
5
|
const index_js_1 = require("./timing/index.js");
|
|
7
6
|
const BaseUserAgent_js_1 = require("./BaseUserAgent.js");
|
|
8
|
-
var ActionMode;
|
|
9
|
-
(function (ActionMode) {
|
|
10
|
-
ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
|
|
11
|
-
ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
|
|
12
|
-
ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
|
|
13
|
-
})(ActionMode || (exports.ActionMode = ActionMode = {}));
|
|
14
7
|
class BaseAction extends core_1.CoreAction {
|
|
15
8
|
constructor(chanel, module) {
|
|
16
9
|
super(chanel, module);
|
|
17
10
|
this.secureHandler = this.secureHandler.bind(this);
|
|
18
|
-
this.mode = ActionMode.DEFAULT;
|
|
11
|
+
this.mode = swagger_mate_1.ActionMode.DEFAULT;
|
|
19
12
|
this.forceDebug = false;
|
|
20
|
-
this.
|
|
13
|
+
this.requestSchema = null;
|
|
21
14
|
}
|
|
22
15
|
static validateSchema(error, schema, key, field, required = true) {
|
|
23
16
|
if ((0, swagger_mate_1.isSwaggerRef)(schema)) {
|
|
@@ -91,7 +84,7 @@ class BaseAction extends core_1.CoreAction {
|
|
|
91
84
|
}
|
|
92
85
|
}
|
|
93
86
|
bodyValidation(req) {
|
|
94
|
-
if (!this.
|
|
87
|
+
if (!this.requestSchema) {
|
|
95
88
|
return null;
|
|
96
89
|
}
|
|
97
90
|
if (!req.body) {
|
|
@@ -102,12 +95,18 @@ class BaseAction extends core_1.CoreAction {
|
|
|
102
95
|
global: [],
|
|
103
96
|
field: [],
|
|
104
97
|
};
|
|
105
|
-
BaseAction.validateSchema(error, this.
|
|
98
|
+
BaseAction.validateSchema(error, this.requestSchema, 'body', req.body);
|
|
106
99
|
if (error.field.length > 0 || error.global.length > 0) {
|
|
107
100
|
return error;
|
|
108
101
|
}
|
|
109
102
|
return req.body;
|
|
110
103
|
}
|
|
104
|
+
static sendError(res, code, error) {
|
|
105
|
+
res.status(code).send({
|
|
106
|
+
type: 'error',
|
|
107
|
+
...error,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
111
110
|
async secureHandler(req, res, next) {
|
|
112
111
|
const extension = this.initExtension(res);
|
|
113
112
|
const auth = extension.timing.start('auth');
|
|
@@ -122,18 +121,18 @@ class BaseAction extends core_1.CoreAction {
|
|
|
122
121
|
res.status(504).send('internal server error');
|
|
123
122
|
return;
|
|
124
123
|
}
|
|
125
|
-
if (this.mode === ActionMode.DMZ) {
|
|
124
|
+
if (this.mode === swagger_mate_1.ActionMode.DMZ) {
|
|
126
125
|
auth.stop();
|
|
127
126
|
try {
|
|
128
127
|
let body = null;
|
|
129
|
-
if (this.
|
|
128
|
+
if (this.requestSchema) {
|
|
130
129
|
body = this.bodyValidation(req);
|
|
131
130
|
}
|
|
132
131
|
if ((0, swagger_mate_1.isErrorType)(body)) {
|
|
133
132
|
res.status(400).send(body);
|
|
134
133
|
return;
|
|
135
134
|
}
|
|
136
|
-
if (this.
|
|
135
|
+
if (this.requestSchema && body === null) {
|
|
137
136
|
res.sendStatus(400);
|
|
138
137
|
return;
|
|
139
138
|
}
|
|
@@ -145,6 +144,7 @@ class BaseAction extends core_1.CoreAction {
|
|
|
145
144
|
extension,
|
|
146
145
|
agent: new BaseUserAgent_js_1.BaseUserAgent(req),
|
|
147
146
|
body,
|
|
147
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
catch (e) {
|
|
@@ -161,14 +161,14 @@ class BaseAction extends core_1.CoreAction {
|
|
|
161
161
|
if (dat && typeof dat !== 'number') {
|
|
162
162
|
try {
|
|
163
163
|
let body = null;
|
|
164
|
-
if (this.
|
|
164
|
+
if (this.requestSchema) {
|
|
165
165
|
body = this.bodyValidation(req);
|
|
166
166
|
}
|
|
167
167
|
if ((0, swagger_mate_1.isErrorType)(body)) {
|
|
168
168
|
res.status(400).send(body);
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
|
-
if (this.
|
|
171
|
+
if (this.requestSchema && body === null) {
|
|
172
172
|
res.sendStatus(400);
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
@@ -180,6 +180,7 @@ class BaseAction extends core_1.CoreAction {
|
|
|
180
180
|
extension,
|
|
181
181
|
agent: new BaseUserAgent_js_1.BaseUserAgent(req),
|
|
182
182
|
body,
|
|
183
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
183
184
|
});
|
|
184
185
|
}
|
|
185
186
|
catch (e) {
|
|
@@ -190,17 +191,17 @@ class BaseAction extends core_1.CoreAction {
|
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
|
-
else if (this.mode === ActionMode.DMZ_WITH_USER) {
|
|
194
|
+
else if (this.mode === swagger_mate_1.ActionMode.DMZ_WITH_USER) {
|
|
194
195
|
try {
|
|
195
196
|
let body = null;
|
|
196
|
-
if (this.
|
|
197
|
+
if (this.requestSchema) {
|
|
197
198
|
body = this.bodyValidation(req);
|
|
198
199
|
}
|
|
199
200
|
if ((0, swagger_mate_1.isErrorType)(body)) {
|
|
200
201
|
res.status(400).send(body);
|
|
201
202
|
return;
|
|
202
203
|
}
|
|
203
|
-
if (this.
|
|
204
|
+
if (this.requestSchema && body === null) {
|
|
204
205
|
res.sendStatus(400);
|
|
205
206
|
return;
|
|
206
207
|
}
|
|
@@ -212,6 +213,7 @@ class BaseAction extends core_1.CoreAction {
|
|
|
212
213
|
extension,
|
|
213
214
|
agent: new BaseUserAgent_js_1.BaseUserAgent(req),
|
|
214
215
|
body,
|
|
216
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
215
217
|
});
|
|
216
218
|
}
|
|
217
219
|
catch (e) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IDataBase } from '@grandlinex/core';
|
|
2
|
-
import { ActionTypes
|
|
2
|
+
import { ActionTypes } from '@grandlinex/swagger-mate';
|
|
3
|
+
import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
4
|
import BaseAction from './BaseAction.js';
|
|
4
5
|
export default abstract class BaseApiAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends BaseAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
|
|
5
6
|
exmod: undefined | IBaseKernelModule<K>;
|
|
@@ -3,23 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const swagger_mate_1 = require("@grandlinex/swagger-mate");
|
|
7
7
|
const BaseApiAction_js_1 = __importDefault(require("./BaseApiAction.js"));
|
|
8
8
|
class RouteApiAction extends BaseApiAction_js_1.default {
|
|
9
9
|
constructor(module, extMod) {
|
|
10
10
|
super('GET', 'action', module, extMod);
|
|
11
11
|
this.exmod = extMod;
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
12
|
+
const route = (0, swagger_mate_1.getRouteMeta)(this);
|
|
13
|
+
if (!route) {
|
|
14
14
|
throw this.lError('No route meta found for action');
|
|
15
15
|
}
|
|
16
|
-
const { type, path,
|
|
16
|
+
const { type, path, meta } = route;
|
|
17
17
|
this.type = type;
|
|
18
18
|
this.channel = path;
|
|
19
|
-
if (mode) {
|
|
20
|
-
this.setMode(mode);
|
|
19
|
+
if (meta?.mode) {
|
|
20
|
+
this.setMode(meta.mode);
|
|
21
21
|
}
|
|
22
|
-
this.
|
|
22
|
+
this.requestSchema = meta?.requestSchema ?? null;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.default = RouteApiAction;
|
|
@@ -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
|
|
2
|
+
import BaseAction 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';
|
|
@@ -9,4 +9,4 @@ export * from './BaseAction.js';
|
|
|
9
9
|
export * from './BaseUserAgent.js';
|
|
10
10
|
export * from './BaseAuthProvider.js';
|
|
11
11
|
export * from './timing/index.js';
|
|
12
|
-
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody,
|
|
12
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
|
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.
|
|
42
|
+
exports.keepRawBody = exports.BaseBridge = exports.BaseClient = exports.BaseAction = exports.BaseCache = exports.RouteApiAction = exports.BaseElement = exports.BaseEndpoint = exports.BaseApiAction = exports.BaseService = exports.BaseKernelModule = exports.BaseAuthProvider = exports.BaseLoopService = void 0;
|
|
43
43
|
const core_1 = require("@grandlinex/core");
|
|
44
44
|
Object.defineProperty(exports, "BaseBridge", { enumerable: true, get: function () { return core_1.CoreBridge; } });
|
|
45
45
|
Object.defineProperty(exports, "BaseCache", { enumerable: true, get: function () { return core_1.CoreCache; } });
|
|
@@ -47,9 +47,8 @@ Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function (
|
|
|
47
47
|
Object.defineProperty(exports, "BaseElement", { enumerable: true, get: function () { return core_1.CoreElement; } });
|
|
48
48
|
Object.defineProperty(exports, "BaseLoopService", { enumerable: true, get: function () { return core_1.CoreLoopService; } });
|
|
49
49
|
Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return core_1.CoreService; } });
|
|
50
|
-
const BaseAction_js_1 =
|
|
50
|
+
const BaseAction_js_1 = __importDefault(require("./BaseAction.js"));
|
|
51
51
|
exports.BaseAction = BaseAction_js_1.default;
|
|
52
|
-
Object.defineProperty(exports, "ActionMode", { enumerable: true, get: function () { return BaseAction_js_1.ActionMode; } });
|
|
53
52
|
const BaseEndpoint_js_1 = __importStar(require("./BaseEndpoint.js"));
|
|
54
53
|
exports.BaseEndpoint = BaseEndpoint_js_1.default;
|
|
55
54
|
Object.defineProperty(exports, "keepRawBody", { enumerable: true, get: function () { return BaseEndpoint_js_1.keepRawBody; } });
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import Kernel from './Kernel.js';
|
|
|
6
6
|
import KernelModule from './KernelModule.js';
|
|
7
7
|
export * from './actions/index.js';
|
|
8
8
|
export * from './api/index.js';
|
|
9
|
-
export * from './annotation/index.js';
|
|
10
9
|
export * from './classes/index.js';
|
|
11
10
|
export * from './modules/crypto/index.js';
|
|
12
11
|
export * from './lib/index.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,7 +28,6 @@ const KernelModule_js_1 = __importDefault(require("./KernelModule.js"));
|
|
|
28
28
|
exports.KernelModule = KernelModule_js_1.default;
|
|
29
29
|
__exportStar(require("./actions/index.js"), exports);
|
|
30
30
|
__exportStar(require("./api/index.js"), exports);
|
|
31
|
-
__exportStar(require("./annotation/index.js"), exports);
|
|
32
31
|
__exportStar(require("./classes/index.js"), exports);
|
|
33
32
|
__exportStar(require("./modules/crypto/index.js"), exports);
|
|
34
33
|
__exportStar(require("./lib/index.js"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
+
import { ErrorType } from '@grandlinex/swagger-mate';
|
|
2
3
|
import { BaseUserAgent, IExtensionInterface, JwtToken } from '../classes/index.js';
|
|
3
4
|
export type XRequest = express.Request & {
|
|
4
5
|
rawBody?: string | null;
|
|
@@ -13,4 +14,5 @@ export type XActionEvent<G = JwtToken | null, B = any> = {
|
|
|
13
14
|
extension: IExtensionInterface;
|
|
14
15
|
agent: BaseUserAgent;
|
|
15
16
|
body: B;
|
|
17
|
+
sendError: (code: number, error: Partial<ErrorType>) => void;
|
|
16
18
|
};
|
package/dist/cjs/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { IAuthProvider, JwtExtend, JwtToken } from '../classes/index.js';
|
|
|
5
5
|
import EntitySchemaExtender from './EntitySchemaExtender.js';
|
|
6
6
|
import { XActionEvent, XRequest } from './express.js';
|
|
7
7
|
export { EntitySchemaExtender };
|
|
8
|
-
export type ActionTypes = 'POST' | 'GET' | 'USE' | 'PATCH' | 'DELETE';
|
|
9
8
|
export interface ICClient<T extends JwtExtend = JwtExtend> extends ICoreCClient {
|
|
10
9
|
setAuthProvider(provider: IAuthProvider<T>): boolean;
|
|
11
10
|
jwtVerifyAccessToken(token: string): Promise<JwtToken<T> | number>;
|
|
@@ -4,9 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
7
|
+
import { Route } from '@grandlinex/swagger-mate';
|
|
8
8
|
import { RouteApiAction } from '../classes/index.js';
|
|
9
|
-
import { Route } from '../annotation/index.js';
|
|
10
9
|
let ApiAuthTestAction = class ApiAuthTestAction extends RouteApiAction {
|
|
11
10
|
async handler({ data, res }) {
|
|
12
11
|
this.debug(data.userid);
|
|
@@ -14,16 +13,11 @@ let ApiAuthTestAction = class ApiAuthTestAction extends RouteApiAction {
|
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
15
|
ApiAuthTestAction = __decorate([
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
responses: SPathUtil.defaultResponse('200', '403'),
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
}),
|
|
27
|
-
Route('GET', '/test/auth')
|
|
16
|
+
Route('GET', '/test/auth', {
|
|
17
|
+
operationId: 'testAuth',
|
|
18
|
+
summary: 'Test user auth',
|
|
19
|
+
tags: ['kernel'],
|
|
20
|
+
responseCodes: ['200', '403'],
|
|
21
|
+
})
|
|
28
22
|
], ApiAuthTestAction);
|
|
29
23
|
export default ApiAuthTestAction;
|
|
@@ -4,9 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { Route } from '../annotation/index.js';
|
|
7
|
+
import { ActionMode, Route } from '@grandlinex/swagger-mate';
|
|
8
|
+
import { RouteApiAction } from '../classes/index.js';
|
|
10
9
|
let ApiVersionAction = class ApiVersionAction extends RouteApiAction {
|
|
11
10
|
async handler({ res, extension }) {
|
|
12
11
|
extension.done();
|
|
@@ -14,24 +13,21 @@ let ApiVersionAction = class ApiVersionAction extends RouteApiAction {
|
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
15
|
ApiVersionAction = __decorate([
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
required: ['api'],
|
|
31
|
-
}, false, '403'),
|
|
16
|
+
Route('GET', '/version', {
|
|
17
|
+
mode: ActionMode.DMZ,
|
|
18
|
+
operationId: 'getVersion',
|
|
19
|
+
summary: 'Get API version',
|
|
20
|
+
tags: ['kernel'],
|
|
21
|
+
responseSchema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
api: {
|
|
25
|
+
type: 'number',
|
|
26
|
+
},
|
|
32
27
|
},
|
|
28
|
+
required: ['api'],
|
|
33
29
|
},
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
responseCodes: ['200', '403'],
|
|
31
|
+
})
|
|
36
32
|
], ApiVersionAction);
|
|
37
33
|
export default ApiVersionAction;
|
|
@@ -4,21 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { Route } from '../annotation/index.js';
|
|
10
|
-
const schema = {
|
|
11
|
-
type: 'object',
|
|
12
|
-
properties: {
|
|
13
|
-
username: {
|
|
14
|
-
type: 'string',
|
|
15
|
-
},
|
|
16
|
-
token: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
required: ['username', 'token'],
|
|
21
|
-
};
|
|
7
|
+
import { ActionMode, Route } from '@grandlinex/swagger-mate';
|
|
8
|
+
import { RouteApiAction } from '../classes/index.js';
|
|
22
9
|
let GetTokenAction = class GetTokenAction extends RouteApiAction {
|
|
23
10
|
async handler({ req, res, extension, body, }) {
|
|
24
11
|
const cc = this.getKernel().getCryptoClient();
|
|
@@ -38,25 +25,33 @@ let GetTokenAction = class GetTokenAction extends RouteApiAction {
|
|
|
38
25
|
}
|
|
39
26
|
};
|
|
40
27
|
GetTokenAction = __decorate([
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
Route('POST', '/token', {
|
|
29
|
+
mode: ActionMode.DMZ,
|
|
30
|
+
operationId: 'getToken',
|
|
31
|
+
summary: 'Get API token',
|
|
32
|
+
tags: ['kernel'],
|
|
33
|
+
requestSchema: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
username: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
},
|
|
39
|
+
token: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
required: ['username', 'token'],
|
|
44
|
+
},
|
|
45
|
+
responseSchema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
token: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
},
|
|
57
51
|
},
|
|
52
|
+
required: ['token'],
|
|
58
53
|
},
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
responseCodes: ['200', '403'],
|
|
55
|
+
})
|
|
61
56
|
], GetTokenAction);
|
|
62
57
|
export default GetTokenAction;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { CoreAction, IDataBase } from '@grandlinex/core';
|
|
2
|
-
import { ErrorType, SSchemaEl } from '@grandlinex/swagger-mate';
|
|
2
|
+
import { ActionMode, ErrorType, SSchemaEl } from '@grandlinex/swagger-mate';
|
|
3
3
|
import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
4
4
|
import { XActionEvent, XRequest, XResponse } from '../lib/express.js';
|
|
5
|
-
export declare enum ActionMode {
|
|
6
|
-
'DEFAULT' = 0,
|
|
7
|
-
'DMZ' = 1,
|
|
8
|
-
'DMZ_WITH_USER' = 2
|
|
9
|
-
}
|
|
10
5
|
export default abstract class BaseAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends CoreAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
|
|
11
6
|
mode: ActionMode;
|
|
12
7
|
forceDebug: boolean;
|
|
13
|
-
|
|
8
|
+
requestSchema: SSchemaEl | null;
|
|
14
9
|
constructor(chanel: string, module: IBaseKernelModule<K, T, P, C, E>);
|
|
15
10
|
abstract handler(event: XActionEvent): Promise<void>;
|
|
16
11
|
static validateSchema(error: ErrorType, schema: SSchemaEl, key: string, field: any, required?: boolean): void;
|
|
17
12
|
bodyValidation<A>(req: XRequest): A | ErrorType | null;
|
|
13
|
+
static sendError(res: XResponse, code: number, error: Partial<ErrorType>): void;
|
|
18
14
|
secureHandler(req: XRequest, res: XResponse, next: () => void): Promise<void>;
|
|
19
15
|
setMode(mode: ActionMode): void;
|
|
20
16
|
abstract register(): void;
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { CoreAction } from '@grandlinex/core';
|
|
2
|
-
import { isErrorType, isSwaggerRef, } from '@grandlinex/swagger-mate';
|
|
2
|
+
import { ActionMode, isErrorType, isSwaggerRef, } from '@grandlinex/swagger-mate';
|
|
3
3
|
import { ExpressServerTiming } from './timing/index.js';
|
|
4
4
|
import { BaseUserAgent } from './BaseUserAgent.js';
|
|
5
|
-
export var ActionMode;
|
|
6
|
-
(function (ActionMode) {
|
|
7
|
-
ActionMode[ActionMode["DEFAULT"] = 0] = "DEFAULT";
|
|
8
|
-
ActionMode[ActionMode["DMZ"] = 1] = "DMZ";
|
|
9
|
-
ActionMode[ActionMode["DMZ_WITH_USER"] = 2] = "DMZ_WITH_USER";
|
|
10
|
-
})(ActionMode || (ActionMode = {}));
|
|
11
5
|
export default class BaseAction extends CoreAction {
|
|
12
6
|
constructor(chanel, module) {
|
|
13
7
|
super(chanel, module);
|
|
14
8
|
this.secureHandler = this.secureHandler.bind(this);
|
|
15
9
|
this.mode = ActionMode.DEFAULT;
|
|
16
10
|
this.forceDebug = false;
|
|
17
|
-
this.
|
|
11
|
+
this.requestSchema = null;
|
|
18
12
|
}
|
|
19
13
|
static validateSchema(error, schema, key, field, required = true) {
|
|
20
14
|
if (isSwaggerRef(schema)) {
|
|
@@ -88,7 +82,7 @@ export default class BaseAction extends CoreAction {
|
|
|
88
82
|
}
|
|
89
83
|
}
|
|
90
84
|
bodyValidation(req) {
|
|
91
|
-
if (!this.
|
|
85
|
+
if (!this.requestSchema) {
|
|
92
86
|
return null;
|
|
93
87
|
}
|
|
94
88
|
if (!req.body) {
|
|
@@ -99,12 +93,18 @@ export default class BaseAction extends CoreAction {
|
|
|
99
93
|
global: [],
|
|
100
94
|
field: [],
|
|
101
95
|
};
|
|
102
|
-
BaseAction.validateSchema(error, this.
|
|
96
|
+
BaseAction.validateSchema(error, this.requestSchema, 'body', req.body);
|
|
103
97
|
if (error.field.length > 0 || error.global.length > 0) {
|
|
104
98
|
return error;
|
|
105
99
|
}
|
|
106
100
|
return req.body;
|
|
107
101
|
}
|
|
102
|
+
static sendError(res, code, error) {
|
|
103
|
+
res.status(code).send({
|
|
104
|
+
type: 'error',
|
|
105
|
+
...error,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
108
|
async secureHandler(req, res, next) {
|
|
109
109
|
const extension = this.initExtension(res);
|
|
110
110
|
const auth = extension.timing.start('auth');
|
|
@@ -123,14 +123,14 @@ export default class BaseAction extends CoreAction {
|
|
|
123
123
|
auth.stop();
|
|
124
124
|
try {
|
|
125
125
|
let body = null;
|
|
126
|
-
if (this.
|
|
126
|
+
if (this.requestSchema) {
|
|
127
127
|
body = this.bodyValidation(req);
|
|
128
128
|
}
|
|
129
129
|
if (isErrorType(body)) {
|
|
130
130
|
res.status(400).send(body);
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
|
-
if (this.
|
|
133
|
+
if (this.requestSchema && body === null) {
|
|
134
134
|
res.sendStatus(400);
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
@@ -142,6 +142,7 @@ export default class BaseAction extends CoreAction {
|
|
|
142
142
|
extension,
|
|
143
143
|
agent: new BaseUserAgent(req),
|
|
144
144
|
body,
|
|
145
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
145
146
|
});
|
|
146
147
|
}
|
|
147
148
|
catch (e) {
|
|
@@ -158,14 +159,14 @@ export default class BaseAction extends CoreAction {
|
|
|
158
159
|
if (dat && typeof dat !== 'number') {
|
|
159
160
|
try {
|
|
160
161
|
let body = null;
|
|
161
|
-
if (this.
|
|
162
|
+
if (this.requestSchema) {
|
|
162
163
|
body = this.bodyValidation(req);
|
|
163
164
|
}
|
|
164
165
|
if (isErrorType(body)) {
|
|
165
166
|
res.status(400).send(body);
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
|
-
if (this.
|
|
169
|
+
if (this.requestSchema && body === null) {
|
|
169
170
|
res.sendStatus(400);
|
|
170
171
|
return;
|
|
171
172
|
}
|
|
@@ -177,6 +178,7 @@ export default class BaseAction extends CoreAction {
|
|
|
177
178
|
extension,
|
|
178
179
|
agent: new BaseUserAgent(req),
|
|
179
180
|
body,
|
|
181
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
180
182
|
});
|
|
181
183
|
}
|
|
182
184
|
catch (e) {
|
|
@@ -190,14 +192,14 @@ export default class BaseAction extends CoreAction {
|
|
|
190
192
|
else if (this.mode === ActionMode.DMZ_WITH_USER) {
|
|
191
193
|
try {
|
|
192
194
|
let body = null;
|
|
193
|
-
if (this.
|
|
195
|
+
if (this.requestSchema) {
|
|
194
196
|
body = this.bodyValidation(req);
|
|
195
197
|
}
|
|
196
198
|
if (isErrorType(body)) {
|
|
197
199
|
res.status(400).send(body);
|
|
198
200
|
return;
|
|
199
201
|
}
|
|
200
|
-
if (this.
|
|
202
|
+
if (this.requestSchema && body === null) {
|
|
201
203
|
res.sendStatus(400);
|
|
202
204
|
return;
|
|
203
205
|
}
|
|
@@ -209,6 +211,7 @@ export default class BaseAction extends CoreAction {
|
|
|
209
211
|
extension,
|
|
210
212
|
agent: new BaseUserAgent(req),
|
|
211
213
|
body,
|
|
214
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
212
215
|
});
|
|
213
216
|
}
|
|
214
217
|
catch (e) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IDataBase } from '@grandlinex/core';
|
|
2
|
-
import { ActionTypes
|
|
2
|
+
import { ActionTypes } from '@grandlinex/swagger-mate';
|
|
3
|
+
import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
4
|
import BaseAction from './BaseAction.js';
|
|
4
5
|
export default abstract class BaseApiAction<K extends IKernel = IKernel, T extends IDataBase<any, any> | null = any, P extends IBaseClient | null = any, C extends IBaseCache | null = any, E extends IBasePresenter | null = any> extends BaseAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
|
|
5
6
|
exmod: undefined | IBaseKernelModule<K>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { getRouteMeta } from '
|
|
1
|
+
import { getRouteMeta } from '@grandlinex/swagger-mate';
|
|
2
2
|
import BaseApiAction from './BaseApiAction.js';
|
|
3
3
|
export default class RouteApiAction extends BaseApiAction {
|
|
4
4
|
constructor(module, extMod) {
|
|
5
5
|
super('GET', 'action', module, extMod);
|
|
6
6
|
this.exmod = extMod;
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
7
|
+
const route = getRouteMeta(this);
|
|
8
|
+
if (!route) {
|
|
9
9
|
throw this.lError('No route meta found for action');
|
|
10
10
|
}
|
|
11
|
-
const { type, path,
|
|
11
|
+
const { type, path, meta } = route;
|
|
12
12
|
this.type = type;
|
|
13
13
|
this.channel = path;
|
|
14
|
-
if (mode) {
|
|
15
|
-
this.setMode(mode);
|
|
14
|
+
if (meta?.mode) {
|
|
15
|
+
this.setMode(meta.mode);
|
|
16
16
|
}
|
|
17
|
-
this.
|
|
17
|
+
this.requestSchema = meta?.requestSchema ?? null;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -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
|
|
2
|
+
import BaseAction 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';
|
|
@@ -9,4 +9,4 @@ export * from './BaseAction.js';
|
|
|
9
9
|
export * from './BaseUserAgent.js';
|
|
10
10
|
export * from './BaseAuthProvider.js';
|
|
11
11
|
export * from './timing/index.js';
|
|
12
|
-
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody,
|
|
12
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
|
|
@@ -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
|
|
2
|
+
import BaseAction 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';
|
|
@@ -9,4 +9,4 @@ export * from './BaseAction.js';
|
|
|
9
9
|
export * from './BaseUserAgent.js';
|
|
10
10
|
export * from './BaseAuthProvider.js';
|
|
11
11
|
export * from './timing/index.js';
|
|
12
|
-
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody,
|
|
12
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, };
|
package/dist/mjs/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import Kernel from './Kernel.js';
|
|
|
6
6
|
import KernelModule from './KernelModule.js';
|
|
7
7
|
export * from './actions/index.js';
|
|
8
8
|
export * from './api/index.js';
|
|
9
|
-
export * from './annotation/index.js';
|
|
10
9
|
export * from './classes/index.js';
|
|
11
10
|
export * from './modules/crypto/index.js';
|
|
12
11
|
export * from './lib/index.js';
|
package/dist/mjs/index.js
CHANGED
|
@@ -6,7 +6,6 @@ import Kernel from './Kernel.js';
|
|
|
6
6
|
import KernelModule from './KernelModule.js';
|
|
7
7
|
export * from './actions/index.js';
|
|
8
8
|
export * from './api/index.js';
|
|
9
|
-
export * from './annotation/index.js';
|
|
10
9
|
export * from './classes/index.js';
|
|
11
10
|
export * from './modules/crypto/index.js';
|
|
12
11
|
export * from './lib/index.js';
|