c2-http 1.0.132 → 1.0.134

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,7 +1,6 @@
1
1
  import express from "express";
2
2
  declare class MiddlewareBody {
3
3
  config(expressApplication: express.Application): void;
4
- convertDates(obj: any, headers: any): void;
5
4
  }
6
5
  declare const _default: MiddlewareBody;
7
6
  export default _default;
@@ -4,52 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const body_parser_1 = __importDefault(require("body-parser"));
7
+ const c2_util_1 = require("c2-util");
8
+ // import moment from "moment";
7
9
  class MiddlewareBody {
8
10
  config(expressApplication) {
9
11
  expressApplication.use(body_parser_1.default.json({ limit: "5mb" }));
10
12
  expressApplication.use(body_parser_1.default.urlencoded({ limit: "5mb", extended: true }));
11
13
  expressApplication.use(body_parser_1.default.text({ limit: "5mb" }));
12
14
  expressApplication.use((request, response, next) => {
15
+ (0, c2_util_1.log)("LOG_BODY", "Body middleware enabled");
13
16
  if (request.body && typeof request.body === "object") {
14
- this.convertDates(request.body, request.headers);
17
+ // this.convertDates(request.body, request.headers)
15
18
  }
16
19
  next();
17
20
  });
18
21
  }
19
- // private convertDates(request: Request): void {
20
- // for (const key in request.body) {
21
- // if (request.body.hasOwnProperty(key)) {
22
- // if (key.endsWith("Date") || key.endsWith("DateTime")) {
23
- // const tz = request.headers["timezone"] as string || "America/Sao_Paulo" as string; // fallback padrão
24
- // // interpreta como GMT-3
25
- // request.body[key] = moment.tz(request.body[key], "YYYY-MM-DD", tz);
26
- // // obj[key] = moment.utc(obj[key]);
27
- // } else if (typeof request.body[key] === "object" && request.body[key] !== null) {
28
- // this.convertDates(request.body[key]);
29
- // }
30
- // }
31
- // }
32
- // }
33
- convertDates(obj, headers) {
34
- // if (Array.isArray(obj)) {
35
- // // percorre arrays também
36
- // for (let i = 0; i < obj.length; i++) {
37
- // this.convertDates(obj[i], headers);
38
- // }
39
- // }
40
- // else if (typeof obj === "object" && obj !== null) {
41
- // for (const key in obj) {
42
- // if (!obj.hasOwnProperty(key)) continue;
43
- // const value = obj[key];
44
- // if (key.endsWith("Date") || key.endsWith("DateTime")) {
45
- // const tz = headers["timezone"] || "America/Sao_Paulo"; // fallback padrão
46
- // obj[key] = moment.tz(value, "YYYY-MM-DD", tz).utc();
47
- // }
48
- // else {
49
- // this.convertDates(value, headers); // recursivo
50
- // }
51
- // }
52
- // }
53
- }
54
22
  }
55
23
  exports.default = new MiddlewareBody;
@@ -3,11 +3,13 @@ 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 c2_util_1 = require("c2-util");
6
7
  const express_http_context_1 = __importDefault(require("express-http-context"));
7
8
  class MiddlewareContext {
8
9
  config(expressApplication) {
9
10
  expressApplication.use(express_http_context_1.default.middleware);
10
11
  expressApplication.use((request, response, next) => {
12
+ (0, c2_util_1.log)("LOG_CONTEXT", "Context middleware enabled");
11
13
  express_http_context_1.default.set("headers", request.headers);
12
14
  express_http_context_1.default.set("requestProtocol", request.protocol);
13
15
  express_http_context_1.default.set("requestHost", request.hostname);
@@ -3,27 +3,31 @@ 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 c2_util_1 = require("c2-util");
6
7
  const cors_1 = __importDefault(require("cors"));
7
8
  class MiddlewareCors {
8
9
  config(expressApplication) {
9
- expressApplication.use((0, cors_1.default)({
10
- origin: (origin, callback) => {
11
- // Permitir solicitações sem uma origem
12
- if (!origin)
10
+ expressApplication.use(() => {
11
+ (0, c2_util_1.log)("LOG_CORS", "CORS middleware enabled");
12
+ return (0, cors_1.default)({
13
+ origin: (origin, callback) => {
14
+ // Permitir solicitações sem uma origem
15
+ if (!origin)
16
+ return callback(null, true);
17
+ if (!process.env.ORIGIN_ENABLES) {
18
+ return callback(null, true);
19
+ }
20
+ if (process.env.ORIGIN_ENABLES.split(",").indexOf(origin) === -1) {
21
+ const msg = "Acesso não permitido para esta origem";
22
+ return callback(new Error(msg), false);
23
+ }
13
24
  return callback(null, true);
14
- if (!process.env.ORIGIN_ENABLES) {
15
- return callback(null, true);
16
- }
17
- if (process.env.ORIGIN_ENABLES.split(",").indexOf(origin) === -1) {
18
- const msg = "Acesso não permitido para esta origem";
19
- return callback(new Error(msg), false);
20
- }
21
- return callback(null, true);
22
- },
23
- methods: "GET,OPTIONS,PUT,POST,PATCH,DELETE",
24
- allowedHeaders: "Content-Type,Authorization,Origin,Accept",
25
- credentials: true
26
- }));
25
+ },
26
+ methods: "GET,OPTIONS,PUT,POST,PATCH,DELETE",
27
+ allowedHeaders: "Content-Type,Authorization,Origin,Accept",
28
+ credentials: true
29
+ });
30
+ });
27
31
  }
28
32
  }
29
33
  exports.default = new MiddlewareCors;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MiddlewareQueryParams = void 0;
4
+ const c2_util_1 = require("c2-util");
4
5
  class MiddlewareQueryParams {
5
6
  config(expressApplication) {
6
7
  expressApplication.use((request, response, next) => {
8
+ (0, c2_util_1.log)("LOG_QUERY_PARAMS", "Query params middleware enabled");
7
9
  for (const key in request.query) {
8
10
  if (request.query.hasOwnProperty(key)) {
9
11
  const value = request.query[key];
@@ -40,13 +40,14 @@ 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(MiddlewareJwt_1.default.config);
43
+ // this.app.use(MiddlewareJwt.config)
44
44
  //middlewares de checagem de token opcional
45
- this.config.middlewaresCloseControllers?.forEach((middl) => {
46
- this.app.use(middl);
47
- });
48
- for (const closeRouter of this.config.closeControllers) {
49
- this.app.use(closeRouter.router);
45
+ // this.config.middlewaresCloseControllers?.forEach((middl: RequestHandler) => {
46
+ // this.app.use(middl)
47
+ // })
48
+ for (const closeRouter of this.config.closeControllers.map(c => c.router)) {
49
+ closeRouter.use(MiddlewareJwt_1.default.config, ...(this.config.middlewaresCloseControllers?.map(m => m) ?? []));
50
+ this.app.use(closeRouter);
50
51
  }
51
52
  (0, c2_util_1.log)("LOG", "Rotas fechadas OK");
52
53
  this.server = this.app.listen(this.config.port, async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.132",
3
+ "version": "1.0.134",
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>",