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