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