ismx-nexo-node-app 0.4.181 → 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;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { KeyLike, RsaPrivateKey } from "crypto";
|
|
1
2
|
export default abstract class CryptoUtils {
|
|
2
3
|
private static crypto;
|
|
3
4
|
private static zeroPad;
|
|
4
5
|
static symEncrypt(key: string, message: string): Promise<Buffer>;
|
|
5
6
|
static symDecrypt(key: string, encrypted: Buffer): Promise<string>;
|
|
6
7
|
/** Asymmetric encryption (RSA) */
|
|
7
|
-
static asymEncrypt(value: string, publicKey:
|
|
8
|
+
static asymEncrypt(value: string, publicKey: RsaPrivateKey | KeyLike): Promise<string>;
|
|
8
9
|
/** Asymmetric decryption (RSA) */
|
|
9
|
-
static asymDecrypt(hash: string, privateKey:
|
|
10
|
+
static asymDecrypt(hash: string, privateKey: RsaPrivateKey | KeyLike): Promise<string>;
|
|
10
11
|
private static sha256Sign;
|
|
11
12
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {privateDecrypt, publicEncrypt} from "node:crypto";
|
|
2
|
+
import {KeyLike, RsaPrivateKey} from "crypto";
|
|
2
3
|
|
|
3
4
|
export default abstract class CryptoUtils {
|
|
4
5
|
|
|
@@ -48,14 +49,14 @@ export default abstract class CryptoUtils {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/** Asymmetric encryption (RSA) */
|
|
51
|
-
static async asymEncrypt(value: string, publicKey:
|
|
52
|
+
static async asymEncrypt(value: string, publicKey: RsaPrivateKey | KeyLike): Promise<string> {
|
|
52
53
|
const buffer = Buffer.from(value, 'utf8');
|
|
53
54
|
const encrypted = publicEncrypt(publicKey, buffer);
|
|
54
55
|
return encrypted.toString('base64');
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
/** Asymmetric decryption (RSA) */
|
|
58
|
-
static async asymDecrypt(hash: string, privateKey:
|
|
59
|
+
static async asymDecrypt(hash: string, privateKey: RsaPrivateKey | KeyLike): Promise<string> {
|
|
59
60
|
const buffer = Buffer.from(hash, 'base64');
|
|
60
61
|
const decrypted = privateDecrypt(privateKey, buffer);
|
|
61
62
|
return decrypted.toString('utf8');
|
|
@@ -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;
|