c2-http 1.0.158 → 1.0.160

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.
@@ -1,6 +1,6 @@
1
1
  import { NextFunction, Request, Response } from "express";
2
2
  declare class MiddlewareCheckTokenFlow {
3
- execute(): Promise<(request: Request, response: Response, next: NextFunction) => Promise<void>>;
3
+ execute(request: Request, response: Response, next: NextFunction): Promise<void>;
4
4
  checkToken(): Promise<void>;
5
5
  }
6
6
  declare const _default: MiddlewareCheckTokenFlow;
@@ -10,30 +10,28 @@ const GetTokenFlowItem_1 = __importDefault(require("./item/GetTokenFlowItem"));
10
10
  const ValidateTokenFlowItem_1 = __importDefault(require("./item/ValidateTokenFlowItem"));
11
11
  const c2_util_1 = require("c2-util");
12
12
  class MiddlewareCheckTokenFlow {
13
- async execute() {
14
- return async (request, response, next) => {
15
- try {
16
- if ((request.path === "/metrics" ||
17
- request.path.startsWith("/metrics") ||
18
- request.path?.includes("/docs"))
19
- && request.method === "GET") {
20
- next();
21
- return;
22
- }
23
- if (request.headers["x-api-key"]) {
24
- next();
25
- return;
26
- }
27
- await this.checkToken();
28
- return next();
13
+ async execute(request, response, next) {
14
+ try {
15
+ if ((request.path === "/metrics" ||
16
+ request.path.startsWith("/metrics") ||
17
+ request.path?.includes("/docs"))
18
+ && request.method === "GET") {
19
+ next();
20
+ return;
29
21
  }
30
- catch (error) {
31
- (0, c2_util_1.log)("LOG_ERROR_CHECK_TOKEN", error);
32
- response
33
- .status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
34
- .json({ message: error.message, detail: error.detail?.data });
22
+ if (request.headers["x-api-key"]) {
23
+ next();
24
+ return;
35
25
  }
36
- };
26
+ await this.checkToken();
27
+ return next();
28
+ }
29
+ catch (error) {
30
+ (0, c2_util_1.log)("LOG_ERROR_CHECK_TOKEN", error);
31
+ response
32
+ .status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
33
+ .json({ message: error.message, detail: error.detail?.data });
34
+ }
37
35
  }
38
36
  async checkToken() {
39
37
  let token = "";
@@ -102,7 +102,7 @@ function HttpDispatchDownload(target, methodName, descriptor) {
102
102
  try {
103
103
  const blockedDate = express_http_context_1.default.get("accountBlockDate");
104
104
  if (blockedDate && (0, moment_1.default)().isAfter((0, moment_1.default)(blockedDate))) {
105
- return response.status(http_status_1.PAYMENT_REQUIRED);
105
+ return response.status(http_status_1.PAYMENT_REQUIRED).end();
106
106
  }
107
107
  const [status, data] = await originalMethod.apply(this, args);
108
108
  return response.status(status).send(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.158",
3
+ "version": "1.0.160",
4
4
  "description": "Biblioteca Typescript para API NodeJS",
5
5
  "repository": "https://cabralsilva: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@github.com/cabralsilva/c2-http.git",
6
6
  "author": "Daniel Cabral <cabralconsultoriaemsoftware@gmail.com>",