c2-http 1.0.113 → 1.0.114

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,5 +1,7 @@
1
1
  import { JwtPayload } from "jsonwebtoken";
2
2
  export interface IJWTPayload extends JwtPayload {
3
3
  account: string;
4
+ accountExpireDate: Date;
5
+ accountBlockDate: Date;
4
6
  scopes: string;
5
7
  }
@@ -9,6 +9,8 @@ class AddInContextFlowItem {
9
9
  express_http_context_1.default.set("token", token);
10
10
  express_http_context_1.default.set("userId", decode.sub);
11
11
  express_http_context_1.default.set("accountId", decode.account);
12
+ express_http_context_1.default.set("accountBlockDate", decode.accountBlockDate);
13
+ express_http_context_1.default.set("accountExpireDate", decode.accountExpireDate);
12
14
  express_http_context_1.default.set("scopes", decode.scopes);
13
15
  }
14
16
  }
@@ -21,5 +21,6 @@ export declare abstract class Controller {
21
21
  registerRoute(options: ISingleRouteParam): void;
22
22
  }
23
23
  export declare function HttpDispatchHandling(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
24
+ export declare function HttpDispatchHandlingAdmin(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
24
25
  export declare function HttpDispatchDownload(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor;
25
26
  export declare function OpenApi(target: any): typeof target;
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenApi = exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.Controller = void 0;
6
+ exports.OpenApi = exports.HttpDispatchDownload = exports.HttpDispatchHandlingAdmin = exports.HttpDispatchHandling = exports.Controller = void 0;
4
7
  const express_1 = require("express");
8
+ const express_http_context_1 = __importDefault(require("express-http-context"));
5
9
  const http_status_1 = require("http-status");
10
+ const moment_1 = __importDefault(require("moment"));
6
11
  class Controller {
7
12
  router;
8
13
  normalizedPaths;
@@ -54,11 +59,11 @@ function HttpDispatchHandling(target, methodName, descriptor) {
54
59
  descriptor.value = async function (...args) {
55
60
  const response = args[1];
56
61
  try {
62
+ const blockedDate = express_http_context_1.default.get("accountBlockDate");
63
+ if (blockedDate && (0, moment_1.default)().isAfter((0, moment_1.default)(blockedDate))) {
64
+ return response.status(http_status_1.PAYMENT_REQUIRED);
65
+ }
57
66
  const returnHttp = await originalMethod.apply(this, args);
58
- // const signatureValidation = await ValidateSignatureFlow.validate();
59
- // if (signatureValidation.expired) {
60
- // returnHttp[0] = PAYMENT_REQUIRED;
61
- // }
62
67
  return response.status(returnHttp[0]).json(returnHttp[1]);
63
68
  }
64
69
  catch (error) {
@@ -71,12 +76,34 @@ function HttpDispatchHandling(target, methodName, descriptor) {
71
76
  return descriptor;
72
77
  }
73
78
  exports.HttpDispatchHandling = HttpDispatchHandling;
79
+ function HttpDispatchHandlingAdmin(target, methodName, descriptor) {
80
+ const originalMethod = descriptor.value;
81
+ descriptor.value = async function (...args) {
82
+ const response = args[1];
83
+ try {
84
+ const returnHttp = await originalMethod.apply(this, args);
85
+ return response.status(returnHttp[0]).json(returnHttp[1]);
86
+ }
87
+ catch (error) {
88
+ console.error(error);
89
+ response
90
+ .status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
91
+ .json({ message: error.message, detail: error.detail?.data });
92
+ }
93
+ };
94
+ return descriptor;
95
+ }
96
+ exports.HttpDispatchHandlingAdmin = HttpDispatchHandlingAdmin;
74
97
  function HttpDispatchDownload(target, methodName, descriptor) {
75
98
  const originalMethod = descriptor.value;
76
99
  descriptor.value = async function (...args) {
77
100
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
78
101
  const [request, response] = args;
79
102
  try {
103
+ const blockedDate = express_http_context_1.default.get("accountBlockDate");
104
+ if (blockedDate && (0, moment_1.default)().isAfter((0, moment_1.default)(blockedDate))) {
105
+ return response.status(http_status_1.PAYMENT_REQUIRED);
106
+ }
80
107
  const [status, data] = await originalMethod.apply(this, args);
81
108
  return response.status(status).send(data);
82
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-http",
3
- "version": "1.0.113",
3
+ "version": "1.0.114",
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>",