c2-http 1.0.144 → 1.0.145

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,7 @@
1
1
  import { NextFunction, Request, Response } from "express";
2
2
  declare class MiddlewareCheckTokenFlow {
3
3
  execute(): Promise<(request: Request, response: Response, next: NextFunction) => Promise<void>>;
4
+ config: (request: Request, response: Response, next: NextFunction) => Promise<void>;
4
5
  checkToken(): Promise<void>;
5
6
  }
6
7
  declare const _default: MiddlewareCheckTokenFlow;
@@ -37,33 +37,31 @@ class MiddlewareCheckTokenFlow {
37
37
  }
38
38
  };
39
39
  }
40
- // public config = async (request: Request, response: Response, next: NextFunction) => {
41
- // log("LOG_CHECK_TOKEN", "Checking token");
42
- // try {
43
- // if (
44
- // (
45
- // request.path === "/metrics" ||
46
- // request.path.startsWith("/metrics") ||
47
- // request.path?.includes("/docs")
48
- // )
49
- // && request.method === "GET") {
50
- // next();
51
- // return;
52
- // }
53
- // if (request.headers["x-api-key"]) {
54
- // next();
55
- // return;
56
- // }
57
- // await this.checkToken()
58
- // log("LOG_CHECK_TOKEN", "Token checked");
59
- // return next()
60
- // } catch (error: any) {
61
- // log("LOG_ERROR_CHECK_TOKEN", error);
62
- // response
63
- // .status(error.status || INTERNAL_SERVER_ERROR)
64
- // .json({ message: error.message, detail: error.detail?.data });
65
- // }
66
- // }
40
+ config = async (request, response, next) => {
41
+ (0, c2_util_1.log)("LOG_CHECK_TOKEN", "Checking token");
42
+ try {
43
+ if ((request.path === "/metrics" ||
44
+ request.path.startsWith("/metrics") ||
45
+ request.path?.includes("/docs"))
46
+ && request.method === "GET") {
47
+ next();
48
+ return;
49
+ }
50
+ if (request.headers["x-api-key"]) {
51
+ next();
52
+ return;
53
+ }
54
+ await this.checkToken();
55
+ (0, c2_util_1.log)("LOG_CHECK_TOKEN", "Token checked");
56
+ return next();
57
+ }
58
+ catch (error) {
59
+ (0, c2_util_1.log)("LOG_ERROR_CHECK_TOKEN", error);
60
+ response
61
+ .status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
62
+ .json({ message: error.message, detail: error.detail?.data });
63
+ }
64
+ };
67
65
  async checkToken() {
68
66
  let token = "";
69
67
  try {
@@ -72,6 +70,7 @@ class MiddlewareCheckTokenFlow {
72
70
  AddInContextFlowItem_1.default.exec(tokenDecoded, token);
73
71
  }
74
72
  catch (error) {
73
+ (0, c2_util_1.log)("LOG_ERROR_CHECK_TOKEN_CHECK_TOKEN", error);
75
74
  throw (0, __1.convertErrorToHttpError)(error);
76
75
  }
77
76
  }
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const express_http_context_1 = __importDefault(require("express-http-context"));
7
+ const c2_util_1 = require("c2-util");
7
8
  class AddInContextFlowItem {
8
9
  exec(decode, token) {
9
10
  express_http_context_1.default.set("token", token);
@@ -16,6 +17,17 @@ class AddInContextFlowItem {
16
17
  express_http_context_1.default.set("accountBlockDate", decode.accountBlockDate);
17
18
  express_http_context_1.default.set("accountExpireDate", decode.accountExpireDate);
18
19
  express_http_context_1.default.set("scopes", decode.scopes);
20
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT", "Adding in context");
21
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_TOKEN", express_http_context_1.default.get("token"));
22
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_USER_ID", express_http_context_1.default.get("userId"));
23
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_USER_PROFILE_ID", express_http_context_1.default.get("userProfileId"));
24
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_USER_IS_ADMIN", express_http_context_1.default.get("userIsAdmin"));
25
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_USER_EMAIL", express_http_context_1.default.get("userEmail"));
26
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_USER_NAME", express_http_context_1.default.get("userName"));
27
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_ACCOUNT_ID", express_http_context_1.default.get("accountId"));
28
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_ACCOUNT_BLOCK_DATE", express_http_context_1.default.get("accountBlockDate"));
29
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_ACCOUNT_EXPIRE_DATE", express_http_context_1.default.get("accountExpireDate"));
30
+ (0, c2_util_1.log)("LOG_ADD_IN_CONTEXT_SCOPES", express_http_context_1.default.get("scopes"));
19
31
  }
20
32
  }
21
33
  exports.default = new AddInContextFlowItem;
@@ -40,7 +40,7 @@ class Server {
40
40
  // this.app.use("/docs", swaggerUI.serve, swaggerUI.setup((global as any).OPEN_API_DOC))
41
41
  (0, c2_util_1.log)("LOG", "Rotas abertas OK");
42
42
  //middlewares de checagem de token obrigatorio
43
- this.app.use(MiddlewareCheckTokenFlow_1.default.execute);
43
+ this.app.use(MiddlewareCheckTokenFlow_1.default.config);
44
44
  //middlewares de checagem de token opcional
45
45
  // this.config.middlewaresCloseControllers?.forEach((middl: RequestHandler) => {
46
46
  // this.app.use(middl)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.144",
3
+ "version": "1.0.145",
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>",