ismx-nexo-node-app 0.4.182 → 0.4.183
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.
|
@@ -51,15 +51,23 @@ class RepositoryRest extends Repository_1.default {
|
|
|
51
51
|
// Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
|
|
52
52
|
// @ts-ignore
|
|
53
53
|
return call.then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
var _a, _b, _c, _d, _e;
|
|
54
|
+
var _a, _b, _c, _d, _e, _f;
|
|
55
|
+
// Captura la información de las cabeceras independientemente de si vienen en stream de datos o en bloque
|
|
55
56
|
let headers = {};
|
|
56
|
-
|
|
57
|
+
if (res.headers instanceof Headers)
|
|
58
|
+
res.headers.forEach((value, key) => headers[key.toLowerCase()] = value);
|
|
59
|
+
else
|
|
60
|
+
Object.entries(res.headers).forEach(([key, value]) => headers[key.toLowerCase()] = value);
|
|
61
|
+
// Interpreta el contenido del cuerpo resultado
|
|
57
62
|
let content = yield res.text();
|
|
58
63
|
(_b = (_a = this.options).onRawResponse) === null || _b === void 0 ? void 0 : _b.call(_a, request, content);
|
|
64
|
+
// Si el cuerpo resultado es un JSON, lo transforma a objeto
|
|
59
65
|
if ((_c = headers['content-type']) === null || _c === void 0 ? void 0 : _c.startsWith('application/json'))
|
|
60
66
|
content = JSON.parse(content, this.reviver);
|
|
67
|
+
if ((_d = headers['content-type']) === null || _d === void 0 ? void 0 : _d.startsWith('application/xml'))
|
|
68
|
+
content = content; //new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' }).parse(content);
|
|
61
69
|
let response = { httpCode: res.status, content: content, headers };
|
|
62
|
-
(
|
|
70
|
+
(_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.onResponse) === null || _f === void 0 ? void 0 : _f.call(_e, request, response);
|
|
63
71
|
return response;
|
|
64
72
|
})).catch((error) => {
|
|
65
73
|
var _a, _b;
|
package/package.json
CHANGED
|
@@ -66,14 +66,24 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
66
66
|
// Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
|
|
67
67
|
// @ts-ignore
|
|
68
68
|
return call.then(async (res: Response) => {
|
|
69
|
+
|
|
70
|
+
// Captura la información de las cabeceras independientemente de si vienen en stream de datos o en bloque
|
|
69
71
|
let headers: any = {};
|
|
70
|
-
|
|
72
|
+
if (res.headers instanceof Headers)
|
|
73
|
+
res.headers.forEach((value, key) => headers[key.toLowerCase()] = value);
|
|
74
|
+
else Object.entries(res.headers).forEach(([key, value]) => headers[key.toLowerCase()] = value);
|
|
75
|
+
|
|
76
|
+
// Interpreta el contenido del cuerpo resultado
|
|
71
77
|
let content: string | E = await res.text();
|
|
72
78
|
this.options.onRawResponse?.(request, content);
|
|
73
79
|
|
|
80
|
+
// Si el cuerpo resultado es un JSON, lo transforma a objeto
|
|
74
81
|
if (headers['content-type']?.startsWith('application/json'))
|
|
75
82
|
content = JSON.parse(content, this.reviver) as E;
|
|
76
83
|
|
|
84
|
+
if (headers['content-type']?.startsWith('application/xml'))
|
|
85
|
+
content = content; //new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_' }).parse(content);
|
|
86
|
+
|
|
77
87
|
let response: HttpResponse<E> = { httpCode: res.status, content: content as E, headers };
|
|
78
88
|
this.options?.onResponse?.(request, response);
|
|
79
89
|
return response;
|