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