c2-http 1.0.1 → 1.0.2
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.
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpDispatchDownload = exports.HttpDispatchHandling = void 0;
|
|
4
|
+
const http_status_1 = require("http-status");
|
|
5
|
+
function HttpDispatchHandling(target, methodName, descriptor) {
|
|
6
|
+
const originalMethod = descriptor.value;
|
|
7
|
+
descriptor.value = async function (...args) {
|
|
8
|
+
const response = args[1];
|
|
9
|
+
try {
|
|
10
|
+
const returnHttp = await originalMethod.apply(this, args);
|
|
11
|
+
// const signatureValidation = await ValidateSignatureFlow.validate();
|
|
12
|
+
// if (signatureValidation.expired) {
|
|
13
|
+
// returnHttp[0] = PAYMENT_REQUIRED;
|
|
14
|
+
// }
|
|
15
|
+
return response.status(returnHttp[0]).json(returnHttp[1]);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error(error);
|
|
19
|
+
response
|
|
20
|
+
.status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
|
|
21
|
+
.json({ message: error.message, detail: error.detail?.data });
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return descriptor;
|
|
25
|
+
}
|
|
26
|
+
exports.HttpDispatchHandling = HttpDispatchHandling;
|
|
27
|
+
function HttpDispatchDownload(target, methodName, descriptor) {
|
|
28
|
+
const originalMethod = descriptor.value;
|
|
29
|
+
descriptor.value = async function (...args) {
|
|
30
|
+
const [response] = args;
|
|
31
|
+
try {
|
|
32
|
+
const [status, data] = await originalMethod.apply(this, args);
|
|
33
|
+
return response.status(status).send(data);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error(error);
|
|
37
|
+
response
|
|
38
|
+
.status(error.status || http_status_1.INTERNAL_SERVER_ERROR)
|
|
39
|
+
.json({ message: error.message, detail: error.detail?.data });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return descriptor;
|
|
43
|
+
}
|
|
44
|
+
exports.HttpDispatchDownload = HttpDispatchDownload;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Controller = void 0;
|
|
4
|
+
const c2_util_1 = require("c2-util");
|
|
5
|
+
const express_1 = require("express");
|
|
6
|
+
class Controller {
|
|
7
|
+
routers = (0, express_1.Router)();
|
|
8
|
+
options;
|
|
9
|
+
constructor(_options) {
|
|
10
|
+
this.options = _options;
|
|
11
|
+
if (!this?.options?.relativePath?.startsWith("/")) {
|
|
12
|
+
throw new Error("the 'relativePatch' must start with a slash '/'");
|
|
13
|
+
}
|
|
14
|
+
if ((0, c2_util_1.isEmpty)(this.options.basePath)) {
|
|
15
|
+
this.options.basePath = "/api/v1";
|
|
16
|
+
}
|
|
17
|
+
if ((0, c2_util_1.isEmpty)(this.options.roles)) {
|
|
18
|
+
this.options.roles = [];
|
|
19
|
+
}
|
|
20
|
+
if ((0, c2_util_1.isEmpty)(this.options.prefixRole)) {
|
|
21
|
+
let defaultPrefixRole = this.options.relativePath;
|
|
22
|
+
if (defaultPrefixRole.startsWith("/")) {
|
|
23
|
+
defaultPrefixRole = defaultPrefixRole.replace("/", "");
|
|
24
|
+
}
|
|
25
|
+
this.options.prefixRole = defaultPrefixRole.replaceAll("/", "-");
|
|
26
|
+
}
|
|
27
|
+
this.options.uri = `${this.options.basePath}${this.options.relativePath}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Controller = Controller;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c2-http",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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>",
|