apacuana-sdk-core 0.1.0 → 0.3.0
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/README.md +175 -55
- package/coverage/clover.xml +249 -101
- package/coverage/coverage-final.json +9 -6
- package/coverage/lcov-report/index.html +45 -30
- package/coverage/lcov-report/src/api/certs.js.html +117 -81
- package/coverage/lcov-report/src/api/index.html +40 -25
- package/coverage/lcov-report/src/api/revocations.js.html +1 -1
- package/coverage/lcov-report/src/api/signatures.js.html +546 -72
- package/coverage/lcov-report/src/api/users.js.html +25 -61
- package/coverage/lcov-report/src/config/index.html +21 -21
- package/coverage/lcov-report/src/config/index.js.html +65 -32
- package/coverage/lcov-report/src/errors/index.html +5 -5
- package/coverage/lcov-report/src/errors/index.js.html +13 -10
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.js.html +13 -4
- package/coverage/lcov-report/src/utils/constant.js.html +4 -4
- package/coverage/lcov-report/src/utils/helpers.js.html +290 -116
- package/coverage/lcov-report/src/utils/httpClient.js.html +646 -0
- package/coverage/lcov-report/src/utils/index.html +30 -15
- package/coverage/lcov.info +515 -181
- package/dist/index.js +323 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +323 -189
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/certs.js +49 -37
- package/src/api/signatures.js +213 -49
- package/src/api/users.js +17 -29
- package/src/errors/index.js +1 -0
- package/src/index.js +4 -1
- package/src/utils/helpers.js +156 -98
- package/tests/api/certs.test.js +111 -5
- package/tests/api/signatures.test.js +152 -4
- package/tests/api/users.test.js +11 -10
- package/src/auth/index.js +0 -24
package/dist/index.mjs
CHANGED
|
@@ -240,6 +240,15 @@ function _toPropertyKey(t) {
|
|
|
240
240
|
var i = _toPrimitive(t, "string");
|
|
241
241
|
return "symbol" == typeof i ? i : i + "";
|
|
242
242
|
}
|
|
243
|
+
function _typeof(o) {
|
|
244
|
+
"@babel/helpers - typeof";
|
|
245
|
+
|
|
246
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
247
|
+
return typeof o;
|
|
248
|
+
} : function (o) {
|
|
249
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
250
|
+
}, _typeof(o);
|
|
251
|
+
}
|
|
243
252
|
function _wrapNativeSuper(t) {
|
|
244
253
|
var r = "function" == typeof Map ? new Map() : void 0;
|
|
245
254
|
return _wrapNativeSuper = function (t) {
|
|
@@ -327,6 +336,7 @@ var ApacuanaAPIError = /*#__PURE__*/function (_Error) {
|
|
|
327
336
|
_this.name = "ApacuanaAPIError";
|
|
328
337
|
_this.statusCode = statusCode;
|
|
329
338
|
_this.errorCode = errorCode;
|
|
339
|
+
_this.success = false; // Añadir el atributo success con valor false
|
|
330
340
|
|
|
331
341
|
// Mantener el stack trace correcto
|
|
332
342
|
if (Error.captureStackTrace) {
|
|
@@ -510,7 +520,7 @@ var httpRequest = /*#__PURE__*/function () {
|
|
|
510
520
|
* Este método es útil para endpoints que requieren datos en el cuerpo de la petición
|
|
511
521
|
* para buscar un usuario, como un ID de sesión o un token de acceso.
|
|
512
522
|
*
|
|
513
|
-
* @returns {Promise<object>} Objeto con los
|
|
523
|
+
* @returns {Promise<{token: string, userData: object, success: boolean}>} Objeto con el token de sesión, los datos del usuario y un indicador de éxito.
|
|
514
524
|
* @throws {Error} Si los parámetros de entrada son inválidos.
|
|
515
525
|
* @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
|
|
516
526
|
*/
|
|
@@ -521,61 +531,46 @@ var getCustomer = /*#__PURE__*/function () {
|
|
|
521
531
|
while (1) switch (_context.p = _context.n) {
|
|
522
532
|
case 0:
|
|
523
533
|
_getConfig = getConfig(), verificationId = _getConfig.verificationId, customerId = _getConfig.customerId;
|
|
524
|
-
|
|
525
|
-
verificationid: verificationId,
|
|
526
|
-
customerid: customerId
|
|
527
|
-
}; // eslint-disable-next-line no-console
|
|
528
|
-
console.log("-> Función 'getCustomer' ejecutada.");
|
|
529
|
-
// eslint-disable-next-line no-console
|
|
530
|
-
console.log("Parámetros recibidos para buscar usuario:", body);
|
|
531
|
-
|
|
532
|
-
// 1. Validación de Parámetros de Entrada (Lado del SDK)
|
|
533
|
-
if (!(!body || !body.verificationid || !body.customerid)) {
|
|
534
|
+
if (!(!verificationId || !customerId)) {
|
|
534
535
|
_context.n = 1;
|
|
535
536
|
break;
|
|
536
537
|
}
|
|
537
|
-
throw new
|
|
538
|
+
throw new ApacuanaAPIError("Both 'verificationId' and 'customerId' must be configured.", 400, "CONFIGURATION_ERROR");
|
|
538
539
|
case 1:
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
"POST");
|
|
546
|
-
case
|
|
540
|
+
body = {
|
|
541
|
+
verificationid: verificationId,
|
|
542
|
+
customerid: customerId
|
|
543
|
+
};
|
|
544
|
+
_context.p = 2;
|
|
545
|
+
_context.n = 3;
|
|
546
|
+
return httpRequest("services/api/register/init", body, "POST");
|
|
547
|
+
case 3:
|
|
547
548
|
response = _context.v;
|
|
548
|
-
// 3. Procesar la Respuesta del Backend
|
|
549
|
-
// Asumiendo que la respuesta exitosa del backend incluye un objeto 'user'
|
|
550
|
-
// eslint-disable-next-line no-console
|
|
551
|
-
console.log("Respuesta del servidor para el token:", response);
|
|
552
549
|
if (!(!response.sessionid || !response.entry)) {
|
|
553
|
-
_context.n =
|
|
550
|
+
_context.n = 4;
|
|
554
551
|
break;
|
|
555
552
|
}
|
|
556
|
-
throw new ApacuanaAPIError("
|
|
557
|
-
case
|
|
553
|
+
throw new ApacuanaAPIError("The API response does not contain the user.", 200, "INVALID_API_RESPONSE");
|
|
554
|
+
case 4:
|
|
558
555
|
return _context.a(2, {
|
|
559
556
|
token: response.sessionid,
|
|
560
|
-
userData: response.entry
|
|
557
|
+
userData: response.entry,
|
|
558
|
+
success: true
|
|
561
559
|
});
|
|
562
|
-
case
|
|
563
|
-
_context.p =
|
|
560
|
+
case 5:
|
|
561
|
+
_context.p = 5;
|
|
564
562
|
_t = _context.v;
|
|
565
|
-
// 4. Manejo de Errores
|
|
566
|
-
// eslint-disable-next-line no-console
|
|
567
|
-
console.error("Error en getCustomer:", _t);
|
|
568
563
|
if (!(_t instanceof ApacuanaAPIError)) {
|
|
569
|
-
_context.n =
|
|
564
|
+
_context.n = 6;
|
|
570
565
|
break;
|
|
571
566
|
}
|
|
572
567
|
throw _t;
|
|
573
|
-
case 5:
|
|
574
|
-
throw new ApacuanaAPIError("Fallo inesperado al obtener el token: ".concat(_t.message || "Error desconocido"));
|
|
575
568
|
case 6:
|
|
569
|
+
throw new ApacuanaAPIError("Unexpected failure getting token: ".concat(_t.message || "Unknown error"));
|
|
570
|
+
case 7:
|
|
576
571
|
return _context.a(2);
|
|
577
572
|
}
|
|
578
|
-
}, _callee, null, [[
|
|
573
|
+
}, _callee, null, [[2, 5]]);
|
|
579
574
|
}));
|
|
580
575
|
return function getCustomer() {
|
|
581
576
|
return _ref.apply(this, arguments);
|
|
@@ -637,6 +632,10 @@ var requestRevocation = /*#__PURE__*/function () {
|
|
|
637
632
|
|
|
638
633
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
639
634
|
|
|
635
|
+
function getDefaultExportFromCjs (x) {
|
|
636
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
637
|
+
}
|
|
638
|
+
|
|
640
639
|
var cryptoJs = {exports: {}};
|
|
641
640
|
|
|
642
641
|
function commonjsRequire(path) {
|
|
@@ -8061,6 +8060,9 @@ function requireBlowfish () {
|
|
|
8061
8060
|
}));
|
|
8062
8061
|
} (cryptoJs));
|
|
8063
8062
|
|
|
8063
|
+
var cryptoJsExports = cryptoJs.exports;
|
|
8064
|
+
var CryptoJS = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
|
|
8065
|
+
|
|
8064
8066
|
/*!
|
|
8065
8067
|
* MIT License
|
|
8066
8068
|
*
|
|
@@ -32647,6 +32649,7 @@ function initCryptoEngine() {
|
|
|
32647
32649
|
|
|
32648
32650
|
initCryptoEngine();
|
|
32649
32651
|
|
|
32652
|
+
var KEY_HEX = "dRgUkXp2s5v8y/B?";
|
|
32650
32653
|
var getCertificateStatus = function getCertificateStatus(userData, certificateInDevice) {
|
|
32651
32654
|
var _userData$verificatio, _userData$requestscer, _userData$requestscer2;
|
|
32652
32655
|
if (!userData) {
|
|
@@ -32664,189 +32667,317 @@ var getCertificateStatus = function getCertificateStatus(userData, certificateIn
|
|
|
32664
32667
|
if (userData !== null && userData !== void 0 && userData.certificationId) return STATUS_CERTIFICATE.current;
|
|
32665
32668
|
return STATUS_CERTIFICATE.revoque;
|
|
32666
32669
|
};
|
|
32667
|
-
|
|
32668
|
-
|
|
32669
|
-
|
|
32670
|
-
|
|
32671
|
-
|
|
32672
|
-
|
|
32673
|
-
|
|
32674
|
-
|
|
32670
|
+
|
|
32671
|
+
// Función para convertir ArrayBuffer a Base64
|
|
32672
|
+
var arrayBufferToBase64 = function arrayBufferToBase64(buffer) {
|
|
32673
|
+
var binary = String.fromCharCode.apply(null, new Uint8Array(buffer));
|
|
32674
|
+
return window.btoa(binary);
|
|
32675
|
+
};
|
|
32676
|
+
function exportPrivateKey(_x) {
|
|
32677
|
+
return _exportPrivateKey.apply(this, arguments);
|
|
32678
|
+
}
|
|
32679
|
+
function _exportPrivateKey() {
|
|
32680
|
+
_exportPrivateKey = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(key) {
|
|
32681
|
+
var crypto, exported, exportablePrivateKey;
|
|
32675
32682
|
return _regenerator().w(function (_context) {
|
|
32676
|
-
while (1) switch (_context.
|
|
32683
|
+
while (1) switch (_context.n) {
|
|
32677
32684
|
case 0:
|
|
32678
|
-
signAlg = _args.length > 0 && _args[0] !== undefined ? _args[0] : "RSASSA-PKCS1-v1_5";
|
|
32679
|
-
hashAlg = _args.length > 1 && _args[1] !== undefined ? _args[1] : "SHA-256";
|
|
32680
|
-
_context.p = 1;
|
|
32681
32685
|
crypto = getCrypto();
|
|
32682
|
-
|
|
32683
|
-
|
|
32684
|
-
|
|
32685
|
-
|
|
32686
|
-
|
|
32686
|
+
_context.n = 1;
|
|
32687
|
+
return crypto.exportKey("pkcs8", key);
|
|
32688
|
+
case 1:
|
|
32689
|
+
exported = _context.v;
|
|
32690
|
+
exportablePrivateKey = new Uint8Array(exported);
|
|
32691
|
+
return _context.a(2, arrayBufferToBase64(exportablePrivateKey));
|
|
32692
|
+
}
|
|
32693
|
+
}, _callee);
|
|
32694
|
+
}));
|
|
32695
|
+
return _exportPrivateKey.apply(this, arguments);
|
|
32696
|
+
}
|
|
32697
|
+
var encryptedCsr = function encryptedCsr(csr) {
|
|
32698
|
+
var encryptKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : KEY_HEX;
|
|
32699
|
+
var body = {
|
|
32700
|
+
csr: CryptoJS.AES.encrypt(csr, encryptKey, {
|
|
32701
|
+
mode: CryptoJS.mode.ECB,
|
|
32702
|
+
padding: CryptoJS.pad.Pkcs7
|
|
32703
|
+
}).toString()
|
|
32704
|
+
};
|
|
32705
|
+
return body;
|
|
32706
|
+
};
|
|
32707
|
+
var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerData) {
|
|
32708
|
+
if (!signerData.name || typeof signerData.name !== "string") {
|
|
32709
|
+
throw new ApacuanaAPIError('El campo "name" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
|
|
32710
|
+
}
|
|
32711
|
+
if (!signerData.reference || typeof signerData.reference !== "string") {
|
|
32712
|
+
throw new ApacuanaAPIError('El campo "reference" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
|
|
32713
|
+
}
|
|
32714
|
+
var validDocTypes = ["V", "P", "E"];
|
|
32715
|
+
if (!signerData.typedoc || !validDocTypes.includes(signerData.typedoc)) {
|
|
32716
|
+
throw new ApacuanaAPIError('El campo "typedoc" es requerido y debe ser uno de los siguientes valores: V, P, E.', 400, "INVALID_PARAMETER_FORMAT");
|
|
32717
|
+
}
|
|
32718
|
+
if (!signerData.doc || typeof signerData.doc !== "string") {
|
|
32719
|
+
throw new ApacuanaAPIError('El campo "doc" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
|
|
32720
|
+
}
|
|
32721
|
+
if (!Array.isArray(signerData.signature) || signerData.signature.length === 0) {
|
|
32722
|
+
throw new ApacuanaAPIError('El campo "signature" es requerido y debe ser un array no vacío.', 400, "INVALID_PARAMETER_FORMAT");
|
|
32723
|
+
}
|
|
32724
|
+
signerData.signature.forEach(function (sig, index) {
|
|
32725
|
+
if (!Number.isInteger(sig.page) || sig.page < 1) {
|
|
32726
|
+
throw new ApacuanaAPIError("La p\xE1gina de la firma ".concat(index + 1, " debe ser un n\xFAmero entero positivo."), 400, "INVALID_PARAMETER_FORMAT");
|
|
32727
|
+
}
|
|
32728
|
+
if (typeof sig.x !== "number" || sig.x < 0 || sig.x > 1) {
|
|
32729
|
+
throw new ApacuanaAPIError("La coordenada X de la firma ".concat(index + 1, " debe ser un n\xFAmero entre 0 y 1."), 400, "INVALID_PARAMETER_FORMAT");
|
|
32730
|
+
}
|
|
32731
|
+
if (typeof sig.y !== "number" || sig.y < 0 || sig.y > 1) {
|
|
32732
|
+
throw new ApacuanaAPIError("La coordenada Y de la firma ".concat(index + 1, " debe ser un n\xFAmero entre 0 y 1."), 400, "INVALID_PARAMETER_FORMAT");
|
|
32733
|
+
}
|
|
32734
|
+
});
|
|
32735
|
+
};
|
|
32736
|
+
var validateCsr = function validateCsr(csr) {
|
|
32737
|
+
var base64Regex = /^[A-Za-z0-9+/=]+$/;
|
|
32738
|
+
if (!csr) {
|
|
32739
|
+
throw new ApacuanaAPIError("La solicitud de firma de certificado (CSR) es requerida.", 400, "INVALID_PARAMETER");
|
|
32740
|
+
}
|
|
32741
|
+
if (typeof csr !== "string" || csr.trim() === "") {
|
|
32742
|
+
throw new ApacuanaAPIError("El CSR debe ser una cadena de texto válida y no puede estar vacía.", 400, "INVALID_PARAMETER_FORMAT");
|
|
32743
|
+
}
|
|
32744
|
+
if (!base64Regex.test(csr)) {
|
|
32745
|
+
throw new ApacuanaAPIError("El CSR debe estar codificado en formato base64 válido.", 400, "INVALID_PARAMETER_FORMAT");
|
|
32746
|
+
}
|
|
32747
|
+
};
|
|
32748
|
+
var validateGetDocsData = function validateGetDocsData(data) {
|
|
32749
|
+
if (!data || typeof data.page === "undefined" || typeof data.size === "undefined") {
|
|
32750
|
+
throw new ApacuanaAPIError("Los parámetros 'page' y 'size' son requeridos.", 400, "INVALID_PARAMETER");
|
|
32751
|
+
}
|
|
32752
|
+
if (typeof data.status !== "undefined" && ![-1, 0, 1, 2].includes(data.status)) {
|
|
32753
|
+
throw new ApacuanaAPIError("El parámetro 'status' no es válido. Los valores permitidos son: -1, 0, 1, 2.", 400, "INVALID_PARAMETER");
|
|
32754
|
+
}
|
|
32755
|
+
};
|
|
32756
|
+
var validateGetDigestData = function validateGetDigestData(signData) {
|
|
32757
|
+
if (!signData || !signData.cert || typeof signData.cert !== "string" || !signData.signatureId || typeof signData.signatureId !== "string") {
|
|
32758
|
+
throw new ApacuanaAPIError("Los parámetros 'cert' y 'signatureId' son requeridos y deben ser cadenas de texto.", 400, "INVALID_PARAMETER");
|
|
32759
|
+
}
|
|
32760
|
+
};
|
|
32761
|
+
var helpers = {
|
|
32762
|
+
getCertificateStatus: getCertificateStatus,
|
|
32763
|
+
exportPrivateKey: exportPrivateKey,
|
|
32764
|
+
arrayBufferToBase64: arrayBufferToBase64,
|
|
32765
|
+
encryptedCsr: encryptedCsr,
|
|
32766
|
+
validateOnBoardingSignerData: validateOnBoardingSignerData,
|
|
32767
|
+
validateCsr: validateCsr,
|
|
32768
|
+
validateGetDocsData: validateGetDocsData,
|
|
32769
|
+
validateGetDigestData: validateGetDigestData
|
|
32770
|
+
};
|
|
32771
|
+
|
|
32772
|
+
/**
|
|
32773
|
+
* Gets the user's certificate status.
|
|
32774
|
+
* @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
|
|
32775
|
+
* @returns {{status: string, success: boolean}} Object with the certificate status and a success indicator.
|
|
32776
|
+
*/
|
|
32777
|
+
var getCertStatus = function getCertStatus() {
|
|
32778
|
+
var isCertificateInDevice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
32779
|
+
var config = getConfig();
|
|
32780
|
+
var status = helpers.getCertificateStatus(config.userData, isCertificateInDevice);
|
|
32781
|
+
return {
|
|
32782
|
+
status: status,
|
|
32783
|
+
success: true
|
|
32784
|
+
};
|
|
32785
|
+
};
|
|
32786
|
+
|
|
32787
|
+
var addSignerOnBoarding = /*#__PURE__*/function () {
|
|
32788
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(signerData) {
|
|
32789
|
+
var _t2;
|
|
32790
|
+
return _regenerator().w(function (_context7) {
|
|
32791
|
+
while (1) switch (_context7.p = _context7.n) {
|
|
32792
|
+
case 0:
|
|
32793
|
+
helpers.validateOnBoardingSignerData(signerData);
|
|
32794
|
+
_context7.p = 1;
|
|
32795
|
+
_context7.n = 2;
|
|
32796
|
+
return httpRequest("services/api/documents/signing", signerData, "POST");
|
|
32687
32797
|
case 2:
|
|
32688
|
-
|
|
32689
|
-
|
|
32690
|
-
|
|
32691
|
-
|
|
32692
|
-
publicExponent: new Uint8Array([1, 0, 1]),
|
|
32693
|
-
hash: {
|
|
32694
|
-
name: hashAlg
|
|
32695
|
-
}
|
|
32696
|
-
}, true, ["sign", "verify"]);
|
|
32798
|
+
return _context7.a(2, {
|
|
32799
|
+
signer: signerData.typedoc + signerData.doc,
|
|
32800
|
+
success: true
|
|
32801
|
+
});
|
|
32697
32802
|
case 3:
|
|
32698
|
-
|
|
32699
|
-
|
|
32803
|
+
_context7.p = 3;
|
|
32804
|
+
_t2 = _context7.v;
|
|
32805
|
+
if (!(_t2 instanceof ApacuanaAPIError)) {
|
|
32806
|
+
_context7.n = 4;
|
|
32807
|
+
break;
|
|
32808
|
+
}
|
|
32809
|
+
throw _t2;
|
|
32700
32810
|
case 4:
|
|
32701
|
-
|
|
32702
|
-
_t = _context.v;
|
|
32703
|
-
console.error("Error durante la generación del par de claves:", _t);
|
|
32704
|
-
throw new ApacuanaAPIError("Fallo en la generaci\xF3n del par de claves: ".concat(_t.message), 0, "KEY_PAIR_GENERATION_ERROR");
|
|
32811
|
+
throw new Error("Failed to add signer in On-Boarding: ".concat(_t2.message));
|
|
32705
32812
|
case 5:
|
|
32706
|
-
return
|
|
32813
|
+
return _context7.a(2);
|
|
32707
32814
|
}
|
|
32708
|
-
},
|
|
32815
|
+
}, _callee7, null, [[1, 3]]);
|
|
32709
32816
|
}));
|
|
32710
|
-
return function
|
|
32711
|
-
return
|
|
32817
|
+
return function addSignerOnBoarding(_x3) {
|
|
32818
|
+
return _ref7.apply(this, arguments);
|
|
32712
32819
|
};
|
|
32713
32820
|
}();
|
|
32714
|
-
var
|
|
32715
|
-
var
|
|
32716
|
-
|
|
32717
|
-
|
|
32718
|
-
privateKey,
|
|
32719
|
-
pkcs10,
|
|
32720
|
-
subjectAttributes,
|
|
32721
|
-
csr,
|
|
32722
|
-
_args2 = arguments,
|
|
32723
|
-
_t2;
|
|
32724
|
-
return _regenerator().w(function (_context2) {
|
|
32725
|
-
while (1) switch (_context2.p = _context2.n) {
|
|
32821
|
+
var addSignerOnPremise = /*#__PURE__*/function () {
|
|
32822
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
32823
|
+
return _regenerator().w(function (_context8) {
|
|
32824
|
+
while (1) switch (_context8.n) {
|
|
32726
32825
|
case 0:
|
|
32727
|
-
|
|
32728
|
-
|
|
32729
|
-
|
|
32730
|
-
|
|
32731
|
-
|
|
32826
|
+
throw new ApacuanaAPIError("Adding signers is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
|
|
32827
|
+
case 1:
|
|
32828
|
+
return _context8.a(2);
|
|
32829
|
+
}
|
|
32830
|
+
}, _callee8);
|
|
32831
|
+
}));
|
|
32832
|
+
return function addSignerOnPremise() {
|
|
32833
|
+
return _ref8.apply(this, arguments);
|
|
32834
|
+
};
|
|
32835
|
+
}();
|
|
32836
|
+
|
|
32837
|
+
/**
|
|
32838
|
+
* Adds a signer to a document, handling different integration types.
|
|
32839
|
+
* @param {object} signerData - Data of the signer to be added.
|
|
32840
|
+
* @returns {Promise<{signer: string, success: boolean}>} Object with the result of adding the signer.
|
|
32841
|
+
* @throws {ApacuanaAPIError} If the signer data is invalid, if the API call fails, or if the integration type is not supported.
|
|
32842
|
+
*/
|
|
32843
|
+
var addSigner = /*#__PURE__*/function () {
|
|
32844
|
+
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(signerData) {
|
|
32845
|
+
var _getConfig3, integrationType;
|
|
32846
|
+
return _regenerator().w(function (_context9) {
|
|
32847
|
+
while (1) switch (_context9.n) {
|
|
32848
|
+
case 0:
|
|
32849
|
+
if (!(!signerData || _typeof(signerData) !== "object" || Object.keys(signerData).length === 0)) {
|
|
32850
|
+
_context9.n = 1;
|
|
32851
|
+
break;
|
|
32852
|
+
}
|
|
32853
|
+
throw new ApacuanaAPIError("Signer data (signerData) is required and must be a non-empty object.", 400, "INVALID_PARAMETER");
|
|
32854
|
+
case 1:
|
|
32855
|
+
_getConfig3 = getConfig(), integrationType = _getConfig3.integrationType;
|
|
32856
|
+
if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
|
|
32857
|
+
_context9.n = 2;
|
|
32732
32858
|
break;
|
|
32733
32859
|
}
|
|
32734
|
-
|
|
32860
|
+
return _context9.a(2, addSignerOnBoarding(signerData));
|
|
32735
32861
|
case 2:
|
|
32736
|
-
if (!(
|
|
32737
|
-
|
|
32862
|
+
if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
|
|
32863
|
+
_context9.n = 3;
|
|
32738
32864
|
break;
|
|
32739
32865
|
}
|
|
32740
|
-
|
|
32866
|
+
return _context9.a(2, addSignerOnPremise(signerData));
|
|
32741
32867
|
case 3:
|
|
32742
|
-
|
|
32743
|
-
|
|
32744
|
-
|
|
32745
|
-
|
|
32746
|
-
|
|
32747
|
-
|
|
32748
|
-
|
|
32749
|
-
|
|
32750
|
-
|
|
32751
|
-
|
|
32752
|
-
|
|
32753
|
-
|
|
32754
|
-
|
|
32755
|
-
|
|
32756
|
-
|
|
32757
|
-
|
|
32758
|
-
|
|
32759
|
-
|
|
32760
|
-
|
|
32761
|
-
|
|
32868
|
+
throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
|
|
32869
|
+
case 4:
|
|
32870
|
+
return _context9.a(2);
|
|
32871
|
+
}
|
|
32872
|
+
}, _callee9);
|
|
32873
|
+
}));
|
|
32874
|
+
return function addSigner(_x4) {
|
|
32875
|
+
return _ref9.apply(this, arguments);
|
|
32876
|
+
};
|
|
32877
|
+
}();
|
|
32878
|
+
var getDocsOnPremise = /*#__PURE__*/function () {
|
|
32879
|
+
var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
|
|
32880
|
+
return _regenerator().w(function (_context0) {
|
|
32881
|
+
while (1) switch (_context0.n) {
|
|
32882
|
+
case 0:
|
|
32883
|
+
throw new ApacuanaAPIError("Document retrieval is not supported for integration type: ONBOARDING", 501, "NOT_IMPLEMENTED");
|
|
32884
|
+
case 1:
|
|
32885
|
+
return _context0.a(2);
|
|
32886
|
+
}
|
|
32887
|
+
}, _callee0);
|
|
32888
|
+
}));
|
|
32889
|
+
return function getDocsOnPremise() {
|
|
32890
|
+
return _ref0.apply(this, arguments);
|
|
32891
|
+
};
|
|
32892
|
+
}();
|
|
32893
|
+
var getDocsOnBoarding = /*#__PURE__*/function () {
|
|
32894
|
+
var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(data) {
|
|
32895
|
+
var _getConfig4, customerId, params, apiUrl, response, _t3;
|
|
32896
|
+
return _regenerator().w(function (_context1) {
|
|
32897
|
+
while (1) switch (_context1.p = _context1.n) {
|
|
32898
|
+
case 0:
|
|
32899
|
+
_getConfig4 = getConfig(), customerId = _getConfig4.customerId;
|
|
32900
|
+
if (customerId) {
|
|
32901
|
+
_context1.n = 1;
|
|
32902
|
+
break;
|
|
32762
32903
|
}
|
|
32763
|
-
|
|
32764
|
-
|
|
32765
|
-
|
|
32766
|
-
|
|
32767
|
-
|
|
32768
|
-
|
|
32769
|
-
|
|
32770
|
-
// value: new asn1js.Utf8String({ value: userData.locality || 'N/A' }),
|
|
32771
|
-
// },
|
|
32772
|
-
].filter(function (attr) {
|
|
32773
|
-
return attr.value.value;
|
|
32774
|
-
}); // Filtra atributos sin valor.
|
|
32775
|
-
// 3. Asignar los atributos al Subject.
|
|
32776
|
-
subjectAttributes.forEach(function (attr) {
|
|
32777
|
-
return pkcs10.subject.typesAndValues.push(new AttributeTypeAndValue(attr));
|
|
32904
|
+
throw new ApacuanaAPIError("'customerId' is not configured. Please configure the SDK.", 400, "CONFIGURATION_ERROR");
|
|
32905
|
+
case 1:
|
|
32906
|
+
_context1.p = 1;
|
|
32907
|
+
params = new URLSearchParams({
|
|
32908
|
+
page: data.page,
|
|
32909
|
+
customerid: customerId,
|
|
32910
|
+
size: data.size
|
|
32778
32911
|
});
|
|
32779
|
-
|
|
32780
|
-
|
|
32781
|
-
|
|
32782
|
-
|
|
32912
|
+
if (typeof data.status !== "undefined") {
|
|
32913
|
+
params.append("status", data.status);
|
|
32914
|
+
}
|
|
32915
|
+
apiUrl = "services/api/documents/listcustomer?".concat(params.toString());
|
|
32916
|
+
_context1.n = 2;
|
|
32917
|
+
return httpRequest(apiUrl, {}, "GET");
|
|
32918
|
+
case 2:
|
|
32919
|
+
response = _context1.v;
|
|
32920
|
+
return _context1.a(2, {
|
|
32921
|
+
totalRecords: response.numofrecords,
|
|
32922
|
+
records: response.records,
|
|
32923
|
+
success: true
|
|
32924
|
+
});
|
|
32925
|
+
case 3:
|
|
32926
|
+
_context1.p = 3;
|
|
32927
|
+
_t3 = _context1.v;
|
|
32928
|
+
if (!(_t3.name === "ApacuanaAPIError")) {
|
|
32929
|
+
_context1.n = 4;
|
|
32930
|
+
break;
|
|
32931
|
+
}
|
|
32932
|
+
throw _t3;
|
|
32783
32933
|
case 4:
|
|
32784
|
-
|
|
32785
|
-
return pkcs10.sign(privateKey, hashAlg);
|
|
32934
|
+
throw new ApacuanaAPIError("Failed to get document list (on-premise): ".concat(_t3.message));
|
|
32786
32935
|
case 5:
|
|
32787
|
-
|
|
32788
|
-
csr = pkcs10.toSchema().toBER(false); // 6. Retornar el CSR y el Subject.
|
|
32789
|
-
return _context2.a(2, {
|
|
32790
|
-
csr: csr,
|
|
32791
|
-
subject: pkcs10.subject
|
|
32792
|
-
});
|
|
32793
|
-
case 6:
|
|
32794
|
-
_context2.p = 6;
|
|
32795
|
-
_t2 = _context2.v;
|
|
32796
|
-
// Manejo de errores centralizado.
|
|
32797
|
-
console.error("Error durante la generación del CSR:", _t2);
|
|
32798
|
-
throw new ApacuanaAPIError("Fallo en la generaci\xF3n del CSR: ".concat(_t2.message), 0, "CSR_GENERATION_ERROR");
|
|
32799
|
-
case 7:
|
|
32800
|
-
return _context2.a(2);
|
|
32936
|
+
return _context1.a(2);
|
|
32801
32937
|
}
|
|
32802
|
-
},
|
|
32938
|
+
}, _callee1, null, [[1, 3]]);
|
|
32803
32939
|
}));
|
|
32804
|
-
return function
|
|
32805
|
-
return
|
|
32940
|
+
return function getDocsOnBoarding(_x5) {
|
|
32941
|
+
return _ref1.apply(this, arguments);
|
|
32806
32942
|
};
|
|
32807
32943
|
}();
|
|
32808
32944
|
|
|
32809
|
-
|
|
32810
|
-
|
|
32811
|
-
|
|
32812
|
-
|
|
32813
|
-
}
|
|
32814
|
-
|
|
32815
|
-
|
|
32816
|
-
|
|
32817
|
-
|
|
32818
|
-
|
|
32819
|
-
|
|
32820
|
-
return _regenerator().w(function (_context3) {
|
|
32821
|
-
while (1) switch (_context3.n) {
|
|
32945
|
+
/**
|
|
32946
|
+
* Gets a list of documents.
|
|
32947
|
+
* @param {object} data - Object with pagination parameters. Must contain {page, size}.
|
|
32948
|
+
* @returns {Promise<{totalRecords: number, records:any[], success: boolean}>} Object with the list of documents.
|
|
32949
|
+
* @throws {ApacuanaAPIError} If pagination parameters are invalid, if 'customerId' is not configured, if the API call fails, or if the integration type is not supported.
|
|
32950
|
+
*/
|
|
32951
|
+
var getDocs = /*#__PURE__*/function () {
|
|
32952
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(data) {
|
|
32953
|
+
var _getConfig5, integrationType;
|
|
32954
|
+
return _regenerator().w(function (_context10) {
|
|
32955
|
+
while (1) switch (_context10.n) {
|
|
32822
32956
|
case 0:
|
|
32823
|
-
|
|
32824
|
-
|
|
32825
|
-
|
|
32957
|
+
helpers.validateGetDocsData(data);
|
|
32958
|
+
_getConfig5 = getConfig(), integrationType = _getConfig5.integrationType;
|
|
32959
|
+
if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
|
|
32960
|
+
_context10.n = 1;
|
|
32961
|
+
break;
|
|
32962
|
+
}
|
|
32963
|
+
return _context10.a(2, getDocsOnBoarding(data));
|
|
32826
32964
|
case 1:
|
|
32827
|
-
|
|
32828
|
-
|
|
32829
|
-
|
|
32965
|
+
if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
|
|
32966
|
+
_context10.n = 2;
|
|
32967
|
+
break;
|
|
32968
|
+
}
|
|
32969
|
+
return _context10.a(2, getDocsOnPremise());
|
|
32970
|
+
case 2:
|
|
32971
|
+
throw new ApacuanaAPIError("Document retrieval is not supported for an unknown integration type: ".concat(integrationType), 501, "NOT_IMPLEMENTED");
|
|
32972
|
+
case 3:
|
|
32973
|
+
return _context10.a(2);
|
|
32830
32974
|
}
|
|
32831
|
-
},
|
|
32975
|
+
}, _callee10);
|
|
32832
32976
|
}));
|
|
32833
|
-
return
|
|
32834
|
-
|
|
32835
|
-
var helpers = {
|
|
32836
|
-
getCertificateStatus: getCertificateStatus,
|
|
32837
|
-
generateKeyPair: generateKeyPair,
|
|
32838
|
-
generateCSR: generateCSR,
|
|
32839
|
-
exportPrivateKey: exportPrivateKey,
|
|
32840
|
-
arrayBufferToBase64: arrayBufferToBase64
|
|
32841
|
-
};
|
|
32842
|
-
|
|
32843
|
-
var getCertStatus = function getCertStatus() {
|
|
32844
|
-
var config = getConfig();
|
|
32845
|
-
var status = helpers.getCertificateStatus(config.userData, false);
|
|
32846
|
-
return {
|
|
32847
|
-
status: status
|
|
32977
|
+
return function getDocs(_x6) {
|
|
32978
|
+
return _ref10.apply(this, arguments);
|
|
32848
32979
|
};
|
|
32849
|
-
};
|
|
32980
|
+
}();
|
|
32850
32981
|
|
|
32851
32982
|
var apacuana = {
|
|
32852
32983
|
/**
|
|
@@ -32918,7 +33049,10 @@ var apacuana = {
|
|
|
32918
33049
|
}(),
|
|
32919
33050
|
getConfig: getConfig,
|
|
32920
33051
|
requestRevocation: requestRevocation,
|
|
32921
|
-
getCertStatus: getCertStatus
|
|
33052
|
+
getCertStatus: getCertStatus,
|
|
33053
|
+
getCustomer: getCustomer,
|
|
33054
|
+
addSigner: addSigner,
|
|
33055
|
+
getDocs: getDocs
|
|
32922
33056
|
};
|
|
32923
33057
|
|
|
32924
33058
|
export { apacuana as default };
|