apacuana-sdk-core 0.2.0 → 0.4.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 (47) hide show
  1. package/README.md +64 -15
  2. package/coverage/clover.xml +155 -121
  3. package/coverage/coverage-final.json +8 -8
  4. package/coverage/lcov-report/block-navigation.js +1 -1
  5. package/coverage/lcov-report/index.html +30 -30
  6. package/coverage/lcov-report/sorter.js +21 -7
  7. package/coverage/lcov-report/src/api/certs.js.html +73 -28
  8. package/coverage/lcov-report/src/api/index.html +31 -31
  9. package/coverage/lcov-report/src/api/revocations.js.html +12 -15
  10. package/coverage/lcov-report/src/api/signatures.js.html +186 -159
  11. package/coverage/lcov-report/src/api/users.js.html +24 -63
  12. package/coverage/lcov-report/src/config/index.html +1 -1
  13. package/coverage/lcov-report/src/config/index.js.html +1 -1
  14. package/coverage/lcov-report/src/errors/index.html +1 -1
  15. package/coverage/lcov-report/src/errors/index.js.html +8 -8
  16. package/coverage/lcov-report/src/index.html +1 -1
  17. package/coverage/lcov-report/src/index.js.html +6 -3
  18. package/coverage/lcov-report/src/utils/constant.js.html +4 -4
  19. package/coverage/lcov-report/src/utils/helpers.js.html +101 -50
  20. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  21. package/coverage/lcov-report/src/utils/index.html +19 -19
  22. package/coverage/lcov.info +293 -221
  23. package/dist/api/certs.d.ts +8 -0
  24. package/dist/api/revocations.d.ts +7 -0
  25. package/dist/api/signatures.d.ts +16 -0
  26. package/dist/api/users.d.ts +15 -0
  27. package/dist/config/index.d.ts +11 -0
  28. package/dist/errors/index.d.ts +10 -0
  29. package/dist/index.d.ts +25 -0
  30. package/dist/index.js +252 -251
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +252 -251
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/utils/constant.d.ts +18 -0
  35. package/dist/utils/helpers.d.ts +21 -0
  36. package/dist/utils/httpClient.d.ts +3 -0
  37. package/package.json +9 -4
  38. package/src/api/certs.js +25 -10
  39. package/src/api/revocations.js +10 -11
  40. package/src/api/signatures.js +106 -97
  41. package/src/api/users.js +16 -29
  42. package/src/index.js +2 -1
  43. package/src/utils/helpers.js +17 -0
  44. package/tests/api/certs.test.js +58 -74
  45. package/tests/api/signatures.test.js +18 -73
  46. package/tests/api/users.test.js +10 -10
  47. package/tsconfig.json +15 -0
package/dist/index.js CHANGED
@@ -522,7 +522,7 @@ var httpRequest = /*#__PURE__*/function () {
522
522
  * Este método es útil para endpoints que requieren datos en el cuerpo de la petición
523
523
  * para buscar un usuario, como un ID de sesión o un token de acceso.
524
524
  *
525
- * @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.
526
526
  * @throws {Error} Si los parámetros de entrada son inválidos.
527
527
  * @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
528
528
  */
@@ -533,62 +533,46 @@ var getCustomer = /*#__PURE__*/function () {
533
533
  while (1) switch (_context.p = _context.n) {
534
534
  case 0:
535
535
  _getConfig = getConfig(), verificationId = _getConfig.verificationId, customerId = _getConfig.customerId;
536
- body = {
537
- verificationid: verificationId,
538
- customerid: customerId
539
- }; // eslint-disable-next-line no-console
540
- console.log("-> Función 'getCustomer' ejecutada.");
541
- // eslint-disable-next-line no-console
542
- console.log("Parámetros recibidos para buscar usuario:", body);
543
-
544
- // 1. Validación de Parámetros de Entrada (Lado del SDK)
545
- if (!(!body || !body.verificationid || !body.customerid)) {
536
+ if (!(!verificationId || !customerId)) {
546
537
  _context.n = 1;
547
538
  break;
548
539
  }
549
- 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");
550
541
  case 1:
551
- _context.p = 1;
552
- _context.n = 2;
553
- return httpRequest("services/api/register/init",
554
- // Endpoint de ejemplo
555
- body,
556
- // Los datos a enviar en el cuerpo de la petición
557
- "POST");
558
- 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:
559
550
  response = _context.v;
560
- // 3. Procesar la Respuesta del Backend
561
- // Asumiendo que la respuesta exitosa del backend incluye un objeto 'user'
562
- // eslint-disable-next-line no-console
563
- console.log("Respuesta del servidor para el token:", response);
564
551
  if (!(!response.sessionid || !response.entry)) {
565
- _context.n = 3;
552
+ _context.n = 4;
566
553
  break;
567
554
  }
568
- throw new ApacuanaAPIError("La respuesta de la API no contiene el usuario.", 200, "INVALID_API_RESPONSE");
569
- case 3:
555
+ throw new ApacuanaAPIError("The API response does not contain the user.", 200, "INVALID_API_RESPONSE");
556
+ case 4:
570
557
  return _context.a(2, {
571
558
  token: response.sessionid,
572
559
  userData: response.entry,
573
560
  success: true
574
561
  });
575
- case 4:
576
- _context.p = 4;
562
+ case 5:
563
+ _context.p = 5;
577
564
  _t = _context.v;
578
- // 4. Manejo de Errores
579
- // eslint-disable-next-line no-console
580
- console.error("Error en getCustomer:", _t);
581
565
  if (!(_t instanceof ApacuanaAPIError)) {
582
- _context.n = 5;
566
+ _context.n = 6;
583
567
  break;
584
568
  }
585
569
  throw _t;
586
- case 5:
587
- throw new ApacuanaAPIError("Fallo inesperado al obtener el token: ".concat(_t.message || "Error desconocido"));
588
570
  case 6:
571
+ throw new ApacuanaAPIError("Unexpected failure getting token: ".concat(_t.message || "Unknown error"));
572
+ case 7:
589
573
  return _context.a(2);
590
574
  }
591
- }, _callee, null, [[1, 4]]);
575
+ }, _callee, null, [[2, 5]]);
592
576
  }));
593
577
  return function getCustomer() {
594
578
  return _ref.apply(this, arguments);
@@ -606,32 +590,32 @@ var requestRevocation = /*#__PURE__*/function () {
606
590
  return _regenerator().w(function (_context) {
607
591
  while (1) switch (_context.p = _context.n) {
608
592
  case 0:
609
- console.log('-> Función \'requestRevocation\' ejecutada.');
610
- console.log('Parámetros recibidos para solicitud de revocación:', {
593
+ console.log("-> Función 'requestRevocation' ejecutada.");
594
+ console.log("Parámetros recibidos para solicitud de revocación:", {
611
595
  reasonCode: reasonCode
612
596
  });
613
597
  if (reasonCode) {
614
598
  _context.n = 1;
615
599
  break;
616
600
  }
617
- throw new Error('ID de certificado y motivo son requeridos para requestRevocation.');
601
+ throw new Error("ID de certificado y motivo son requeridos para requestRevocation.");
618
602
  case 1:
619
603
  _context.p = 1;
620
604
  _context.n = 2;
621
- return httpRequest('users/api/customers/requestcert', {
605
+ return httpRequest("users/api/customers/requestcert", {
622
606
  reason: reasonCode
623
- }, 'POST');
607
+ }, "POST");
624
608
  case 2:
625
609
  response = _context.v;
626
- console.log('Respuesta del servidor', response);
610
+ console.log("Respuesta del servidor", response);
627
611
  if (response.success) {
628
612
  _context.n = 3;
629
613
  break;
630
614
  }
631
- throw new ApacuanaAPIError(response.message || 'Error desconocido al solicitar revocación.');
615
+ throw new ApacuanaAPIError(response.message || "Error desconocido al solicitar revocación.");
632
616
  case 3:
633
617
  return _context.a(2, {
634
- revocationStatus: response.status || 'pending',
618
+ revocationStatus: response.status || "pending",
635
619
  requestId: response.id
636
620
  });
637
621
  case 4:
@@ -32771,6 +32755,11 @@ var validateGetDocsData = function validateGetDocsData(data) {
32771
32755
  throw new ApacuanaAPIError("El parámetro 'status' no es válido. Los valores permitidos son: -1, 0, 1, 2.", 400, "INVALID_PARAMETER");
32772
32756
  }
32773
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
+ };
32774
32763
  var helpers = {
32775
32764
  getCertificateStatus: getCertificateStatus,
32776
32765
  exportPrivateKey: exportPrivateKey,
@@ -32778,9 +32767,121 @@ var helpers = {
32778
32767
  encryptedCsr: encryptedCsr,
32779
32768
  validateOnBoardingSignerData: validateOnBoardingSignerData,
32780
32769
  validateCsr: validateCsr,
32781
- validateGetDocsData: validateGetDocsData
32770
+ validateGetDocsData: validateGetDocsData,
32771
+ validateGetDigestData: validateGetDigestData
32782
32772
  };
32783
32773
 
32774
+ var generateCertOnBoarding = /*#__PURE__*/function () {
32775
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
32776
+ var csr,
32777
+ encryptedCSR,
32778
+ response,
32779
+ cert,
32780
+ _args = arguments,
32781
+ _t;
32782
+ return _regenerator().w(function (_context) {
32783
+ while (1) switch (_context.p = _context.n) {
32784
+ case 0:
32785
+ csr = _args.length > 0 && _args[0] !== undefined ? _args[0] : undefined;
32786
+ _context.p = 1;
32787
+ encryptedCSR = helpers.encryptedCsr(csr);
32788
+ _context.n = 2;
32789
+ return httpRequest("services/api/register/certificate", encryptedCSR, "POST");
32790
+ case 2:
32791
+ response = _context.v;
32792
+ cert = response.cert;
32793
+ if (cert) {
32794
+ _context.n = 3;
32795
+ break;
32796
+ }
32797
+ throw new ApacuanaAPIError("The API response does not contain the certificate.", response.status, "INVALID_API_RESPONSE");
32798
+ case 3:
32799
+ return _context.a(2, {
32800
+ cert: cert,
32801
+ success: true
32802
+ });
32803
+ case 4:
32804
+ _context.p = 4;
32805
+ _t = _context.v;
32806
+ if (!(_t instanceof ApacuanaAPIError)) {
32807
+ _context.n = 5;
32808
+ break;
32809
+ }
32810
+ throw _t;
32811
+ case 5:
32812
+ throw new Error("Certificate generation failed: ".concat(_t.message));
32813
+ case 6:
32814
+ return _context.a(2);
32815
+ }
32816
+ }, _callee, null, [[1, 4]]);
32817
+ }));
32818
+ return function generateCertOnBoarding() {
32819
+ return _ref.apply(this, arguments);
32820
+ };
32821
+ }();
32822
+ var generateCertOnPremise = /*#__PURE__*/function () {
32823
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
32824
+ return _regenerator().w(function (_context2) {
32825
+ while (1) switch (_context2.n) {
32826
+ case 0:
32827
+ throw new ApacuanaAPIError("Certificate generation is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32828
+ case 1:
32829
+ return _context2.a(2);
32830
+ }
32831
+ }, _callee2);
32832
+ }));
32833
+ return function generateCertOnPremise() {
32834
+ return _ref2.apply(this, arguments);
32835
+ };
32836
+ }();
32837
+
32838
+ /**
32839
+ * Generates a digital certificate.
32840
+ * @param {string} [csr] - Certificate Signing Request (CSR).
32841
+ * @returns {Promise<{cert: string, success: boolean}>} Object with the generated certificate and a success indicator.
32842
+ * @throws {ApacuanaAPIError} If the CSR is invalid, if the API response does not contain the certificate, or if the integration type is not supported.
32843
+ * @throws {Error} If certificate generation fails for another reason.
32844
+ */
32845
+ var generateCert = /*#__PURE__*/function () {
32846
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
32847
+ var csr,
32848
+ _getConfig,
32849
+ integrationType,
32850
+ _args3 = arguments;
32851
+ return _regenerator().w(function (_context3) {
32852
+ while (1) switch (_context3.n) {
32853
+ case 0:
32854
+ csr = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : undefined;
32855
+ _getConfig = getConfig(), integrationType = _getConfig.integrationType;
32856
+ helpers.validateCsr(csr);
32857
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
32858
+ _context3.n = 1;
32859
+ break;
32860
+ }
32861
+ return _context3.a(2, generateCertOnBoarding(csr));
32862
+ case 1:
32863
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
32864
+ _context3.n = 2;
32865
+ break;
32866
+ }
32867
+ return _context3.a(2, generateCertOnPremise());
32868
+ case 2:
32869
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
32870
+ case 3:
32871
+ return _context3.a(2);
32872
+ }
32873
+ }, _callee3);
32874
+ }));
32875
+ return function generateCert() {
32876
+ return _ref3.apply(this, arguments);
32877
+ };
32878
+ }();
32879
+
32880
+ /**
32881
+ * Gets the user's certificate status.
32882
+ * @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
32883
+ * @returns {{status: string, success: boolean}} Object with the certificate status and a success indicator.
32884
+ */
32784
32885
  var getCertStatus = function getCertStatus() {
32785
32886
  var isCertificateInDevice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
32786
32887
  var config = getConfig();
@@ -32791,299 +32892,198 @@ var getCertStatus = function getCertStatus() {
32791
32892
  };
32792
32893
  };
32793
32894
 
32794
- /*
32795
- const signDocumentOnBoarding = async (documentData, signatureData) => {
32796
- try {
32797
- const response = await httpRequest(
32798
- "/docs/sign",
32799
- { documentData, signatureData },
32800
- "POST"
32801
- );
32802
- if (!response.success) {
32803
- throw new ApacuanaAPIError(
32804
- response.message || "Error desconocido al firmar documento."
32805
- );
32806
- }
32807
- return { signedDocId: response.id, status: response.message };
32808
- } catch (error) {
32809
- if (error.name === "ApacuanaAPIError") {
32810
- throw error;
32811
- }
32812
- throw new ApacuanaAPIError(
32813
- `Fallo en la firma del documento (on-boarding): ${error.message}`
32814
- );
32815
- }
32816
- };
32817
-
32818
- const signDocumentOnPremise = async (signature, cert, privateKey) => {
32819
- helpers.validateSignOnPremiseData({ signature, cert, privateKey });
32820
- try {
32821
- const digestBody = {
32822
- publickey: cert,
32823
- };
32824
-
32825
- const digestResponse = await httpRequest(
32826
- `services/api/documents/getdigest/${signature.id}`,
32827
- digestBody,
32828
- "POST"
32829
- );
32830
-
32831
- const digest = digestResponse.data?.digest || digestResponse.digest;
32832
- if (!digest) {
32833
- throw new ApacuanaAPIError(
32834
- "La generación de firma ha fallado: no se pudo obtener el digest del documento."
32835
- );
32836
- }
32837
-
32838
- const signedDigest = await helpers.signDigest(digest, privateKey);
32839
-
32840
- const signBody = {
32841
- positions: JSON.stringify(
32842
- signature.positions.map((p) => ({
32843
- x: p.x,
32844
- y: p.y,
32845
- page: p.page,
32846
- status: 1,
32847
- }))
32848
- ),
32849
- publickey: cert,
32850
- signeddigest: signedDigest,
32851
- };
32852
-
32853
- const signResponse = await httpRequest(
32854
- `services/api/documents/sign/${signature.id}`,
32855
- signBody,
32856
- "PUT"
32857
- );
32858
-
32859
- return signResponse;
32860
- } catch (error) {
32861
- if (error.name === "ApacuanaAPIError") {
32862
- throw error;
32863
- }
32864
- throw new ApacuanaAPIError(
32865
- `Fallo en la firma del documento (on-premise): ${error.message}`
32866
- );
32867
- }
32868
- };
32869
- */
32870
-
32871
- /**
32872
- * Firma un documento PDF con un certificado digital.
32873
- * @param {object} data - Datos para la firma. Para 'on-boarding', debe contener {documentData, signatureData}. Para 'on-premise', debe contener {signature, cert, privateKey}.
32874
- * @returns {Promise<object>} Objeto con el resultado de la firma.
32875
- */
32876
- /*
32877
- export const signDocument = async (signData) => {
32878
- if (
32879
- !signData ||
32880
- typeof signData !== "object" ||
32881
- Object.keys(signData).length === 0
32882
- ) {
32883
- throw new ApacuanaAPIError(
32884
- "El parámetro 'data' es requerido y debe ser un objeto no vacío.",
32885
- 400,
32886
- "INVALID_PARAMETER"
32887
- );
32888
- }
32889
-
32890
- const { integrationType } = getConfig();
32891
-
32892
- if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
32893
- return signDocumentOnBoarding(signData);
32894
- }
32895
-
32896
- if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
32897
- return signDocumentOnPremise(signData);
32898
- }
32899
-
32900
- throw new ApacuanaAPIError(
32901
- `Tipo de integración no soportado: ${integrationType}`,
32902
- 400,
32903
- "UNSUPPORTED_INTEGRATION_TYPE"
32904
- );
32905
- };
32906
- */
32907
-
32908
32895
  var addSignerOnBoarding = /*#__PURE__*/function () {
32909
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signerData) {
32910
- var _t;
32911
- return _regenerator().w(function (_context) {
32912
- while (1) switch (_context.p = _context.n) {
32896
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(signerData) {
32897
+ var _t2;
32898
+ return _regenerator().w(function (_context7) {
32899
+ while (1) switch (_context7.p = _context7.n) {
32913
32900
  case 0:
32914
32901
  helpers.validateOnBoardingSignerData(signerData);
32915
- _context.p = 1;
32916
- _context.n = 2;
32902
+ _context7.p = 1;
32903
+ _context7.n = 2;
32917
32904
  return httpRequest("services/api/documents/signing", signerData, "POST");
32918
32905
  case 2:
32919
- return _context.a(2, {
32906
+ return _context7.a(2, {
32920
32907
  signer: signerData.typedoc + signerData.doc,
32921
32908
  success: true
32922
32909
  });
32923
32910
  case 3:
32924
- _context.p = 3;
32925
- _t = _context.v;
32926
- if (!(_t instanceof ApacuanaAPIError)) {
32927
- _context.n = 4;
32911
+ _context7.p = 3;
32912
+ _t2 = _context7.v;
32913
+ if (!(_t2 instanceof ApacuanaAPIError)) {
32914
+ _context7.n = 4;
32928
32915
  break;
32929
32916
  }
32930
- throw _t;
32917
+ throw _t2;
32931
32918
  case 4:
32932
- throw new Error("Fallo al agregar firmante en On-Boarding: ".concat(_t.message));
32919
+ throw new Error("Failed to add signer in On-Boarding: ".concat(_t2.message));
32933
32920
  case 5:
32934
- return _context.a(2);
32921
+ return _context7.a(2);
32935
32922
  }
32936
- }, _callee, null, [[1, 3]]);
32923
+ }, _callee7, null, [[1, 3]]);
32937
32924
  }));
32938
- return function addSignerOnBoarding(_x) {
32939
- return _ref.apply(this, arguments);
32925
+ return function addSignerOnBoarding(_x3) {
32926
+ return _ref7.apply(this, arguments);
32940
32927
  };
32941
32928
  }();
32942
32929
  var addSignerOnPremise = /*#__PURE__*/function () {
32943
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
32944
- return _regenerator().w(function (_context2) {
32945
- while (1) switch (_context2.n) {
32930
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
32931
+ return _regenerator().w(function (_context8) {
32932
+ while (1) switch (_context8.n) {
32946
32933
  case 0:
32947
- return _context2.a(2, Promise.resolve({
32948
- signerId: "on-premise-signer-id",
32949
- status: "added"
32950
- }));
32934
+ throw new ApacuanaAPIError("Adding signers is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32935
+ case 1:
32936
+ return _context8.a(2);
32951
32937
  }
32952
- }, _callee2);
32938
+ }, _callee8);
32953
32939
  }));
32954
32940
  return function addSignerOnPremise() {
32955
- return _ref2.apply(this, arguments);
32941
+ return _ref8.apply(this, arguments);
32956
32942
  };
32957
32943
  }();
32958
32944
 
32959
32945
  /**
32960
- * Agrega un firmante a un documento, manejando diferentes tipos de integración.
32961
- * @param {object} signerData - Datos del firmante a agregar.
32962
- * @returns {Promise<object>} Objeto con el resultado de agregar el firmante.
32946
+ * Adds a signer to a document, handling different integration types.
32947
+ * @param {object} signerData - Data of the signer to be added.
32948
+ * @returns {Promise<{signer: string, success: boolean}>} Object with the result of adding the signer.
32949
+ * @throws {ApacuanaAPIError} If the signer data is invalid, if the API call fails, or if the integration type is not supported.
32963
32950
  */
32964
32951
  var addSigner = /*#__PURE__*/function () {
32965
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(signerData) {
32966
- var _getConfig, integrationType;
32967
- return _regenerator().w(function (_context3) {
32968
- while (1) switch (_context3.n) {
32952
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(signerData) {
32953
+ var _getConfig3, integrationType;
32954
+ return _regenerator().w(function (_context9) {
32955
+ while (1) switch (_context9.n) {
32969
32956
  case 0:
32970
32957
  if (!(!signerData || _typeof(signerData) !== "object" || Object.keys(signerData).length === 0)) {
32971
- _context3.n = 1;
32958
+ _context9.n = 1;
32972
32959
  break;
32973
32960
  }
32974
- throw new ApacuanaAPIError("Los datos del firmante (signerData) son requeridos y deben ser un objeto no vacío.", 400, "INVALID_PARAMETER");
32961
+ throw new ApacuanaAPIError("Signer data (signerData) is required and must be a non-empty object.", 400, "INVALID_PARAMETER");
32975
32962
  case 1:
32976
- _getConfig = getConfig(), integrationType = _getConfig.integrationType;
32963
+ _getConfig3 = getConfig(), integrationType = _getConfig3.integrationType;
32977
32964
  if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
32978
- _context3.n = 2;
32965
+ _context9.n = 2;
32979
32966
  break;
32980
32967
  }
32981
- return _context3.a(2, addSignerOnBoarding(signerData));
32968
+ return _context9.a(2, addSignerOnBoarding(signerData));
32982
32969
  case 2:
32983
32970
  if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
32984
- _context3.n = 3;
32971
+ _context9.n = 3;
32985
32972
  break;
32986
32973
  }
32987
- return _context3.a(2, addSignerOnPremise(signerData));
32974
+ return _context9.a(2, addSignerOnPremise(signerData));
32988
32975
  case 3:
32989
- throw new ApacuanaAPIError("Tipo de integraci\xF3n no soportado: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
32976
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
32990
32977
  case 4:
32991
- return _context3.a(2);
32978
+ return _context9.a(2);
32992
32979
  }
32993
- }, _callee3);
32980
+ }, _callee9);
32994
32981
  }));
32995
- return function addSigner(_x2) {
32996
- return _ref3.apply(this, arguments);
32982
+ return function addSigner(_x4) {
32983
+ return _ref9.apply(this, arguments);
32997
32984
  };
32998
32985
  }();
32999
32986
  var getDocsOnPremise = /*#__PURE__*/function () {
33000
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
33001
- return _regenerator().w(function (_context4) {
33002
- while (1) switch (_context4.n) {
32987
+ var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0() {
32988
+ return _regenerator().w(function (_context0) {
32989
+ while (1) switch (_context0.n) {
33003
32990
  case 0:
33004
- throw new ApacuanaAPIError("La obtención de documentos no está soportada para el tipo de integración: ONBOARDING", 501, "NOT_IMPLEMENTED");
32991
+ throw new ApacuanaAPIError("Document retrieval is not supported for integration type: ONBOARDING", 501, "NOT_IMPLEMENTED");
33005
32992
  case 1:
33006
- return _context4.a(2);
32993
+ return _context0.a(2);
33007
32994
  }
33008
- }, _callee4);
32995
+ }, _callee0);
33009
32996
  }));
33010
32997
  return function getDocsOnPremise() {
33011
- return _ref4.apply(this, arguments);
32998
+ return _ref0.apply(this, arguments);
33012
32999
  };
33013
33000
  }();
33014
33001
  var getDocsOnBoarding = /*#__PURE__*/function () {
33015
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(data) {
33016
- var _getConfig2, customerId, apiUrl, response, _t2;
33017
- return _regenerator().w(function (_context5) {
33018
- while (1) switch (_context5.p = _context5.n) {
33002
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(data) {
33003
+ var _getConfig4, customerId, params, apiUrl, response, _t3;
33004
+ return _regenerator().w(function (_context1) {
33005
+ while (1) switch (_context1.p = _context1.n) {
33019
33006
  case 0:
33020
- _getConfig2 = getConfig(), customerId = _getConfig2.customerId;
33007
+ _getConfig4 = getConfig(), customerId = _getConfig4.customerId;
33021
33008
  if (customerId) {
33022
- _context5.n = 1;
33009
+ _context1.n = 1;
33023
33010
  break;
33024
33011
  }
33025
- throw new ApacuanaAPIError("El 'customerId' no está configurado. Por favor, configure el SDK.", 400, "CONFIGURATION_ERROR");
33012
+ throw new ApacuanaAPIError("'customerId' is not configured. Please configure the SDK.", 400, "CONFIGURATION_ERROR");
33026
33013
  case 1:
33027
- _context5.p = 1;
33028
- apiUrl = "services/api/documents/listcustomer?page=".concat(data.page, "&customerid=").concat(customerId, "&size=").concat(data.size, "&status=").concat(data.status);
33029
- _context5.n = 2;
33014
+ _context1.p = 1;
33015
+ params = new URLSearchParams({
33016
+ page: data.page,
33017
+ customerid: customerId,
33018
+ size: data.size
33019
+ });
33020
+ if (typeof data.status !== "undefined") {
33021
+ params.append("status", data.status);
33022
+ }
33023
+ apiUrl = "services/api/documents/listcustomer?".concat(params.toString());
33024
+ _context1.n = 2;
33030
33025
  return httpRequest(apiUrl, {}, "GET");
33031
33026
  case 2:
33032
- response = _context5.v;
33033
- return _context5.a(2, response);
33027
+ response = _context1.v;
33028
+ return _context1.a(2, {
33029
+ totalRecords: response.numofrecords,
33030
+ records: response.records,
33031
+ success: true
33032
+ });
33034
33033
  case 3:
33035
- _context5.p = 3;
33036
- _t2 = _context5.v;
33037
- if (!(_t2.name === "ApacuanaAPIError")) {
33038
- _context5.n = 4;
33034
+ _context1.p = 3;
33035
+ _t3 = _context1.v;
33036
+ if (!(_t3.name === "ApacuanaAPIError")) {
33037
+ _context1.n = 4;
33039
33038
  break;
33040
33039
  }
33041
- throw _t2;
33040
+ throw _t3;
33042
33041
  case 4:
33043
- throw new ApacuanaAPIError("Fallo al obtener la lista de documentos (on-premise): ".concat(_t2.message));
33042
+ throw new ApacuanaAPIError("Failed to get document list (on-premise): ".concat(_t3.message));
33044
33043
  case 5:
33045
- return _context5.a(2);
33044
+ return _context1.a(2);
33046
33045
  }
33047
- }, _callee5, null, [[1, 3]]);
33046
+ }, _callee1, null, [[1, 3]]);
33048
33047
  }));
33049
- return function getDocsOnBoarding(_x3) {
33050
- return _ref5.apply(this, arguments);
33048
+ return function getDocsOnBoarding(_x5) {
33049
+ return _ref1.apply(this, arguments);
33051
33050
  };
33052
33051
  }();
33053
33052
 
33054
33053
  /**
33055
- * Obtiene una lista de documentos.
33056
- * @param {object} data - Objeto con los parámetros de paginación. Debe contener {page, size}.
33057
- * @returns {Promise<object>} Objeto con la lista de documentos.
33054
+ * Gets a list of documents.
33055
+ * @param {object} data - Object with pagination parameters. Must contain {page, size}.
33056
+ * @returns {Promise<{totalRecords: number, records:any[], success: boolean}>} Object with the list of documents.
33057
+ * @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.
33058
33058
  */
33059
33059
  var getDocs = /*#__PURE__*/function () {
33060
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(data) {
33061
- var _getConfig3, integrationType;
33062
- return _regenerator().w(function (_context6) {
33063
- while (1) switch (_context6.n) {
33060
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(data) {
33061
+ var _getConfig5, integrationType;
33062
+ return _regenerator().w(function (_context10) {
33063
+ while (1) switch (_context10.n) {
33064
33064
  case 0:
33065
33065
  helpers.validateGetDocsData(data);
33066
- _getConfig3 = getConfig(), integrationType = _getConfig3.integrationType;
33066
+ _getConfig5 = getConfig(), integrationType = _getConfig5.integrationType;
33067
33067
  if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33068
- _context6.n = 1;
33068
+ _context10.n = 1;
33069
33069
  break;
33070
33070
  }
33071
- return _context6.a(2, getDocsOnBoarding(data));
33071
+ return _context10.a(2, getDocsOnBoarding(data));
33072
33072
  case 1:
33073
33073
  if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33074
- _context6.n = 2;
33074
+ _context10.n = 2;
33075
33075
  break;
33076
33076
  }
33077
- return _context6.a(2, getDocsOnPremise());
33077
+ return _context10.a(2, getDocsOnPremise());
33078
33078
  case 2:
33079
- throw new ApacuanaAPIError("La obtenci\xF3n de documentos no est\xE1 soportada para un tipo de integraci\xF3n desconocido: ".concat(integrationType), 501, "NOT_IMPLEMENTED");
33079
+ throw new ApacuanaAPIError("Document retrieval is not supported for an unknown integration type: ".concat(integrationType), 501, "NOT_IMPLEMENTED");
33080
33080
  case 3:
33081
- return _context6.a(2);
33081
+ return _context10.a(2);
33082
33082
  }
33083
- }, _callee6);
33083
+ }, _callee10);
33084
33084
  }));
33085
- return function getDocs(_x4) {
33086
- return _ref6.apply(this, arguments);
33085
+ return function getDocs(_x6) {
33086
+ return _ref10.apply(this, arguments);
33087
33087
  };
33088
33088
  }();
33089
33089
 
@@ -33160,7 +33160,8 @@ var apacuana = {
33160
33160
  getCertStatus: getCertStatus,
33161
33161
  getCustomer: getCustomer,
33162
33162
  addSigner: addSigner,
33163
- getDocs: getDocs
33163
+ getDocs: getDocs,
33164
+ generateCert: generateCert
33164
33165
  };
33165
33166
 
33166
33167
  module.exports = apacuana;