apacuana-sdk-core 0.6.2 → 0.7.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 +105 -288
  2. package/coverage/clover.xml +142 -136
  3. package/coverage/coverage-final.json +5 -5
  4. package/coverage/lcov-report/index.html +34 -34
  5. package/coverage/lcov-report/src/api/certs.js.html +34 -7
  6. package/coverage/lcov-report/src/api/index.html +19 -19
  7. package/coverage/lcov-report/src/api/revocations.js.html +135 -30
  8. package/coverage/lcov-report/src/api/signatures.js.html +76 -4
  9. package/coverage/lcov-report/src/api/users.js.html +1 -1
  10. package/coverage/lcov-report/src/config/index.html +13 -13
  11. package/coverage/lcov-report/src/config/index.js.html +69 -18
  12. package/coverage/lcov-report/src/errors/index.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.js.html +1 -1
  14. package/coverage/lcov-report/src/index.html +15 -15
  15. package/coverage/lcov-report/src/index.js.html +14 -68
  16. package/coverage/lcov-report/src/utils/constant.js.html +1 -1
  17. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  18. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  19. package/coverage/lcov-report/src/utils/index.html +1 -1
  20. package/coverage/lcov.info +224 -216
  21. package/dist/api/certs.d.ts +11 -1
  22. package/dist/api/revocations.d.ts +32 -12
  23. package/dist/api/signatures.d.ts +37 -5
  24. package/dist/config/index.d.ts +13 -2
  25. package/dist/index.d.ts +4 -1
  26. package/dist/index.js +160 -75
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +160 -75
  29. package/dist/index.mjs.map +1 -1
  30. package/package.json +1 -1
  31. package/src/api/certs.js +12 -3
  32. package/src/api/revocations.js +55 -20
  33. package/src/api/signatures.js +25 -1
  34. package/src/config/index.js +25 -8
  35. package/src/index.js +4 -22
package/dist/index.mjs CHANGED
@@ -287,7 +287,19 @@ var INTEGRATION_TYPE = {
287
287
  ONPREMISE: "ONPREMISE"
288
288
  };
289
289
 
290
- var config = {
290
+ /**
291
+ * @typedef {object} SDKConfig
292
+ * @property {string} apiUrl
293
+ * @property {string} secretKey
294
+ * @property {string} apiKey
295
+ * @property {string} verificationId
296
+ * @property {string} customerId
297
+ * @property {string} integrationType
298
+ * @property {object} [userData]
299
+ * @property {string} [token]
300
+ */
301
+
302
+ var defaultConfig = {
291
303
  apiUrl: "",
292
304
  secretKey: "",
293
305
  apiKey: "",
@@ -297,6 +309,9 @@ var config = {
297
309
  userData: undefined,
298
310
  token: undefined
299
311
  };
312
+
313
+ /** @type {SDKConfig} */
314
+ var config = _objectSpread2({}, defaultConfig);
300
315
  var setConfig = function setConfig(newConfig) {
301
316
  var apiUrl = newConfig.apiUrl,
302
317
  secretKey = newConfig.secretKey,
@@ -309,17 +324,18 @@ var setConfig = function setConfig(newConfig) {
309
324
 
310
325
  // Nueva validación para el valor de integrationType
311
326
  if (!Object.values(INTEGRATION_TYPE).includes(integrationType)) {
312
- throw new Error("Apacuana SDK: El valor de integrationType ('".concat(integrationType, "') no es v\xE1lido. ") + "Valores permitidos: ".concat(Object.values(INTEGRATION_TYPE).join(', ')));
327
+ throw new Error("Apacuana SDK: El valor de integrationType ('".concat(integrationType, "') no es v\xE1lido. ") + "Valores permitidos: ".concat(Object.values(INTEGRATION_TYPE).join(", ")));
313
328
  }
314
329
  config = _objectSpread2(_objectSpread2({}, config), newConfig);
315
330
  // eslint-disable-next-line no-console
316
- console.log("[Config] SDK Configuración actualizada (desde config):", _objectSpread2(_objectSpread2({}, config), {}, {
317
- secretKey: "********"
318
- }));
319
331
  };
320
332
  var getConfig = function getConfig() {
321
333
  return _objectSpread2({}, config);
322
334
  };
335
+ var cleanConfig = function cleanConfig() {
336
+ config = _objectSpread2({}, defaultConfig);
337
+ console.log("Apacuana SDK: Configuración limpiada.");
338
+ };
323
339
 
324
340
  // src/errors/index.js
325
341
 
@@ -582,54 +598,107 @@ var getCustomer = /*#__PURE__*/function () {
582
598
  * @param {string} reasonCode - Código o descripción del motivo de la revocación.
583
599
  * @returns {Promise<RequestRevocationResponse>} Objeto con el estado de la solicitud de revocación.
584
600
  */
601
+ /**
602
+ * @typedef {object} RevocationResponse
603
+ * @property {boolean} success - Indicates if the revocation request was successful.
604
+ * @property {string} [message] - A message providing details about the outcome.
605
+ */
606
+
607
+ /**
608
+ * @typedef {object} RevocationReason
609
+ * @property {string} code - The code for the revocation reason.
610
+ * @property {string} description - The description of the revocation reason.
611
+ */
612
+
613
+ /**
614
+ * @typedef {object} RevocationReasonsResponse
615
+ * @property {boolean} success - Indicates if the request was successful.
616
+ * @property {RevocationReason[]} reasons - A list of revocation reasons.
617
+ */
618
+
619
+ /**
620
+ * Requests the revocation of a certificate.
621
+ * @param {number} reasonCode - Código o descripción del motivo de la revocación.
622
+ * @returns {Promise<RevocationResponse>} An object indicating the success of the request.
623
+ * @throws {ApacuanaAPIError} If the revocation request fails.
624
+ */
585
625
  var requestRevocation = /*#__PURE__*/function () {
586
626
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(reasonCode) {
587
627
  var response, _t;
588
628
  return _regenerator().w(function (_context) {
589
629
  while (1) switch (_context.p = _context.n) {
590
630
  case 0:
591
- console.log("-> Función 'requestRevocation' ejecutada.");
592
- console.log("Parámetros recibidos para solicitud de revocación:", {
593
- reasonCode: reasonCode
594
- });
595
631
  if (reasonCode) {
596
632
  _context.n = 1;
597
633
  break;
598
634
  }
599
- throw new Error("ID de certificado y motivo son requeridos para requestRevocation.");
635
+ throw new Error("Código de motivo es requerido para requestRevocation.");
600
636
  case 1:
601
637
  _context.p = 1;
602
638
  _context.n = 2;
603
- return httpRequest("users/api/customers/requestcert", {
639
+ return httpRequest("services/api/onboardingclient/requestcert", {
604
640
  reason: reasonCode
605
641
  }, "POST");
606
642
  case 2:
607
643
  response = _context.v;
608
- console.log("Respuesta del servidor", response);
609
- if (response.success) {
610
- _context.n = 3;
611
- break;
612
- }
613
- throw new ApacuanaAPIError(response.message || "Error desconocido al solicitar revocación.");
644
+ return _context.a(2, response);
614
645
  case 3:
615
- return _context.a(2, {
616
- revocationStatus: response.status || "pending",
617
- requestId: response.id
618
- });
619
- case 4:
620
- _context.p = 4;
646
+ _context.p = 3;
621
647
  _t = _context.v;
622
648
  throw new Error("Fallo en la solicitud de revocaci\xF3n: ".concat(_t.message));
623
- case 5:
649
+ case 4:
624
650
  return _context.a(2);
625
651
  }
626
- }, _callee, null, [[1, 4]]);
652
+ }, _callee, null, [[1, 3]]);
627
653
  }));
628
654
  return function requestRevocation(_x) {
629
655
  return _ref.apply(this, arguments);
630
656
  };
631
657
  }();
632
658
 
659
+ /**
660
+ * Retrieves the available reasons for certificate revocation.
661
+ * @returns {Promise<RevocationReasonsResponse>} An object containing the list of revocation reasons.
662
+ * @throws {ApacuanaAPIError} If fetching the reasons fails.
663
+ */
664
+ var getRevocationReasons = /*#__PURE__*/function () {
665
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
666
+ var response, _t2;
667
+ return _regenerator().w(function (_context2) {
668
+ while (1) switch (_context2.p = _context2.n) {
669
+ case 0:
670
+ _context2.p = 0;
671
+ _context2.n = 1;
672
+ return httpRequest("config/api/revocation/reasonsonboarding", {}, "GET");
673
+ case 1:
674
+ response = _context2.v;
675
+ if (response.records) {
676
+ _context2.n = 2;
677
+ break;
678
+ }
679
+ throw new ApacuanaAPIError("Failed to fetch revocation reasons.");
680
+ case 2:
681
+ return _context2.a(2, response.records);
682
+ case 3:
683
+ _context2.p = 3;
684
+ _t2 = _context2.v;
685
+ if (!(_t2 instanceof ApacuanaAPIError)) {
686
+ _context2.n = 4;
687
+ break;
688
+ }
689
+ throw _t2;
690
+ case 4:
691
+ throw new Error("Failed to get revocation reasons. Please try again later.");
692
+ case 5:
693
+ return _context2.a(2);
694
+ }
695
+ }, _callee2, null, [[0, 3]]);
696
+ }));
697
+ return function getRevocationReasons() {
698
+ return _ref2.apply(this, arguments);
699
+ };
700
+ }();
701
+
633
702
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
634
703
 
635
704
  function getDefaultExportFromCjs (x) {
@@ -32867,6 +32936,7 @@ var helpers = {
32867
32936
  /**
32868
32937
  * @typedef {object} GenerateCertResponse
32869
32938
  * @property {string} cert - El certificado generado en formato string.
32939
+ * @property {string} certifiedid - El ID del certificado generado.
32870
32940
  * @property {boolean} success - Indica si la operación fue exitosa.
32871
32941
  */
32872
32942
 
@@ -32876,51 +32946,53 @@ var helpers = {
32876
32946
  * @property {boolean} success - Indica si la operación fue exitosa.
32877
32947
  */
32878
32948
 
32949
+ /**
32950
+ * @typedef {object} EncryptedCSRObject
32951
+ * @property {string} csr - The encrypted Certificate Signing Request.
32952
+ */
32953
+
32954
+ /**
32955
+ * @param {EncryptedCSRObject} encryptedCSR
32956
+ */
32879
32957
  var generateCertOnBoarding = /*#__PURE__*/function () {
32880
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
32881
- var encryptedCSR,
32882
- response,
32883
- cert,
32884
- certifiedid,
32885
- _args = arguments,
32886
- _t;
32958
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(encryptedCSR) {
32959
+ var response, cert, certifiedid, _t;
32887
32960
  return _regenerator().w(function (_context) {
32888
32961
  while (1) switch (_context.p = _context.n) {
32889
32962
  case 0:
32890
- encryptedCSR = _args.length > 0 && _args[0] !== undefined ? _args[0] : undefined;
32891
- _context.p = 1;
32892
- _context.n = 2;
32963
+ _context.p = 0;
32964
+ _context.n = 1;
32893
32965
  return httpRequest("services/api/register/certificate", encryptedCSR, "POST");
32894
- case 2:
32966
+ case 1:
32895
32967
  response = _context.v;
32896
32968
  cert = response.cert, certifiedid = response.certifiedid;
32897
32969
  if (!(!cert || !certifiedid)) {
32898
- _context.n = 3;
32970
+ _context.n = 2;
32899
32971
  break;
32900
32972
  }
32901
32973
  throw new ApacuanaAPIError("The API response does not contain the certificate.", response.status, "INVALID_API_RESPONSE");
32902
- case 3:
32974
+ case 2:
32903
32975
  return _context.a(2, {
32904
32976
  cert: cert,
32905
32977
  certifiedid: certifiedid,
32906
32978
  success: true
32907
32979
  });
32908
- case 4:
32909
- _context.p = 4;
32980
+ case 3:
32981
+ _context.p = 3;
32910
32982
  _t = _context.v;
32911
32983
  if (!(_t instanceof ApacuanaAPIError)) {
32912
- _context.n = 5;
32984
+ _context.n = 4;
32913
32985
  break;
32914
32986
  }
32915
32987
  throw _t;
32916
- case 5:
32988
+ case 4:
32917
32989
  throw new Error("Certificate generation failed: ".concat(_t.message));
32918
- case 6:
32990
+ case 5:
32919
32991
  return _context.a(2);
32920
32992
  }
32921
- }, _callee, null, [[1, 4]]);
32993
+ }, _callee, null, [[0, 3]]);
32922
32994
  }));
32923
- return function generateCertOnBoarding() {
32995
+ return function generateCertOnBoarding(_x) {
32924
32996
  return _ref.apply(this, arguments);
32925
32997
  };
32926
32998
  }();
@@ -32942,21 +33014,17 @@ var generateCertOnPremise = /*#__PURE__*/function () {
32942
33014
 
32943
33015
  /**
32944
33016
  * Generates a digital certificate.
32945
- * @param {string} [csr] - Certificate Signing Request (CSR).
33017
+ * @param {EncryptedCSRObject} encryptedCSR - Certificate Signing Request (CSR) object.
32946
33018
  * @returns {Promise<GenerateCertResponse>} Object with the generated certificate and a success indicator.
32947
33019
  * @throws {ApacuanaAPIError} If the CSR is invalid, if the API response does not contain the certificate, or if the integration type is not supported.
32948
33020
  * @throws {Error} If certificate generation fails for another reason.
32949
33021
  */
32950
33022
  var generateCert = /*#__PURE__*/function () {
32951
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
32952
- var encryptedCSR,
32953
- _getConfig,
32954
- integrationType,
32955
- _args3 = arguments;
33023
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(encryptedCSR) {
33024
+ var _getConfig, integrationType;
32956
33025
  return _regenerator().w(function (_context3) {
32957
33026
  while (1) switch (_context3.n) {
32958
33027
  case 0:
32959
- encryptedCSR = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : undefined;
32960
33028
  _getConfig = getConfig(), integrationType = _getConfig.integrationType;
32961
33029
  helpers.validateCsr(encryptedCSR);
32962
33030
  if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
@@ -32977,7 +33045,7 @@ var generateCert = /*#__PURE__*/function () {
32977
33045
  }
32978
33046
  }, _callee3);
32979
33047
  }));
32980
- return function generateCert() {
33048
+ return function generateCert(_x2) {
32981
33049
  return _ref3.apply(this, arguments);
32982
33050
  };
32983
33051
  }();
@@ -33013,7 +33081,6 @@ var getCertStatus = function getCertStatus() {
33013
33081
  * Define la estructura de datos para añadir un firmante.
33014
33082
  * @typedef {object} SignerData
33015
33083
  * @property {string} docId - Identificador único del documento.
33016
- * @property {Signer} signer - Objeto con la información del firmante.
33017
33084
  */
33018
33085
 
33019
33086
  /**
@@ -33384,6 +33451,31 @@ var getDigest = /*#__PURE__*/function () {
33384
33451
  * @returns {Promise<AddSignerResponse>} Una promesa que resuelve a un objeto con el resultado de la operación.
33385
33452
  * @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.
33386
33453
  */
33454
+ /**
33455
+ * @typedef {object} SignaturePosition
33456
+ * @property {number} page - The page number for the signature.
33457
+ * @property {number} x - The x-coordinate for the signature's position (from 0 to 1).
33458
+ * @property {number} y - The y-coordinate for the signature's position (from 0 to 1).
33459
+ */
33460
+
33461
+ /**
33462
+ * @typedef {object} OnboardingSignerData
33463
+ * @property {string} name - The name of the document.
33464
+ * @property {string} reference - An external reference for the document.
33465
+ * @property {string} typedoc - The type of document of the signer (e.g., "V", "E", "J").
33466
+ * @property {string} doc - The document number of the signer.
33467
+ * @property {SignaturePosition[]} signature - An array of signature positions.
33468
+ */
33469
+
33470
+ /**
33471
+ * Adds a new signer to the signature process.
33472
+ * This function acts as a dispatcher, delegating to the appropriate implementation
33473
+ * based on the configured integration type.
33474
+ *
33475
+ * @param {OnboardingSignerData | object} signerData - The signer's data. The structure depends on the integration type.
33476
+ * @returns {Promise<object>} The result from the API.
33477
+ * @throws {ApacuanaAPIError} If signerData is invalid or if the integration type is not supported.
33478
+ */
33387
33479
  var addSigner = /*#__PURE__*/function () {
33388
33480
  var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(signerData) {
33389
33481
  var _getConfig4, integrationType;
@@ -33476,55 +33568,47 @@ var apacuana = {
33476
33568
  return _regenerator().w(function (_context) {
33477
33569
  while (1) switch (_context.p = _context.n) {
33478
33570
  case 0:
33479
- // eslint-disable-next-line no-console
33480
- console.log("-> apacuana-sdk: Iniciando configuración y validando usuario...");
33481
- _context.p = 1;
33482
- // 1. Guardar la configuración inicial
33571
+ _context.p = 0;
33483
33572
  setConfig(config);
33484
-
33485
- // 2. Inicializar el cliente HTTP con la configuración guardada
33486
33573
  initHttpClient();
33487
-
33488
- // 3. Opcional: Validar que la configuración se guardó correctamente
33489
33574
  currentConfig = getConfig();
33490
33575
  if (currentConfig.customerId) {
33491
- _context.n = 2;
33576
+ _context.n = 1;
33492
33577
  break;
33493
33578
  }
33494
33579
  throw new Error("Apacuana SDK: La configuración de CustomerId no se ha guardado" + " correctamente.");
33495
- case 2:
33496
- _context.n = 3;
33580
+ case 1:
33581
+ _context.n = 2;
33497
33582
  return getCustomer();
33498
- case 3:
33583
+ case 2:
33499
33584
  _yield$getCustomer = _context.v;
33500
33585
  token = _yield$getCustomer.token;
33501
33586
  userData = _yield$getCustomer.userData;
33502
- // Opcional: Guardar los detalles del usuario en la configuración
33503
- // para acceso futuro si fuera necesario
33504
33587
  setConfig(_objectSpread2(_objectSpread2({}, currentConfig), {}, {
33505
33588
  token: token,
33506
33589
  userData: userData
33507
33590
  }));
33508
33591
  setAuthToken(token);
33509
- // eslint-disable-next-line no-console
33510
- console.log("-> apacuana-sdk: Inicialización completa. Usuario validado:", token);
33511
33592
  return _context.a(2, true);
33512
- case 4:
33513
- _context.p = 4;
33593
+ case 3:
33594
+ _context.p = 3;
33514
33595
  _t = _context.v;
33515
33596
  // eslint-disable-next-line no-console
33516
33597
  console.error("Error durante la inicialización del SDK:", _t);
33517
33598
  throw _t;
33518
- case 5:
33599
+ case 4:
33519
33600
  return _context.a(2);
33520
33601
  }
33521
- }, _callee, null, [[1, 4]]);
33602
+ }, _callee, null, [[0, 3]]);
33522
33603
  }));
33523
33604
  function init(_x) {
33524
33605
  return _init.apply(this, arguments);
33525
33606
  }
33526
33607
  return init;
33527
33608
  }(),
33609
+ close: function close() {
33610
+ return cleanConfig();
33611
+ },
33528
33612
  getConfig: getConfig,
33529
33613
  requestRevocation: requestRevocation,
33530
33614
  getCertStatus: getCertStatus,
@@ -33533,7 +33617,8 @@ var apacuana = {
33533
33617
  getDocs: getDocs,
33534
33618
  generateCert: generateCert,
33535
33619
  signDocument: signDocument,
33536
- getDigest: getDigest
33620
+ getDigest: getDigest,
33621
+ getRevocationReasons: getRevocationReasons
33537
33622
  };
33538
33623
 
33539
33624
  export { apacuana as default };