c2-http 1.0.112 → 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.
|
@@ -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;
|
package/dist/model/Controller.js
CHANGED
|
@@ -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/dist/model/Server.js
CHANGED
|
@@ -23,24 +23,25 @@ class Server {
|
|
|
23
23
|
(0, i18n_1.initializei18n)(this.config.i18n);
|
|
24
24
|
MiddlewareGlobals_1.default.config(this.app);
|
|
25
25
|
let pathsToMetrics = [];
|
|
26
|
+
for (const controllers of [...this.config.openControllers, ...this.config.closeControllers]) {
|
|
27
|
+
pathsToMetrics = [...pathsToMetrics, ...controllers.normalizedPaths];
|
|
28
|
+
}
|
|
29
|
+
const metricsMiddleware = (0, express_prom_bundle_1.default)({
|
|
30
|
+
includeMethod: true,
|
|
31
|
+
includePath: true,
|
|
32
|
+
normalizePath: pathsToMetrics,
|
|
33
|
+
metricsPath: "/metrics"
|
|
34
|
+
});
|
|
35
|
+
this.app.use(metricsMiddleware);
|
|
26
36
|
for (const openController of this.config.openControllers) {
|
|
27
37
|
this.app.use(openController.router);
|
|
28
|
-
pathsToMetrics = [...pathsToMetrics, ...openController.normalizedPaths];
|
|
29
38
|
}
|
|
30
39
|
// this.app.use("/docs", swaggerUI.serve, swaggerUI.setup((global as any).OPEN_API_DOC))
|
|
31
40
|
(0, c2_util_1.log)("LOG", "Rotas abertas OK");
|
|
32
41
|
this.app.use(MiddlewareJwt_1.default.config);
|
|
33
42
|
for (const closeRouter of this.config.closeControllers) {
|
|
34
43
|
this.app.use(closeRouter.router);
|
|
35
|
-
pathsToMetrics = [...pathsToMetrics, ...closeRouter.normalizedPaths];
|
|
36
44
|
}
|
|
37
|
-
const metricsMiddleware = (0, express_prom_bundle_1.default)({
|
|
38
|
-
includeMethod: true,
|
|
39
|
-
includePath: true,
|
|
40
|
-
normalizePath: pathsToMetrics,
|
|
41
|
-
metricsPath: "/metrics"
|
|
42
|
-
});
|
|
43
|
-
this.app.use(metricsMiddleware);
|
|
44
45
|
(0, c2_util_1.log)("LOG", "Rotas fechadas OK");
|
|
45
46
|
this.server = this.app.listen(this.config.port, async () => {
|
|
46
47
|
(0, c2_util_1.log)("LOG_INIT_SERVER", `Server running on port ${this.config.port}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-http",
|
|
3
|
-
"version": "1.0.
|
|
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>",
|