apacuana-sdk-core 0.3.0 → 0.5.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 (42) hide show
  1. package/coverage/clover.xml +82 -82
  2. package/coverage/coverage-final.json +3 -3
  3. package/coverage/lcov-report/block-navigation.js +1 -1
  4. package/coverage/lcov-report/index.html +1 -1
  5. package/coverage/lcov-report/sorter.js +21 -7
  6. package/coverage/lcov-report/src/api/certs.js.html +2 -2
  7. package/coverage/lcov-report/src/api/index.html +1 -1
  8. package/coverage/lcov-report/src/api/revocations.js.html +12 -15
  9. package/coverage/lcov-report/src/api/signatures.js.html +320 -140
  10. package/coverage/lcov-report/src/api/users.js.html +1 -1
  11. package/coverage/lcov-report/src/config/index.html +1 -1
  12. package/coverage/lcov-report/src/config/index.js.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.html +1 -1
  14. package/coverage/lcov-report/src/errors/index.js.html +1 -1
  15. package/coverage/lcov-report/src/index.html +1 -1
  16. package/coverage/lcov-report/src/index.js.html +6 -3
  17. package/coverage/lcov-report/src/utils/constant.js.html +1 -1
  18. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  19. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  20. package/coverage/lcov-report/src/utils/index.html +1 -1
  21. package/coverage/lcov.info +137 -137
  22. package/dist/api/certs.d.ts +8 -0
  23. package/dist/api/revocations.d.ts +7 -0
  24. package/dist/api/signatures.d.ts +107 -0
  25. package/dist/api/users.d.ts +15 -0
  26. package/dist/config/index.d.ts +11 -0
  27. package/dist/errors/index.d.ts +10 -0
  28. package/dist/index.d.ts +25 -0
  29. package/dist/index.js +204 -97
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +204 -97
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/utils/constant.d.ts +18 -0
  34. package/dist/utils/helpers.d.ts +21 -0
  35. package/dist/utils/httpClient.d.ts +3 -0
  36. package/package.json +9 -4
  37. package/src/api/certs.js +1 -1
  38. package/src/api/revocations.js +10 -11
  39. package/src/api/signatures.js +156 -96
  40. package/src/index.js +2 -1
  41. package/tests/api/signatures.test.js +11 -4
  42. package/tsconfig.json +15 -0
package/dist/index.js CHANGED
@@ -590,32 +590,32 @@ var requestRevocation = /*#__PURE__*/function () {
590
590
  return _regenerator().w(function (_context) {
591
591
  while (1) switch (_context.p = _context.n) {
592
592
  case 0:
593
- console.log('-> Función \'requestRevocation\' ejecutada.');
594
- 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:", {
595
595
  reasonCode: reasonCode
596
596
  });
597
597
  if (reasonCode) {
598
598
  _context.n = 1;
599
599
  break;
600
600
  }
601
- 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.");
602
602
  case 1:
603
603
  _context.p = 1;
604
604
  _context.n = 2;
605
- return httpRequest('users/api/customers/requestcert', {
605
+ return httpRequest("users/api/customers/requestcert", {
606
606
  reason: reasonCode
607
- }, 'POST');
607
+ }, "POST");
608
608
  case 2:
609
609
  response = _context.v;
610
- console.log('Respuesta del servidor', response);
610
+ console.log("Respuesta del servidor", response);
611
611
  if (response.success) {
612
612
  _context.n = 3;
613
613
  break;
614
614
  }
615
- throw new ApacuanaAPIError(response.message || 'Error desconocido al solicitar revocación.');
615
+ throw new ApacuanaAPIError(response.message || "Error desconocido al solicitar revocación.");
616
616
  case 3:
617
617
  return _context.a(2, {
618
- revocationStatus: response.status || 'pending',
618
+ revocationStatus: response.status || "pending",
619
619
  requestId: response.id
620
620
  });
621
621
  case 4:
@@ -32771,6 +32771,112 @@ var helpers = {
32771
32771
  validateGetDigestData: validateGetDigestData
32772
32772
  };
32773
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
+
32774
32880
  /**
32775
32881
  * Gets the user's certificate status.
32776
32882
  * @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
@@ -32787,125 +32893,83 @@ var getCertStatus = function getCertStatus() {
32787
32893
  };
32788
32894
 
32789
32895
  var addSignerOnBoarding = /*#__PURE__*/function () {
32790
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(signerData) {
32896
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(signerData) {
32791
32897
  var _t2;
32792
- return _regenerator().w(function (_context7) {
32793
- while (1) switch (_context7.p = _context7.n) {
32898
+ return _regenerator().w(function (_context5) {
32899
+ while (1) switch (_context5.p = _context5.n) {
32794
32900
  case 0:
32795
32901
  helpers.validateOnBoardingSignerData(signerData);
32796
- _context7.p = 1;
32797
- _context7.n = 2;
32902
+ _context5.p = 1;
32903
+ _context5.n = 2;
32798
32904
  return httpRequest("services/api/documents/signing", signerData, "POST");
32799
32905
  case 2:
32800
- return _context7.a(2, {
32906
+ return _context5.a(2, {
32801
32907
  signer: signerData.typedoc + signerData.doc,
32802
32908
  success: true
32803
32909
  });
32804
32910
  case 3:
32805
- _context7.p = 3;
32806
- _t2 = _context7.v;
32911
+ _context5.p = 3;
32912
+ _t2 = _context5.v;
32807
32913
  if (!(_t2 instanceof ApacuanaAPIError)) {
32808
- _context7.n = 4;
32914
+ _context5.n = 4;
32809
32915
  break;
32810
32916
  }
32811
32917
  throw _t2;
32812
32918
  case 4:
32813
32919
  throw new Error("Failed to add signer in On-Boarding: ".concat(_t2.message));
32814
32920
  case 5:
32815
- return _context7.a(2);
32921
+ return _context5.a(2);
32816
32922
  }
32817
- }, _callee7, null, [[1, 3]]);
32923
+ }, _callee5, null, [[1, 3]]);
32818
32924
  }));
32819
- return function addSignerOnBoarding(_x3) {
32820
- return _ref7.apply(this, arguments);
32925
+ return function addSignerOnBoarding(_x2) {
32926
+ return _ref5.apply(this, arguments);
32821
32927
  };
32822
32928
  }();
32823
32929
  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) {
32930
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
32931
+ return _regenerator().w(function (_context6) {
32932
+ while (1) switch (_context6.n) {
32827
32933
  case 0:
32828
32934
  throw new ApacuanaAPIError("Adding signers is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32829
32935
  case 1:
32830
- return _context8.a(2);
32936
+ return _context6.a(2);
32831
32937
  }
32832
- }, _callee8);
32938
+ }, _callee6);
32833
32939
  }));
32834
32940
  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;
32860
- break;
32861
- }
32862
- return _context9.a(2, addSignerOnBoarding(signerData));
32863
- case 2:
32864
- if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
32865
- _context9.n = 3;
32866
- break;
32867
- }
32868
- return _context9.a(2, addSignerOnPremise(signerData));
32869
- case 3:
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);
32941
+ return _ref6.apply(this, arguments);
32878
32942
  };
32879
32943
  }();
32880
32944
  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) {
32945
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
32946
+ return _regenerator().w(function (_context7) {
32947
+ while (1) switch (_context7.n) {
32884
32948
  case 0:
32885
- throw new ApacuanaAPIError("Document retrieval is not supported for integration type: ONBOARDING", 501, "NOT_IMPLEMENTED");
32949
+ throw new ApacuanaAPIError("Document retrieval is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32886
32950
  case 1:
32887
- return _context0.a(2);
32951
+ return _context7.a(2);
32888
32952
  }
32889
- }, _callee0);
32953
+ }, _callee7);
32890
32954
  }));
32891
32955
  return function getDocsOnPremise() {
32892
- return _ref0.apply(this, arguments);
32956
+ return _ref7.apply(this, arguments);
32893
32957
  };
32894
32958
  }();
32895
32959
  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) {
32960
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(data) {
32961
+ var _getConfig, customerId, params, apiUrl, response, _t3;
32962
+ return _regenerator().w(function (_context8) {
32963
+ while (1) switch (_context8.p = _context8.n) {
32900
32964
  case 0:
32901
- _getConfig4 = getConfig(), customerId = _getConfig4.customerId;
32965
+ _getConfig = getConfig(), customerId = _getConfig.customerId;
32902
32966
  if (customerId) {
32903
- _context1.n = 1;
32967
+ _context8.n = 1;
32904
32968
  break;
32905
32969
  }
32906
32970
  throw new ApacuanaAPIError("'customerId' is not configured. Please configure the SDK.", 400, "CONFIGURATION_ERROR");
32907
32971
  case 1:
32908
- _context1.p = 1;
32972
+ _context8.p = 1;
32909
32973
  params = new URLSearchParams({
32910
32974
  page: data.page,
32911
32975
  customerid: customerId,
@@ -32915,40 +32979,82 @@ var getDocsOnBoarding = /*#__PURE__*/function () {
32915
32979
  params.append("status", data.status);
32916
32980
  }
32917
32981
  apiUrl = "services/api/documents/listcustomer?".concat(params.toString());
32918
- _context1.n = 2;
32982
+ _context8.n = 2;
32919
32983
  return httpRequest(apiUrl, {}, "GET");
32920
32984
  case 2:
32921
- response = _context1.v;
32922
- return _context1.a(2, {
32985
+ response = _context8.v;
32986
+ return _context8.a(2, {
32923
32987
  totalRecords: response.numofrecords,
32924
32988
  records: response.records,
32925
32989
  success: true
32926
32990
  });
32927
32991
  case 3:
32928
- _context1.p = 3;
32929
- _t3 = _context1.v;
32992
+ _context8.p = 3;
32993
+ _t3 = _context8.v;
32930
32994
  if (!(_t3.name === "ApacuanaAPIError")) {
32931
- _context1.n = 4;
32995
+ _context8.n = 4;
32932
32996
  break;
32933
32997
  }
32934
32998
  throw _t3;
32935
32999
  case 4:
32936
- throw new ApacuanaAPIError("Failed to get document list (on-premise): ".concat(_t3.message));
33000
+ throw new ApacuanaAPIError("Failed to get document list (on-boarding): ".concat(_t3.message));
32937
33001
  case 5:
33002
+ return _context8.a(2);
33003
+ }
33004
+ }, _callee8, null, [[1, 3]]);
33005
+ }));
33006
+ return function getDocsOnBoarding(_x3) {
33007
+ return _ref8.apply(this, arguments);
33008
+ };
33009
+ }();
33010
+
33011
+ /**
33012
+ * Añade un firmante a un documento.
33013
+ * @param {SignerData} signerData - Los datos del firmante que se va a añadir.
33014
+ * @returns {Promise<AddSignerResponse>} Una promesa que resuelve a un objeto con el resultado de la operación.
33015
+ * @throws {ApacuanaAPIError} Si los datos del firmante son inválidos, la llamada a la API falla, o el tipo de integración no es soportado.
33016
+ */
33017
+ var addSigner = /*#__PURE__*/function () {
33018
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(signerData) {
33019
+ var _getConfig4, integrationType;
33020
+ return _regenerator().w(function (_context1) {
33021
+ while (1) switch (_context1.n) {
33022
+ case 0:
33023
+ if (!(!signerData || _typeof(signerData) !== "object" || Object.keys(signerData).length === 0)) {
33024
+ _context1.n = 1;
33025
+ break;
33026
+ }
33027
+ throw new ApacuanaAPIError("Signer data (signerData) is required and must be a non-empty object.", 400, "INVALID_PARAMETER");
33028
+ case 1:
33029
+ _getConfig4 = getConfig(), integrationType = _getConfig4.integrationType;
33030
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33031
+ _context1.n = 2;
33032
+ break;
33033
+ }
33034
+ return _context1.a(2, addSignerOnBoarding(signerData));
33035
+ case 2:
33036
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33037
+ _context1.n = 3;
33038
+ break;
33039
+ }
33040
+ return _context1.a(2, addSignerOnPremise());
33041
+ case 3:
33042
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
33043
+ case 4:
32938
33044
  return _context1.a(2);
32939
33045
  }
32940
- }, _callee1, null, [[1, 3]]);
33046
+ }, _callee1);
32941
33047
  }));
32942
- return function getDocsOnBoarding(_x5) {
33048
+ return function addSigner(_x5) {
32943
33049
  return _ref1.apply(this, arguments);
32944
33050
  };
32945
33051
  }();
32946
33052
 
32947
33053
  /**
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.
33054
+ * Obtiene una lista de documentos basada en los filtros especificados.
33055
+ * @param {GetDocsParams} data - Objeto con parámetros de paginación y filtros.
33056
+ * @returns {Promise<GetDocsResponse>} Una promesa que resuelve a un objeto con la lista de documentos.
33057
+ * @throws {ApacuanaAPIError} Si los parámetros de paginación son inválidos, 'customerId' no está configurado, la llamada a la API falla, o el tipo de integración no es soportado.
32952
33058
  */
32953
33059
  var getDocs = /*#__PURE__*/function () {
32954
33060
  var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(data) {
@@ -33054,7 +33160,8 @@ var apacuana = {
33054
33160
  getCertStatus: getCertStatus,
33055
33161
  getCustomer: getCustomer,
33056
33162
  addSigner: addSigner,
33057
- getDocs: getDocs
33163
+ getDocs: getDocs,
33164
+ generateCert: generateCert
33058
33165
  };
33059
33166
 
33060
33167
  module.exports = apacuana;