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.mjs CHANGED
@@ -588,32 +588,32 @@ var requestRevocation = /*#__PURE__*/function () {
588
588
  return _regenerator().w(function (_context) {
589
589
  while (1) switch (_context.p = _context.n) {
590
590
  case 0:
591
- console.log('-> Función \'requestRevocation\' ejecutada.');
592
- console.log('Parámetros recibidos para solicitud de revocación:', {
591
+ console.log("-> Función 'requestRevocation' ejecutada.");
592
+ console.log("Parámetros recibidos para solicitud de revocación:", {
593
593
  reasonCode: reasonCode
594
594
  });
595
595
  if (reasonCode) {
596
596
  _context.n = 1;
597
597
  break;
598
598
  }
599
- throw new Error('ID de certificado y motivo son requeridos para requestRevocation.');
599
+ throw new Error("ID de certificado y motivo son requeridos para requestRevocation.");
600
600
  case 1:
601
601
  _context.p = 1;
602
602
  _context.n = 2;
603
- return httpRequest('users/api/customers/requestcert', {
603
+ return httpRequest("users/api/customers/requestcert", {
604
604
  reason: reasonCode
605
- }, 'POST');
605
+ }, "POST");
606
606
  case 2:
607
607
  response = _context.v;
608
- console.log('Respuesta del servidor', response);
608
+ console.log("Respuesta del servidor", response);
609
609
  if (response.success) {
610
610
  _context.n = 3;
611
611
  break;
612
612
  }
613
- throw new ApacuanaAPIError(response.message || 'Error desconocido al solicitar revocación.');
613
+ throw new ApacuanaAPIError(response.message || "Error desconocido al solicitar revocación.");
614
614
  case 3:
615
615
  return _context.a(2, {
616
- revocationStatus: response.status || 'pending',
616
+ revocationStatus: response.status || "pending",
617
617
  requestId: response.id
618
618
  });
619
619
  case 4:
@@ -32769,6 +32769,112 @@ var helpers = {
32769
32769
  validateGetDigestData: validateGetDigestData
32770
32770
  };
32771
32771
 
32772
+ var generateCertOnBoarding = /*#__PURE__*/function () {
32773
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
32774
+ var csr,
32775
+ encryptedCSR,
32776
+ response,
32777
+ cert,
32778
+ _args = arguments,
32779
+ _t;
32780
+ return _regenerator().w(function (_context) {
32781
+ while (1) switch (_context.p = _context.n) {
32782
+ case 0:
32783
+ csr = _args.length > 0 && _args[0] !== undefined ? _args[0] : undefined;
32784
+ _context.p = 1;
32785
+ encryptedCSR = helpers.encryptedCsr(csr);
32786
+ _context.n = 2;
32787
+ return httpRequest("services/api/register/certificate", encryptedCSR, "POST");
32788
+ case 2:
32789
+ response = _context.v;
32790
+ cert = response.cert;
32791
+ if (cert) {
32792
+ _context.n = 3;
32793
+ break;
32794
+ }
32795
+ throw new ApacuanaAPIError("The API response does not contain the certificate.", response.status, "INVALID_API_RESPONSE");
32796
+ case 3:
32797
+ return _context.a(2, {
32798
+ cert: cert,
32799
+ success: true
32800
+ });
32801
+ case 4:
32802
+ _context.p = 4;
32803
+ _t = _context.v;
32804
+ if (!(_t instanceof ApacuanaAPIError)) {
32805
+ _context.n = 5;
32806
+ break;
32807
+ }
32808
+ throw _t;
32809
+ case 5:
32810
+ throw new Error("Certificate generation failed: ".concat(_t.message));
32811
+ case 6:
32812
+ return _context.a(2);
32813
+ }
32814
+ }, _callee, null, [[1, 4]]);
32815
+ }));
32816
+ return function generateCertOnBoarding() {
32817
+ return _ref.apply(this, arguments);
32818
+ };
32819
+ }();
32820
+ var generateCertOnPremise = /*#__PURE__*/function () {
32821
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
32822
+ return _regenerator().w(function (_context2) {
32823
+ while (1) switch (_context2.n) {
32824
+ case 0:
32825
+ throw new ApacuanaAPIError("Certificate generation is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32826
+ case 1:
32827
+ return _context2.a(2);
32828
+ }
32829
+ }, _callee2);
32830
+ }));
32831
+ return function generateCertOnPremise() {
32832
+ return _ref2.apply(this, arguments);
32833
+ };
32834
+ }();
32835
+
32836
+ /**
32837
+ * Generates a digital certificate.
32838
+ * @param {string} [csr] - Certificate Signing Request (CSR).
32839
+ * @returns {Promise<{cert: string, success: boolean}>} Object with the generated certificate and a success indicator.
32840
+ * @throws {ApacuanaAPIError} If the CSR is invalid, if the API response does not contain the certificate, or if the integration type is not supported.
32841
+ * @throws {Error} If certificate generation fails for another reason.
32842
+ */
32843
+ var generateCert = /*#__PURE__*/function () {
32844
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
32845
+ var csr,
32846
+ _getConfig,
32847
+ integrationType,
32848
+ _args3 = arguments;
32849
+ return _regenerator().w(function (_context3) {
32850
+ while (1) switch (_context3.n) {
32851
+ case 0:
32852
+ csr = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : undefined;
32853
+ _getConfig = getConfig(), integrationType = _getConfig.integrationType;
32854
+ helpers.validateCsr(csr);
32855
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
32856
+ _context3.n = 1;
32857
+ break;
32858
+ }
32859
+ return _context3.a(2, generateCertOnBoarding(csr));
32860
+ case 1:
32861
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
32862
+ _context3.n = 2;
32863
+ break;
32864
+ }
32865
+ return _context3.a(2, generateCertOnPremise());
32866
+ case 2:
32867
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
32868
+ case 3:
32869
+ return _context3.a(2);
32870
+ }
32871
+ }, _callee3);
32872
+ }));
32873
+ return function generateCert() {
32874
+ return _ref3.apply(this, arguments);
32875
+ };
32876
+ }();
32877
+
32772
32878
  /**
32773
32879
  * Gets the user's certificate status.
32774
32880
  * @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
@@ -32785,125 +32891,83 @@ var getCertStatus = function getCertStatus() {
32785
32891
  };
32786
32892
 
32787
32893
  var addSignerOnBoarding = /*#__PURE__*/function () {
32788
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(signerData) {
32894
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(signerData) {
32789
32895
  var _t2;
32790
- return _regenerator().w(function (_context7) {
32791
- while (1) switch (_context7.p = _context7.n) {
32896
+ return _regenerator().w(function (_context5) {
32897
+ while (1) switch (_context5.p = _context5.n) {
32792
32898
  case 0:
32793
32899
  helpers.validateOnBoardingSignerData(signerData);
32794
- _context7.p = 1;
32795
- _context7.n = 2;
32900
+ _context5.p = 1;
32901
+ _context5.n = 2;
32796
32902
  return httpRequest("services/api/documents/signing", signerData, "POST");
32797
32903
  case 2:
32798
- return _context7.a(2, {
32904
+ return _context5.a(2, {
32799
32905
  signer: signerData.typedoc + signerData.doc,
32800
32906
  success: true
32801
32907
  });
32802
32908
  case 3:
32803
- _context7.p = 3;
32804
- _t2 = _context7.v;
32909
+ _context5.p = 3;
32910
+ _t2 = _context5.v;
32805
32911
  if (!(_t2 instanceof ApacuanaAPIError)) {
32806
- _context7.n = 4;
32912
+ _context5.n = 4;
32807
32913
  break;
32808
32914
  }
32809
32915
  throw _t2;
32810
32916
  case 4:
32811
32917
  throw new Error("Failed to add signer in On-Boarding: ".concat(_t2.message));
32812
32918
  case 5:
32813
- return _context7.a(2);
32919
+ return _context5.a(2);
32814
32920
  }
32815
- }, _callee7, null, [[1, 3]]);
32921
+ }, _callee5, null, [[1, 3]]);
32816
32922
  }));
32817
- return function addSignerOnBoarding(_x3) {
32818
- return _ref7.apply(this, arguments);
32923
+ return function addSignerOnBoarding(_x2) {
32924
+ return _ref5.apply(this, arguments);
32819
32925
  };
32820
32926
  }();
32821
32927
  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) {
32928
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
32929
+ return _regenerator().w(function (_context6) {
32930
+ while (1) switch (_context6.n) {
32825
32931
  case 0:
32826
32932
  throw new ApacuanaAPIError("Adding signers is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32827
32933
  case 1:
32828
- return _context8.a(2);
32934
+ return _context6.a(2);
32829
32935
  }
32830
- }, _callee8);
32936
+ }, _callee6);
32831
32937
  }));
32832
32938
  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;
32858
- break;
32859
- }
32860
- return _context9.a(2, addSignerOnBoarding(signerData));
32861
- case 2:
32862
- if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
32863
- _context9.n = 3;
32864
- break;
32865
- }
32866
- return _context9.a(2, addSignerOnPremise(signerData));
32867
- case 3:
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);
32939
+ return _ref6.apply(this, arguments);
32876
32940
  };
32877
32941
  }();
32878
32942
  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) {
32943
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
32944
+ return _regenerator().w(function (_context7) {
32945
+ while (1) switch (_context7.n) {
32882
32946
  case 0:
32883
- throw new ApacuanaAPIError("Document retrieval is not supported for integration type: ONBOARDING", 501, "NOT_IMPLEMENTED");
32947
+ throw new ApacuanaAPIError("Document retrieval is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32884
32948
  case 1:
32885
- return _context0.a(2);
32949
+ return _context7.a(2);
32886
32950
  }
32887
- }, _callee0);
32951
+ }, _callee7);
32888
32952
  }));
32889
32953
  return function getDocsOnPremise() {
32890
- return _ref0.apply(this, arguments);
32954
+ return _ref7.apply(this, arguments);
32891
32955
  };
32892
32956
  }();
32893
32957
  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) {
32958
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(data) {
32959
+ var _getConfig, customerId, params, apiUrl, response, _t3;
32960
+ return _regenerator().w(function (_context8) {
32961
+ while (1) switch (_context8.p = _context8.n) {
32898
32962
  case 0:
32899
- _getConfig4 = getConfig(), customerId = _getConfig4.customerId;
32963
+ _getConfig = getConfig(), customerId = _getConfig.customerId;
32900
32964
  if (customerId) {
32901
- _context1.n = 1;
32965
+ _context8.n = 1;
32902
32966
  break;
32903
32967
  }
32904
32968
  throw new ApacuanaAPIError("'customerId' is not configured. Please configure the SDK.", 400, "CONFIGURATION_ERROR");
32905
32969
  case 1:
32906
- _context1.p = 1;
32970
+ _context8.p = 1;
32907
32971
  params = new URLSearchParams({
32908
32972
  page: data.page,
32909
32973
  customerid: customerId,
@@ -32913,40 +32977,82 @@ var getDocsOnBoarding = /*#__PURE__*/function () {
32913
32977
  params.append("status", data.status);
32914
32978
  }
32915
32979
  apiUrl = "services/api/documents/listcustomer?".concat(params.toString());
32916
- _context1.n = 2;
32980
+ _context8.n = 2;
32917
32981
  return httpRequest(apiUrl, {}, "GET");
32918
32982
  case 2:
32919
- response = _context1.v;
32920
- return _context1.a(2, {
32983
+ response = _context8.v;
32984
+ return _context8.a(2, {
32921
32985
  totalRecords: response.numofrecords,
32922
32986
  records: response.records,
32923
32987
  success: true
32924
32988
  });
32925
32989
  case 3:
32926
- _context1.p = 3;
32927
- _t3 = _context1.v;
32990
+ _context8.p = 3;
32991
+ _t3 = _context8.v;
32928
32992
  if (!(_t3.name === "ApacuanaAPIError")) {
32929
- _context1.n = 4;
32993
+ _context8.n = 4;
32930
32994
  break;
32931
32995
  }
32932
32996
  throw _t3;
32933
32997
  case 4:
32934
- throw new ApacuanaAPIError("Failed to get document list (on-premise): ".concat(_t3.message));
32998
+ throw new ApacuanaAPIError("Failed to get document list (on-boarding): ".concat(_t3.message));
32935
32999
  case 5:
33000
+ return _context8.a(2);
33001
+ }
33002
+ }, _callee8, null, [[1, 3]]);
33003
+ }));
33004
+ return function getDocsOnBoarding(_x3) {
33005
+ return _ref8.apply(this, arguments);
33006
+ };
33007
+ }();
33008
+
33009
+ /**
33010
+ * Añade un firmante a un documento.
33011
+ * @param {SignerData} signerData - Los datos del firmante que se va a añadir.
33012
+ * @returns {Promise<AddSignerResponse>} Una promesa que resuelve a un objeto con el resultado de la operación.
33013
+ * @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.
33014
+ */
33015
+ var addSigner = /*#__PURE__*/function () {
33016
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(signerData) {
33017
+ var _getConfig4, integrationType;
33018
+ return _regenerator().w(function (_context1) {
33019
+ while (1) switch (_context1.n) {
33020
+ case 0:
33021
+ if (!(!signerData || _typeof(signerData) !== "object" || Object.keys(signerData).length === 0)) {
33022
+ _context1.n = 1;
33023
+ break;
33024
+ }
33025
+ throw new ApacuanaAPIError("Signer data (signerData) is required and must be a non-empty object.", 400, "INVALID_PARAMETER");
33026
+ case 1:
33027
+ _getConfig4 = getConfig(), integrationType = _getConfig4.integrationType;
33028
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33029
+ _context1.n = 2;
33030
+ break;
33031
+ }
33032
+ return _context1.a(2, addSignerOnBoarding(signerData));
33033
+ case 2:
33034
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33035
+ _context1.n = 3;
33036
+ break;
33037
+ }
33038
+ return _context1.a(2, addSignerOnPremise());
33039
+ case 3:
33040
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
33041
+ case 4:
32936
33042
  return _context1.a(2);
32937
33043
  }
32938
- }, _callee1, null, [[1, 3]]);
33044
+ }, _callee1);
32939
33045
  }));
32940
- return function getDocsOnBoarding(_x5) {
33046
+ return function addSigner(_x5) {
32941
33047
  return _ref1.apply(this, arguments);
32942
33048
  };
32943
33049
  }();
32944
33050
 
32945
33051
  /**
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.
33052
+ * Obtiene una lista de documentos basada en los filtros especificados.
33053
+ * @param {GetDocsParams} data - Objeto con parámetros de paginación y filtros.
33054
+ * @returns {Promise<GetDocsResponse>} Una promesa que resuelve a un objeto con la lista de documentos.
33055
+ * @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.
32950
33056
  */
32951
33057
  var getDocs = /*#__PURE__*/function () {
32952
33058
  var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(data) {
@@ -33052,7 +33158,8 @@ var apacuana = {
33052
33158
  getCertStatus: getCertStatus,
33053
33159
  getCustomer: getCustomer,
33054
33160
  addSigner: addSigner,
33055
- getDocs: getDocs
33161
+ getDocs: getDocs,
33162
+ generateCert: generateCert
33056
33163
  };
33057
33164
 
33058
33165
  export { apacuana as default };