ismx-nexo-node-app 0.4.172 → 0.4.175
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/js/business/BusinessLogger.js +2 -4
- package/dist/js/business/BusinessServer.js +14 -11
- package/dist/js/repository/RepositoryRest.js +2 -1
- package/dist/types/business/BusinessServer.d.ts +2 -0
- package/package.json +1 -1
- package/src/main/node/business/BusinessLogger.ts +2 -6
- package/src/main/node/business/BusinessServer.ts +17 -11
- package/src/main/node/repository/RepositoryRest.ts +2 -2
|
@@ -27,10 +27,8 @@ class BusinessLogger {
|
|
|
27
27
|
constructor() {
|
|
28
28
|
this.logStream = null;
|
|
29
29
|
this.currentLogFile = null;
|
|
30
|
-
Promise.resolve().then(() => __importStar(require("fs"))).then((e) => this.fs = e.default)
|
|
31
|
-
|
|
32
|
-
Promise.resolve().then(() => __importStar(require("path"))).then((e) => this.path = e.default)
|
|
33
|
-
.catch(() => null);
|
|
30
|
+
Promise.resolve().then(() => __importStar(require("fs"))).then((e) => this.fs = e.default);
|
|
31
|
+
Promise.resolve().then(() => __importStar(require("path"))).then((e) => this.path = e.default);
|
|
34
32
|
}
|
|
35
33
|
file() {
|
|
36
34
|
return null;
|
|
@@ -37,30 +37,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const Service_1 = require("../api/Service");
|
|
39
39
|
const Business_1 = __importDefault(require("./Business"));
|
|
40
|
-
const node_stream_1 = require("node:stream");
|
|
41
40
|
class BusinessServer extends Business_1.default {
|
|
42
41
|
constructor() {
|
|
43
42
|
super();
|
|
44
43
|
this.services = [];
|
|
45
44
|
this.publish = this.publish.bind(this);
|
|
45
|
+
Promise.resolve().then(() => __importStar(require("express"))).then((e) => this.express = e.default);
|
|
46
|
+
Promise.resolve().then(() => __importStar(require("cors"))).then((e) => this.cors = e.default);
|
|
47
|
+
Promise.resolve().then(() => __importStar(require("node:stream"))).then((e) => this.readable = e.default.Readable);
|
|
46
48
|
}
|
|
47
49
|
init() {
|
|
48
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
this.app = this.express();
|
|
52
|
+
this.app.use(this.express.urlencoded({ extended: false }));
|
|
53
|
+
this.app.use(this.cors({
|
|
54
|
+
origin: true,
|
|
55
|
+
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
56
|
+
allowedHeaders: ["Authorization", "Content-Type"],
|
|
57
|
+
exposedHeaders: ["Authorization"],
|
|
58
|
+
credentials: false
|
|
59
|
+
}));
|
|
60
|
+
this.app.options("*", this.cors({
|
|
57
61
|
origin: true,
|
|
58
62
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
59
63
|
allowedHeaders: ["Authorization", "Content-Type"],
|
|
60
64
|
exposedHeaders: ["Authorization"],
|
|
61
65
|
credentials: false
|
|
62
66
|
}));
|
|
63
|
-
this.app.options("*", cors());
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
start(port) {
|
|
@@ -156,7 +159,7 @@ class BusinessServer extends Business_1.default {
|
|
|
156
159
|
socket.set(header, value);
|
|
157
160
|
});
|
|
158
161
|
if (response.pipe)
|
|
159
|
-
|
|
162
|
+
this.readable.fromWeb(response.pipe).pipe(socket);
|
|
160
163
|
else
|
|
161
164
|
socket.send(response === null || response === void 0 ? void 0 : response.content);
|
|
162
165
|
try {
|
|
@@ -28,6 +28,7 @@ class RepositoryRest extends Repository_1.default {
|
|
|
28
28
|
// Especifica el método de la llamada HTTP al recurso.
|
|
29
29
|
request.method = method;
|
|
30
30
|
request.endpoint = endpoint;
|
|
31
|
+
request.url = `${this.baseUrl}${endpoint}`;
|
|
31
32
|
// Notifica que una petición REST va a ser realizada
|
|
32
33
|
request = (_c = (_b = (_a = this.options).interceptor) === null || _b === void 0 ? void 0 : _b.call(_a, endpoint, request)) !== null && _c !== void 0 ? _c : request;
|
|
33
34
|
// Completa la información de las cabeceras con cabeceras comunes por llamada a API.
|
|
@@ -44,7 +45,7 @@ class RepositoryRest extends Repository_1.default {
|
|
|
44
45
|
for (const [header, value] of Object.entries((_e = request.headers) !== null && _e !== void 0 ? _e : {}))
|
|
45
46
|
headers.set(header, (_g = (_f = request.headers) === null || _f === void 0 ? void 0 : _f[header]) !== null && _g !== void 0 ? _g : "");
|
|
46
47
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
47
|
-
let call = fetch(
|
|
48
|
+
let call = fetch(request.url + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { body: method !== "GET" ? body : undefined, headers }));
|
|
48
49
|
// Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
|
|
49
50
|
return call.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
50
51
|
var _a, _b, _c, _d, _e;
|
package/package.json
CHANGED
|
@@ -8,12 +8,8 @@ export default class BusinessLogger
|
|
|
8
8
|
private path: any;
|
|
9
9
|
|
|
10
10
|
constructor() {
|
|
11
|
-
import("fs")
|
|
12
|
-
|
|
13
|
-
.catch(() => null);
|
|
14
|
-
import("path")
|
|
15
|
-
.then((e) => this.path = e.default)
|
|
16
|
-
.catch(() => null);
|
|
11
|
+
import("fs").then((e) => this.fs = e.default)
|
|
12
|
+
import("path").then((e) => this.path = e.default)
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
protected file(): string | null {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Service, {HttpRequest, HttpResponse} from "../api/Service";
|
|
2
2
|
import Business from "./Business";
|
|
3
|
-
import {Readable} from "node:stream";
|
|
4
3
|
|
|
5
4
|
export default class BusinessServer extends Business
|
|
6
5
|
{
|
|
@@ -9,23 +8,24 @@ export default class BusinessServer extends Business
|
|
|
9
8
|
private express: any;
|
|
10
9
|
|
|
11
10
|
private app: any;
|
|
11
|
+
private cors: any;
|
|
12
|
+
private readable: any;
|
|
12
13
|
|
|
13
14
|
constructor() {
|
|
14
15
|
super()
|
|
15
16
|
this.publish = this.publish.bind(this);
|
|
17
|
+
|
|
18
|
+
import("express").then((e) => this.express = e.default);
|
|
19
|
+
import("cors").then((e) => this.cors = e.default)
|
|
20
|
+
import("node:stream").then((e) => this.readable = e.default.Readable)
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
async init()
|
|
19
24
|
{
|
|
20
|
-
|
|
21
|
-
const cors = await import("cors").then((e) => e.default).catch(() => null);
|
|
22
|
-
if (!express || !cors) return;
|
|
23
|
-
|
|
24
|
-
this.express = express;
|
|
25
|
-
this.app = express();
|
|
25
|
+
this.app = this.express();
|
|
26
26
|
|
|
27
|
-
this.app.use(express.urlencoded({ extended: false }));
|
|
28
|
-
this.app.use(cors({
|
|
27
|
+
this.app.use(this.express.urlencoded({ extended: false }));
|
|
28
|
+
this.app.use(this.cors({
|
|
29
29
|
origin: true,
|
|
30
30
|
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
31
31
|
allowedHeaders: ["Authorization", "Content-Type"],
|
|
@@ -33,7 +33,13 @@ export default class BusinessServer extends Business
|
|
|
33
33
|
credentials: false
|
|
34
34
|
}));
|
|
35
35
|
|
|
36
|
-
this.app.options("*", cors(
|
|
36
|
+
this.app.options("*", this.cors({
|
|
37
|
+
origin: true,
|
|
38
|
+
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
39
|
+
allowedHeaders: ["Authorization", "Content-Type"],
|
|
40
|
+
exposedHeaders: ["Authorization"],
|
|
41
|
+
credentials: false
|
|
42
|
+
}));
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
start(port: number) {
|
|
@@ -120,7 +126,7 @@ export default class BusinessServer extends Business
|
|
|
120
126
|
Object.entries(response.headers ?? {}).forEach(([header, value]) => {
|
|
121
127
|
socket.set(header, value);
|
|
122
128
|
});
|
|
123
|
-
if (response.pipe)
|
|
129
|
+
if (response.pipe) this.readable.fromWeb(response.pipe).pipe(socket);
|
|
124
130
|
else socket.send(response?.content);
|
|
125
131
|
|
|
126
132
|
try { this.onEnd?.(request, response); } catch(e) { }
|
|
@@ -14,7 +14,6 @@ export interface RestOptions {
|
|
|
14
14
|
export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
15
15
|
{
|
|
16
16
|
private readonly baseUrl: string;
|
|
17
|
-
|
|
18
17
|
private readonly options: RestOptions
|
|
19
18
|
|
|
20
19
|
constructor(baseUrl: string, options: RestOptions={}) {
|
|
@@ -34,6 +33,7 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
34
33
|
// Especifica el método de la llamada HTTP al recurso.
|
|
35
34
|
request.method = method;
|
|
36
35
|
request.endpoint = endpoint;
|
|
36
|
+
request.url = `${this.baseUrl}${endpoint}`;
|
|
37
37
|
|
|
38
38
|
// Notifica que una petición REST va a ser realizada
|
|
39
39
|
request = this.options.interceptor?.(endpoint, request) ?? request
|
|
@@ -55,7 +55,7 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
55
55
|
headers.set(header, request.headers?.[header] ?? "");
|
|
56
56
|
|
|
57
57
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
58
|
-
let call = fetch(
|
|
58
|
+
let call = fetch(request.url + QueryUtils.map(request.query), {
|
|
59
59
|
...request, body: method !== "GET" ? body : undefined, headers
|
|
60
60
|
});
|
|
61
61
|
|