@grandlinex/kernel 1.0.2 → 1.1.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/dist/cjs/KernelModule.js +1 -1
- package/dist/cjs/actions/ApiAuthTestAction.d.ts +2 -4
- package/dist/cjs/actions/ApiAuthTestAction.js +3 -9
- package/dist/cjs/actions/ApiVersionAction.d.ts +2 -4
- package/dist/cjs/actions/ApiVersionAction.js +3 -10
- package/dist/cjs/actions/GetTokenAction.d.ts +8 -9
- package/dist/cjs/actions/GetTokenAction.js +18 -36
- package/dist/cjs/annotation/index.d.ts +13 -0
- package/dist/cjs/annotation/index.js +21 -0
- package/dist/cjs/classes/BaseAction.d.ts +5 -0
- package/dist/cjs/classes/BaseAction.js +140 -1
- package/dist/cjs/classes/BaseApiAction.js +1 -1
- package/dist/cjs/classes/RouteApiAction.d.ts +6 -0
- package/dist/cjs/classes/RouteApiAction.js +25 -0
- package/dist/cjs/classes/index.d.ts +2 -1
- package/dist/cjs/classes/index.js +3 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/lib/express.d.ts +4 -1
- package/dist/cjs/modules/crypto/CryptoClient.d.ts +3 -2
- package/dist/cjs/modules/crypto/CryptoClient.js +2 -1
- package/dist/mjs/KernelModule.js +2 -2
- package/dist/mjs/actions/ApiAuthTestAction.d.ts +2 -4
- package/dist/mjs/actions/ApiAuthTestAction.js +4 -10
- package/dist/mjs/actions/ApiVersionAction.d.ts +2 -4
- package/dist/mjs/actions/ApiVersionAction.js +4 -11
- package/dist/mjs/actions/GetTokenAction.d.ts +8 -9
- package/dist/mjs/actions/GetTokenAction.js +19 -37
- package/dist/mjs/annotation/index.d.ts +13 -0
- package/dist/mjs/annotation/index.js +16 -0
- package/dist/mjs/classes/BaseAction.d.ts +5 -0
- package/dist/mjs/classes/BaseAction.js +140 -1
- package/dist/mjs/classes/BaseApiAction.js +1 -1
- package/dist/mjs/classes/RouteApiAction.d.ts +6 -0
- package/dist/mjs/classes/RouteApiAction.js +19 -0
- package/dist/mjs/classes/index.d.ts +2 -1
- package/dist/mjs/classes/index.js +2 -1
- package/dist/mjs/index.d.ts +1 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/lib/express.d.ts +4 -1
- package/dist/mjs/modules/crypto/CryptoClient.d.ts +3 -2
- package/dist/mjs/modules/crypto/CryptoClient.js +2 -1
- package/package.json +13 -12
- package/tsconfig-cjs.json +0 -92
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseApiAction } from '../classes/index.js';
|
|
1
|
+
import { RouteApiAction } from '../classes/index.js';
|
|
3
2
|
import { XActionEvent } from '../lib/express.js';
|
|
4
|
-
export default class ApiVersionAction extends
|
|
5
|
-
constructor(module: IBaseKernelModule);
|
|
3
|
+
export default class ApiVersionAction extends RouteApiAction {
|
|
6
4
|
handler({ res, extension }: XActionEvent): Promise<void>;
|
|
7
5
|
}
|
|
@@ -4,17 +4,10 @@ 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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { SPath, SPathUtil } from '@grandlinex/swagger-mate';
|
|
11
|
-
import { ActionMode,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
super('GET', '/version', module);
|
|
15
|
-
this.handler = this.handler.bind(this);
|
|
16
|
-
this.setMode(ActionMode.DMZ);
|
|
17
|
-
}
|
|
8
|
+
import { ActionMode, RouteApiAction } from '../classes/index.js';
|
|
9
|
+
import { Route } from '../annotation/index.js';
|
|
10
|
+
let ApiVersionAction = class ApiVersionAction extends RouteApiAction {
|
|
18
11
|
async handler({ res, extension }) {
|
|
19
12
|
extension.done();
|
|
20
13
|
res.status(200).send({ api: this.getKernel().getApiVersion() });
|
|
@@ -39,6 +32,6 @@ ApiVersionAction = __decorate([
|
|
|
39
32
|
},
|
|
40
33
|
},
|
|
41
34
|
}),
|
|
42
|
-
|
|
35
|
+
Route('GET', '/version', ActionMode.DMZ)
|
|
43
36
|
], ApiVersionAction);
|
|
44
37
|
export default ApiVersionAction;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseApiAction, JwtToken } from '../classes/index.js';
|
|
1
|
+
import { JwtToken, RouteApiAction } from '../classes/index.js';
|
|
3
2
|
import { XActionEvent } from '../lib/express.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
handler({ req, res, extension, }: XActionEvent<JwtToken>): Promise<void>;
|
|
3
|
+
type SchemaType = {
|
|
4
|
+
username: string;
|
|
5
|
+
token: string;
|
|
6
|
+
};
|
|
7
|
+
export default class GetTokenAction extends RouteApiAction {
|
|
8
|
+
handler({ req, res, extension, body, }: XActionEvent<JwtToken, SchemaType>): Promise<void>;
|
|
11
9
|
}
|
|
10
|
+
export {};
|
|
@@ -4,32 +4,25 @@ 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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { SPath, SPathUtil } from '@grandlinex/swagger-mate';
|
|
11
|
-
import { ActionMode,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
import { ActionMode, RouteApiAction } from '../classes/index.js';
|
|
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
|
+
};
|
|
22
|
+
let GetTokenAction = class GetTokenAction extends RouteApiAction {
|
|
23
|
+
async handler({ req, res, extension, body, }) {
|
|
23
24
|
const cc = this.getKernel().getCryptoClient();
|
|
24
|
-
|
|
25
|
-
res.status(400).send('no token');
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (!req.body.username) {
|
|
29
|
-
res.status(401).send('no username');
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const { username, token } = req.body;
|
|
25
|
+
const { username, token } = body;
|
|
33
26
|
const valid = await extension.timing.startFunc('validation', () => cc.apiTokenValidation(username, token, 'api'));
|
|
34
27
|
if (valid.valid && valid.userId) {
|
|
35
28
|
const jwt = await cc.jwtGenerateAccessToken({
|
|
@@ -51,18 +44,7 @@ GetTokenAction = __decorate([
|
|
|
51
44
|
operationId: 'getToken',
|
|
52
45
|
summary: 'Get API token',
|
|
53
46
|
tags: ['kernel'],
|
|
54
|
-
requestBody: SPathUtil.jsonBody(
|
|
55
|
-
type: 'object',
|
|
56
|
-
properties: {
|
|
57
|
-
username: {
|
|
58
|
-
type: 'string',
|
|
59
|
-
},
|
|
60
|
-
token: {
|
|
61
|
-
type: 'string',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
required: ['username', 'token'],
|
|
65
|
-
}),
|
|
47
|
+
requestBody: SPathUtil.jsonBody(schema),
|
|
66
48
|
responses: SPathUtil.jsonResponse('200', {
|
|
67
49
|
type: 'object',
|
|
68
50
|
properties: {
|
|
@@ -75,6 +57,6 @@ GetTokenAction = __decorate([
|
|
|
75
57
|
},
|
|
76
58
|
},
|
|
77
59
|
}),
|
|
78
|
-
|
|
60
|
+
Route('POST', '/token', ActionMode.DMZ, schema)
|
|
79
61
|
], GetTokenAction);
|
|
80
62
|
export default GetTokenAction;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { ObjectLike } from '@grandlinex/core';
|
|
3
|
+
import { SSchemaEl } from '@grandlinex/swagger-mate';
|
|
4
|
+
import { ActionTypes } from '../lib/index.js';
|
|
5
|
+
import { ActionMode } from '../classes/index.js';
|
|
6
|
+
export type RouteMeta = {
|
|
7
|
+
type: ActionTypes;
|
|
8
|
+
path: string;
|
|
9
|
+
mode?: ActionMode;
|
|
10
|
+
schema?: SSchemaEl;
|
|
11
|
+
};
|
|
12
|
+
export declare const Route: (type: ActionTypes, path: string, mode?: ActionMode, schema?: SSchemaEl) => ClassDecorator;
|
|
13
|
+
export declare function getRouteMeta<T extends ObjectLike>(target: T): RouteMeta | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
const routeKey = Symbol('route');
|
|
3
|
+
export const Route = (type, path, mode, schema) => {
|
|
4
|
+
return (target) => {
|
|
5
|
+
const metadata = {
|
|
6
|
+
type,
|
|
7
|
+
path,
|
|
8
|
+
mode,
|
|
9
|
+
schema,
|
|
10
|
+
};
|
|
11
|
+
Reflect.defineMetadata(routeKey, metadata, target.prototype);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export function getRouteMeta(target) {
|
|
15
|
+
return Reflect.getMetadata(routeKey, target.constructor.prototype);
|
|
16
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CoreAction, IDataBase } from '@grandlinex/core';
|
|
2
|
+
import { ErrorType, SSchemaEl } from '@grandlinex/swagger-mate';
|
|
2
3
|
import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
4
|
import { XActionEvent, XRequest, XResponse } from '../lib/express.js';
|
|
4
5
|
export declare enum ActionMode {
|
|
@@ -9,8 +10,12 @@ export declare enum ActionMode {
|
|
|
9
10
|
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> {
|
|
10
11
|
mode: ActionMode;
|
|
11
12
|
forceDebug: boolean;
|
|
13
|
+
schema: SSchemaEl | null;
|
|
12
14
|
constructor(chanel: string, module: IBaseKernelModule<K, T, P, C, E>);
|
|
13
15
|
abstract handler(event: XActionEvent): Promise<void>;
|
|
16
|
+
static validateSchema(error: ErrorType, schema: SSchemaEl, key: string, field: any, required?: boolean): void;
|
|
17
|
+
bodyValidation<A>(req: XRequest): A | ErrorType | null;
|
|
18
|
+
static sendError(res: XResponse, code: number, error: Partial<ErrorType>): void;
|
|
14
19
|
secureHandler(req: XRequest, res: XResponse, next: () => void): Promise<void>;
|
|
15
20
|
setMode(mode: ActionMode): void;
|
|
16
21
|
abstract register(): void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CoreAction } from '@grandlinex/core';
|
|
2
|
+
import { isErrorType, isSwaggerRef, } from '@grandlinex/swagger-mate';
|
|
2
3
|
import { ExpressServerTiming } from './timing/index.js';
|
|
3
4
|
import { BaseUserAgent } from './BaseUserAgent.js';
|
|
4
5
|
export var ActionMode;
|
|
@@ -13,6 +14,102 @@ export default class BaseAction extends CoreAction {
|
|
|
13
14
|
this.secureHandler = this.secureHandler.bind(this);
|
|
14
15
|
this.mode = ActionMode.DEFAULT;
|
|
15
16
|
this.forceDebug = false;
|
|
17
|
+
this.schema = null;
|
|
18
|
+
}
|
|
19
|
+
static validateSchema(error, schema, key, field, required = true) {
|
|
20
|
+
if (isSwaggerRef(schema)) {
|
|
21
|
+
error.field?.push({
|
|
22
|
+
key,
|
|
23
|
+
message: `Ref schema body validation is not supported yet`,
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!required && (field === undefined || field === null)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
switch (schema?.type) {
|
|
31
|
+
case 'boolean':
|
|
32
|
+
if (typeof field !== 'boolean') {
|
|
33
|
+
error.field?.push({
|
|
34
|
+
key,
|
|
35
|
+
message: `must be a boolean`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case 'integer':
|
|
40
|
+
case 'number':
|
|
41
|
+
if (typeof field !== 'number') {
|
|
42
|
+
error.field?.push({
|
|
43
|
+
key,
|
|
44
|
+
message: `must be a number`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
case 'string':
|
|
49
|
+
if (typeof field !== 'string') {
|
|
50
|
+
error.field?.push({
|
|
51
|
+
key,
|
|
52
|
+
message: `must be a string`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'array':
|
|
57
|
+
if (!Array.isArray(field)) {
|
|
58
|
+
error.field?.push({
|
|
59
|
+
key,
|
|
60
|
+
message: `must be a array`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (schema.items) {
|
|
64
|
+
field.forEach((it, id) => {
|
|
65
|
+
this.validateSchema(error, schema.items, `${key}[${id}]`, it);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 'object':
|
|
70
|
+
if (typeof field !== 'object') {
|
|
71
|
+
error.field?.push({
|
|
72
|
+
key,
|
|
73
|
+
message: `must be a object`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (schema.properties) {
|
|
77
|
+
Object.entries(schema.properties).forEach(([k, s]) => {
|
|
78
|
+
this.validateSchema(error, s, `${key}.${k}`, field[k], schema.required ? schema.required.includes(k) : false);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case undefined:
|
|
83
|
+
default:
|
|
84
|
+
error.field?.push({
|
|
85
|
+
key,
|
|
86
|
+
message: `Schema type is not defined or not supported`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
bodyValidation(req) {
|
|
91
|
+
if (!this.schema) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (!req.body) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const error = {
|
|
98
|
+
type: 'error',
|
|
99
|
+
global: [],
|
|
100
|
+
field: [],
|
|
101
|
+
};
|
|
102
|
+
BaseAction.validateSchema(error, this.schema, 'body', req.body);
|
|
103
|
+
if (error.field.length > 0 || error.global.length > 0) {
|
|
104
|
+
return error;
|
|
105
|
+
}
|
|
106
|
+
return req.body;
|
|
107
|
+
}
|
|
108
|
+
static sendError(res, code, error) {
|
|
109
|
+
res.status(code).send({
|
|
110
|
+
type: 'error',
|
|
111
|
+
...error,
|
|
112
|
+
});
|
|
16
113
|
}
|
|
17
114
|
async secureHandler(req, res, next) {
|
|
18
115
|
const extension = this.initExtension(res);
|
|
@@ -31,6 +128,18 @@ export default class BaseAction extends CoreAction {
|
|
|
31
128
|
if (this.mode === ActionMode.DMZ) {
|
|
32
129
|
auth.stop();
|
|
33
130
|
try {
|
|
131
|
+
let body = null;
|
|
132
|
+
if (this.schema) {
|
|
133
|
+
body = this.bodyValidation(req);
|
|
134
|
+
}
|
|
135
|
+
if (isErrorType(body)) {
|
|
136
|
+
res.status(400).send(body);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (this.schema && body === null) {
|
|
140
|
+
res.sendStatus(400);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
34
143
|
await this.handler({
|
|
35
144
|
res,
|
|
36
145
|
req,
|
|
@@ -38,6 +147,8 @@ export default class BaseAction extends CoreAction {
|
|
|
38
147
|
data: null,
|
|
39
148
|
extension,
|
|
40
149
|
agent: new BaseUserAgent(req),
|
|
150
|
+
body,
|
|
151
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
41
152
|
});
|
|
42
153
|
}
|
|
43
154
|
catch (e) {
|
|
@@ -53,6 +164,18 @@ export default class BaseAction extends CoreAction {
|
|
|
53
164
|
auth.stop();
|
|
54
165
|
if (dat && typeof dat !== 'number') {
|
|
55
166
|
try {
|
|
167
|
+
let body = null;
|
|
168
|
+
if (this.schema) {
|
|
169
|
+
body = this.bodyValidation(req);
|
|
170
|
+
}
|
|
171
|
+
if (isErrorType(body)) {
|
|
172
|
+
res.status(400).send(body);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (this.schema && body === null) {
|
|
176
|
+
res.sendStatus(400);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
56
179
|
await this.handler({
|
|
57
180
|
res,
|
|
58
181
|
req,
|
|
@@ -60,6 +183,8 @@ export default class BaseAction extends CoreAction {
|
|
|
60
183
|
data: dat,
|
|
61
184
|
extension,
|
|
62
185
|
agent: new BaseUserAgent(req),
|
|
186
|
+
body,
|
|
187
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
63
188
|
});
|
|
64
189
|
}
|
|
65
190
|
catch (e) {
|
|
@@ -72,6 +197,18 @@ export default class BaseAction extends CoreAction {
|
|
|
72
197
|
}
|
|
73
198
|
else if (this.mode === ActionMode.DMZ_WITH_USER) {
|
|
74
199
|
try {
|
|
200
|
+
let body = null;
|
|
201
|
+
if (this.schema) {
|
|
202
|
+
body = this.bodyValidation(req);
|
|
203
|
+
}
|
|
204
|
+
if (isErrorType(body)) {
|
|
205
|
+
res.status(400).send(body);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (this.schema && body === null) {
|
|
209
|
+
res.sendStatus(400);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
75
212
|
await this.handler({
|
|
76
213
|
res,
|
|
77
214
|
req,
|
|
@@ -79,6 +216,8 @@ export default class BaseAction extends CoreAction {
|
|
|
79
216
|
data: null,
|
|
80
217
|
extension,
|
|
81
218
|
agent: new BaseUserAgent(req),
|
|
219
|
+
body,
|
|
220
|
+
sendError: (code, error) => BaseAction.sendError(res, code, error),
|
|
82
221
|
});
|
|
83
222
|
}
|
|
84
223
|
catch (e) {
|
|
@@ -93,7 +232,7 @@ export default class BaseAction extends CoreAction {
|
|
|
93
232
|
res.sendStatus(dat);
|
|
94
233
|
}
|
|
95
234
|
else {
|
|
96
|
-
res.
|
|
235
|
+
res.sendStatus(401);
|
|
97
236
|
}
|
|
98
237
|
}
|
|
99
238
|
setMode(mode) {
|
|
@@ -11,7 +11,7 @@ export default class BaseApiAction extends BaseAction {
|
|
|
11
11
|
endpoint = this.exmod.getPresenter();
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
endpoint = this.getModule().getPresenter();
|
|
14
|
+
endpoint = this.getKernel().getModule().getPresenter();
|
|
15
15
|
}
|
|
16
16
|
if (endpoint) {
|
|
17
17
|
this.debug(`register ${this.type} ${this.getName()}`);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IDataBase } from '@grandlinex/core';
|
|
2
|
+
import { IBaseAction, IBaseCache, IBaseClient, IBaseKernelModule, IBasePresenter, IKernel } from '../lib/index.js';
|
|
3
|
+
import BaseApiAction from './BaseApiAction.js';
|
|
4
|
+
export default abstract class RouteApiAction<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 BaseApiAction<K, T, P, C, E> implements IBaseAction<K, T, P, C, E> {
|
|
5
|
+
constructor(module: IBaseKernelModule<K, T, P, C, E>, extMod?: IBaseKernelModule<K>);
|
|
6
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getRouteMeta } from '../annotation/index.js';
|
|
2
|
+
import BaseApiAction from './BaseApiAction.js';
|
|
3
|
+
export default class RouteApiAction extends BaseApiAction {
|
|
4
|
+
constructor(module, extMod) {
|
|
5
|
+
super('GET', 'action', module, extMod);
|
|
6
|
+
this.exmod = extMod;
|
|
7
|
+
const meta = getRouteMeta(this);
|
|
8
|
+
if (!meta) {
|
|
9
|
+
throw this.lError('No route meta found for action');
|
|
10
|
+
}
|
|
11
|
+
const { type, path, mode, schema } = meta;
|
|
12
|
+
this.type = type;
|
|
13
|
+
this.channel = path;
|
|
14
|
+
if (mode) {
|
|
15
|
+
this.setMode(mode);
|
|
16
|
+
}
|
|
17
|
+
this.schema = schema ?? null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -3,9 +3,10 @@ import BaseAction, { ActionMode } from './BaseAction.js';
|
|
|
3
3
|
import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
|
|
4
4
|
import BaseKernelModule from './BaseKernelModule.js';
|
|
5
5
|
import BaseApiAction from './BaseApiAction.js';
|
|
6
|
+
import RouteApiAction from './RouteApiAction.js';
|
|
6
7
|
import BaseAuthProvider from './BaseAuthProvider.js';
|
|
7
8
|
export * from './BaseAction.js';
|
|
8
9
|
export * from './BaseUserAgent.js';
|
|
9
10
|
export * from './BaseAuthProvider.js';
|
|
10
11
|
export * from './timing/index.js';
|
|
11
|
-
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
|
|
12
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
|
|
@@ -3,9 +3,10 @@ import BaseAction, { ActionMode } from './BaseAction.js';
|
|
|
3
3
|
import BaseEndpoint, { keepRawBody } from './BaseEndpoint.js';
|
|
4
4
|
import BaseKernelModule from './BaseKernelModule.js';
|
|
5
5
|
import BaseApiAction from './BaseApiAction.js';
|
|
6
|
+
import RouteApiAction from './RouteApiAction.js';
|
|
6
7
|
import BaseAuthProvider from './BaseAuthProvider.js';
|
|
7
8
|
export * from './BaseAction.js';
|
|
8
9
|
export * from './BaseUserAgent.js';
|
|
9
10
|
export * from './BaseAuthProvider.js';
|
|
10
11
|
export * from './timing/index.js';
|
|
11
|
-
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
|
|
12
|
+
export { BaseLoopService, BaseAuthProvider, BaseKernelModule, BaseService, BaseApiAction, BaseEndpoint, BaseElement, RouteApiAction, BaseCache, BaseAction, BaseClient, BaseBridge, keepRawBody, ActionMode, };
|
package/dist/mjs/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ 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';
|
|
9
10
|
export * from './classes/index.js';
|
|
10
11
|
export * from './modules/crypto/index.js';
|
|
11
12
|
export * from './lib/index.js';
|
package/dist/mjs/index.js
CHANGED
|
@@ -6,6 +6,7 @@ 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';
|
|
9
10
|
export * from './classes/index.js';
|
|
10
11
|
export * from './modules/crypto/index.js';
|
|
11
12
|
export * from './lib/index.js';
|
|
@@ -1,15 +1,18 @@
|
|
|
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;
|
|
5
6
|
};
|
|
6
7
|
export type XResponse = express.Response;
|
|
7
8
|
export type XNextFc = express.NextFunction;
|
|
8
|
-
export type XActionEvent<G = JwtToken | null> = {
|
|
9
|
+
export type XActionEvent<G = JwtToken | null, B = any> = {
|
|
9
10
|
req: XRequest;
|
|
10
11
|
res: XResponse;
|
|
11
12
|
next: XNextFc;
|
|
12
13
|
data: G;
|
|
13
14
|
extension: IExtensionInterface;
|
|
14
15
|
agent: BaseUserAgent;
|
|
16
|
+
body: B;
|
|
17
|
+
sendError: (code: number, error: Partial<ErrorType>) => void;
|
|
15
18
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { CoreCryptoClient } from '@grandlinex/core';
|
|
2
|
+
import { type StringValue } from 'ms';
|
|
2
3
|
import { ICClient, IKernel } from '../../lib/index.js';
|
|
3
4
|
import { IAuthProvider, JwtExtend, JwtToken } from '../../classes/index.js';
|
|
4
5
|
import { XRequest } from '../../lib/express.js';
|
|
5
6
|
export default class CryptoClient<T extends JwtExtend = JwtExtend> extends CoreCryptoClient implements ICClient<T> {
|
|
6
7
|
protected authProvider: IAuthProvider<T> | null;
|
|
7
8
|
protected kernel: IKernel;
|
|
8
|
-
protected expiresIn:
|
|
9
|
+
protected expiresIn: StringValue;
|
|
9
10
|
constructor(key: string, kernel: IKernel);
|
|
10
11
|
setAuthProvider(provider: IAuthProvider<T>): boolean;
|
|
11
12
|
jwtVerifyAccessToken(token: string): Promise<JwtToken<T> | number>;
|
|
12
13
|
jwtDecodeAccessToken(token: string): JwtToken<T> | null;
|
|
13
|
-
jwtGenerateAccessToken(data: JwtToken<T>, extend?: Record<string, any>, expire?:
|
|
14
|
+
jwtGenerateAccessToken(data: JwtToken<T>, extend?: Record<string, any>, expire?: StringValue | number): Promise<string>;
|
|
14
15
|
apiTokenValidation(username: string, token: string, requestType: string): Promise<{
|
|
15
16
|
valid: boolean;
|
|
16
17
|
userId: string | null;
|
|
@@ -5,7 +5,8 @@ export default class CryptoClient extends CoreCryptoClient {
|
|
|
5
5
|
super(kernel, key);
|
|
6
6
|
this.kernel = kernel;
|
|
7
7
|
this.authProvider = null;
|
|
8
|
-
this.expiresIn = kernel.getConfigStore().get('JWT_EXPIRE') ||
|
|
8
|
+
this.expiresIn = (kernel.getConfigStore().get('JWT_EXPIRE') ||
|
|
9
|
+
'1 days');
|
|
9
10
|
}
|
|
10
11
|
setAuthProvider(provider) {
|
|
11
12
|
if (this.authProvider) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/kernel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "GrandLineX is an out-of-the-box server framework on top of ExpressJs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"doc-converage": "jest --runInBand --ci --collectCoverage --coverageDirectory=\"./docs/coverage\" --reporters=default --reporters=jest-junit",
|
|
32
32
|
"makeDocs": "typedoc",
|
|
33
33
|
"openDocs": "npm run makeDocs",
|
|
34
|
-
"makeSpec": "
|
|
34
|
+
"makeSpec": "swagger-mate"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"typescript",
|
|
@@ -46,22 +46,23 @@
|
|
|
46
46
|
},
|
|
47
47
|
"license": "BSD-3-Clause",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"@grandlinex/
|
|
51
|
-
"
|
|
49
|
+
"reflect-metadata": "0.2.2",
|
|
50
|
+
"@grandlinex/core": "1.1.1",
|
|
51
|
+
"@grandlinex/swagger-mate": "1.1.1",
|
|
52
|
+
"axios": "1.11.0",
|
|
52
53
|
"body-parser": "1.20.3",
|
|
53
54
|
"express": "5.1.0",
|
|
54
55
|
"jsonwebtoken": "9.0.2",
|
|
55
56
|
"@types/express": "5.0.3",
|
|
56
|
-
"@types/jsonwebtoken": "9.0.
|
|
57
|
+
"@types/jsonwebtoken": "9.0.10",
|
|
58
|
+
"@types/ms": "2.1.0"
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
59
61
|
"@types/jest": "29.5.14",
|
|
60
|
-
"@types/node": "22.15.
|
|
62
|
+
"@types/node": "22.15.20",
|
|
61
63
|
"@typescript-eslint/eslint-plugin": "7.18.0",
|
|
62
64
|
"@typescript-eslint/parser": "7.18.0",
|
|
63
|
-
"
|
|
64
|
-
"eslint": "8.57.0",
|
|
65
|
+
"eslint": "8.57.1",
|
|
65
66
|
"eslint-config-airbnb": "19.0.4",
|
|
66
67
|
"eslint-config-airbnb-typescript": "18.0.0",
|
|
67
68
|
"eslint-config-prettier": "9.1.0",
|
|
@@ -71,12 +72,12 @@
|
|
|
71
72
|
"eslint-plugin-prettier": "5.2.1",
|
|
72
73
|
"jest": "29.7.0",
|
|
73
74
|
"jest-junit": "16.0.0",
|
|
74
|
-
"prettier": "3.
|
|
75
|
+
"prettier": "3.5.3",
|
|
75
76
|
"ts-jest": "29.3.4",
|
|
76
77
|
"ts-loader": "9.5.2",
|
|
77
78
|
"ts-node": "10.9.2",
|
|
78
|
-
"typedoc": "0.28.
|
|
79
|
-
"typescript": "5.
|
|
79
|
+
"typedoc": "0.28.10",
|
|
80
|
+
"typescript": "5.9.2"
|
|
80
81
|
},
|
|
81
82
|
"engines": {
|
|
82
83
|
"node": ">=22.0.0"
|