@wabot-dev/framework 0.5.5 → 0.5.6

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.
@@ -7,7 +7,7 @@ import '../../../core/validation/metadata/ValidationMetadataStore.js';
7
7
  import '../../../feature/express/ExpressProvider.js';
8
8
  import 'express';
9
9
  import 'path';
10
- import '../../../feature/rest-controller/RestRequest.js';
10
+ import 'http';
11
11
  import { ApiKeyGuardMiddleware } from './ApiKeyGuardMiddleware.js';
12
12
 
13
13
  function apiKeyGuard() {
@@ -7,7 +7,7 @@ import '../../../core/validation/metadata/ValidationMetadataStore.js';
7
7
  import '../../../feature/express/ExpressProvider.js';
8
8
  import 'express';
9
9
  import 'path';
10
- import '../../../feature/rest-controller/RestRequest.js';
10
+ import 'http';
11
11
  import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
12
12
 
13
13
  function jwtGuard() {
@@ -1,14 +1,4 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import '../../core/injection/index.js';
3
- import '../../core/validation/metadata/ValidationMetadataStore.js';
4
- import { isRecord } from '../../core/validation/validators/is-record/@isRecord.js';
5
-
6
1
  class RestRequest {
7
- headers;
8
2
  }
9
- __decorate([
10
- isRecord('string', 'string'),
11
- __metadata("design:type", Object)
12
- ], RestRequest.prototype, "headers", void 0);
13
3
 
14
4
  export { RestRequest };
@@ -10,6 +10,7 @@ import path__default from 'path';
10
10
  import { EXPRESS_REQ, EXPRESS_RES } from './injection-tokens.js';
11
11
  import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
12
12
  import { RestRequest } from './RestRequest.js';
13
+ import { IncomingMessage } from 'http';
13
14
 
14
15
  function buildRequest(req) {
15
16
  return Object.assign({}, req.body, req.query, req.params);
@@ -51,18 +52,23 @@ function runRestControllers(controllers) {
51
52
  }
52
53
  if (endPoint.paramsTypes.length === 1) {
53
54
  const paramType = endPoint.paramsTypes[0];
54
- if (typeof paramType !== 'function') {
55
- throw new Error(`invalid rest controller endpoint parameter type`);
55
+ if (paramType === IncomingMessage) {
56
+ endPointArgs.push(req);
56
57
  }
57
- const paramInfo = validationMetadataStore.getModelValidatorsInfo(paramType);
58
- const validableReq = paramInfo.modelHierarchy.includes(RestRequest)
59
- ? req
60
- : buildRequest(req);
61
- const { value, error } = validateModel(validableReq, paramInfo);
62
- if (error) {
63
- throw new CustomError({ httpCode: 400, message: error.description, info: error });
58
+ else {
59
+ if (typeof paramType !== 'function') {
60
+ throw new Error(`invalid rest controller endpoint parameter type`);
61
+ }
62
+ const paramInfo = validationMetadataStore.getModelValidatorsInfo(paramType);
63
+ const validableReq = paramInfo.modelHierarchy.includes(RestRequest)
64
+ ? req
65
+ : buildRequest(req);
66
+ const { value, error } = validateModel(validableReq, paramInfo);
67
+ if (error) {
68
+ throw new CustomError({ httpCode: 400, message: error.description, info: error });
69
+ }
70
+ endPointArgs.push(value);
64
71
  }
65
- endPointArgs.push(value);
66
72
  }
67
73
  const response = await controllerInstance[endPoint.functionName].apply(controllerInstance, endPointArgs);
68
74
  res.status(200).json(response ?? null);
@@ -1221,7 +1221,6 @@ declare const EXPRESS_REQ = "EXPRESS_REQ";
1221
1221
  declare const EXPRESS_RES = "EXPRESS_RES";
1222
1222
 
1223
1223
  declare class RestRequest {
1224
- headers?: Record<string, string>;
1225
1224
  }
1226
1225
 
1227
1226
  declare class SocketServerConfig {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wabot-dev/framework",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "Framework for IA Chat Bots",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",