apacuana-sdk-core 0.1.0 → 0.2.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 +117 -46
  2. package/coverage/clover.xml +205 -91
  3. package/coverage/coverage-final.json +9 -6
  4. package/coverage/lcov-report/index.html +48 -33
  5. package/coverage/lcov-report/src/api/certs.js.html +74 -83
  6. package/coverage/lcov-report/src/api/index.html +36 -21
  7. package/coverage/lcov-report/src/api/revocations.js.html +1 -1
  8. package/coverage/lcov-report/src/api/signatures.js.html +528 -81
  9. package/coverage/lcov-report/src/api/users.js.html +5 -2
  10. package/coverage/lcov-report/src/config/index.html +21 -21
  11. package/coverage/lcov-report/src/config/index.js.html +65 -32
  12. package/coverage/lcov-report/src/errors/index.html +5 -5
  13. package/coverage/lcov-report/src/errors/index.js.html +13 -10
  14. package/coverage/lcov-report/src/index.html +1 -1
  15. package/coverage/lcov-report/src/index.js.html +13 -4
  16. package/coverage/lcov-report/src/utils/constant.js.html +4 -4
  17. package/coverage/lcov-report/src/utils/helpers.js.html +268 -145
  18. package/coverage/lcov-report/src/utils/httpClient.js.html +646 -0
  19. package/coverage/lcov-report/src/utils/index.html +32 -17
  20. package/coverage/lcov.info +429 -167
  21. package/dist/index.js +390 -150
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +390 -150
  24. package/dist/index.mjs.map +1 -1
  25. package/package.json +1 -1
  26. package/src/api/certs.js +27 -30
  27. package/src/api/signatures.js +205 -50
  28. package/src/api/users.js +1 -0
  29. package/src/errors/index.js +1 -0
  30. package/src/index.js +4 -1
  31. package/src/utils/helpers.js +140 -99
  32. package/tests/api/certs.test.js +126 -4
  33. package/tests/api/signatures.test.js +207 -4
  34. package/tests/api/users.test.js +1 -0
  35. package/src/auth/index.js +0 -24
package/dist/index.js CHANGED
@@ -242,6 +242,15 @@ function _toPropertyKey(t) {
242
242
  var i = _toPrimitive(t, "string");
243
243
  return "symbol" == typeof i ? i : i + "";
244
244
  }
245
+ function _typeof(o) {
246
+ "@babel/helpers - typeof";
247
+
248
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
249
+ return typeof o;
250
+ } : function (o) {
251
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
252
+ }, _typeof(o);
253
+ }
245
254
  function _wrapNativeSuper(t) {
246
255
  var r = "function" == typeof Map ? new Map() : void 0;
247
256
  return _wrapNativeSuper = function (t) {
@@ -329,6 +338,7 @@ var ApacuanaAPIError = /*#__PURE__*/function (_Error) {
329
338
  _this.name = "ApacuanaAPIError";
330
339
  _this.statusCode = statusCode;
331
340
  _this.errorCode = errorCode;
341
+ _this.success = false; // Añadir el atributo success con valor false
332
342
 
333
343
  // Mantener el stack trace correcto
334
344
  if (Error.captureStackTrace) {
@@ -559,7 +569,8 @@ var getCustomer = /*#__PURE__*/function () {
559
569
  case 3:
560
570
  return _context.a(2, {
561
571
  token: response.sessionid,
562
- userData: response.entry
572
+ userData: response.entry,
573
+ success: true
563
574
  });
564
575
  case 4:
565
576
  _context.p = 4;
@@ -639,6 +650,10 @@ var requestRevocation = /*#__PURE__*/function () {
639
650
 
640
651
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
641
652
 
653
+ function getDefaultExportFromCjs (x) {
654
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
655
+ }
656
+
642
657
  var cryptoJs = {exports: {}};
643
658
 
644
659
  function commonjsRequire(path) {
@@ -8063,6 +8078,9 @@ function requireBlowfish () {
8063
8078
  }));
8064
8079
  } (cryptoJs));
8065
8080
 
8081
+ var cryptoJsExports = cryptoJs.exports;
8082
+ var CryptoJS = /*@__PURE__*/getDefaultExportFromCjs(cryptoJsExports);
8083
+
8066
8084
  /*!
8067
8085
  * MIT License
8068
8086
  *
@@ -32649,6 +32667,7 @@ function initCryptoEngine() {
32649
32667
 
32650
32668
  initCryptoEngine();
32651
32669
 
32670
+ var KEY_HEX = "dRgUkXp2s5v8y/B?";
32652
32671
  var getCertificateStatus = function getCertificateStatus(userData, certificateInDevice) {
32653
32672
  var _userData$verificatio, _userData$requestscer, _userData$requestscer2;
32654
32673
  if (!userData) {
@@ -32666,189 +32685,407 @@ var getCertificateStatus = function getCertificateStatus(userData, certificateIn
32666
32685
  if (userData !== null && userData !== void 0 && userData.certificationId) return STATUS_CERTIFICATE.current;
32667
32686
  return STATUS_CERTIFICATE.revoque;
32668
32687
  };
32669
- var generateKeyPair = /*#__PURE__*/function () {
32670
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
32671
- var signAlg,
32672
- hashAlg,
32673
- crypto,
32674
- keyPair,
32675
- _args = arguments,
32676
- _t;
32688
+
32689
+ // Función para convertir ArrayBuffer a Base64
32690
+ var arrayBufferToBase64 = function arrayBufferToBase64(buffer) {
32691
+ var binary = String.fromCharCode.apply(null, new Uint8Array(buffer));
32692
+ return window.btoa(binary);
32693
+ };
32694
+ function exportPrivateKey(_x) {
32695
+ return _exportPrivateKey.apply(this, arguments);
32696
+ }
32697
+ function _exportPrivateKey() {
32698
+ _exportPrivateKey = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(key) {
32699
+ var crypto, exported, exportablePrivateKey;
32700
+ return _regenerator().w(function (_context) {
32701
+ while (1) switch (_context.n) {
32702
+ case 0:
32703
+ crypto = getCrypto();
32704
+ _context.n = 1;
32705
+ return crypto.exportKey("pkcs8", key);
32706
+ case 1:
32707
+ exported = _context.v;
32708
+ exportablePrivateKey = new Uint8Array(exported);
32709
+ return _context.a(2, arrayBufferToBase64(exportablePrivateKey));
32710
+ }
32711
+ }, _callee);
32712
+ }));
32713
+ return _exportPrivateKey.apply(this, arguments);
32714
+ }
32715
+ var encryptedCsr = function encryptedCsr(csr) {
32716
+ var encryptKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : KEY_HEX;
32717
+ var body = {
32718
+ csr: CryptoJS.AES.encrypt(csr, encryptKey, {
32719
+ mode: CryptoJS.mode.ECB,
32720
+ padding: CryptoJS.pad.Pkcs7
32721
+ }).toString()
32722
+ };
32723
+ return body;
32724
+ };
32725
+ var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerData) {
32726
+ if (!signerData.name || typeof signerData.name !== "string") {
32727
+ throw new ApacuanaAPIError('El campo "name" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32728
+ }
32729
+ if (!signerData.reference || typeof signerData.reference !== "string") {
32730
+ throw new ApacuanaAPIError('El campo "reference" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32731
+ }
32732
+ var validDocTypes = ["V", "P", "E"];
32733
+ if (!signerData.typedoc || !validDocTypes.includes(signerData.typedoc)) {
32734
+ throw new ApacuanaAPIError('El campo "typedoc" es requerido y debe ser uno de los siguientes valores: V, P, E.', 400, "INVALID_PARAMETER_FORMAT");
32735
+ }
32736
+ if (!signerData.doc || typeof signerData.doc !== "string") {
32737
+ throw new ApacuanaAPIError('El campo "doc" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32738
+ }
32739
+ if (!Array.isArray(signerData.signature) || signerData.signature.length === 0) {
32740
+ throw new ApacuanaAPIError('El campo "signature" es requerido y debe ser un array no vacío.', 400, "INVALID_PARAMETER_FORMAT");
32741
+ }
32742
+ signerData.signature.forEach(function (sig, index) {
32743
+ if (!Number.isInteger(sig.page) || sig.page < 1) {
32744
+ throw new ApacuanaAPIError("La p\xE1gina de la firma ".concat(index + 1, " debe ser un n\xFAmero entero positivo."), 400, "INVALID_PARAMETER_FORMAT");
32745
+ }
32746
+ if (typeof sig.x !== "number" || sig.x < 0 || sig.x > 1) {
32747
+ throw new ApacuanaAPIError("La coordenada X de la firma ".concat(index + 1, " debe ser un n\xFAmero entre 0 y 1."), 400, "INVALID_PARAMETER_FORMAT");
32748
+ }
32749
+ if (typeof sig.y !== "number" || sig.y < 0 || sig.y > 1) {
32750
+ throw new ApacuanaAPIError("La coordenada Y de la firma ".concat(index + 1, " debe ser un n\xFAmero entre 0 y 1."), 400, "INVALID_PARAMETER_FORMAT");
32751
+ }
32752
+ });
32753
+ };
32754
+ var validateCsr = function validateCsr(csr) {
32755
+ var base64Regex = /^[A-Za-z0-9+/=]+$/;
32756
+ if (!csr) {
32757
+ throw new ApacuanaAPIError("La solicitud de firma de certificado (CSR) es requerida.", 400, "INVALID_PARAMETER");
32758
+ }
32759
+ if (typeof csr !== "string" || csr.trim() === "") {
32760
+ throw new ApacuanaAPIError("El CSR debe ser una cadena de texto válida y no puede estar vacía.", 400, "INVALID_PARAMETER_FORMAT");
32761
+ }
32762
+ if (!base64Regex.test(csr)) {
32763
+ throw new ApacuanaAPIError("El CSR debe estar codificado en formato base64 válido.", 400, "INVALID_PARAMETER_FORMAT");
32764
+ }
32765
+ };
32766
+ var validateGetDocsData = function validateGetDocsData(data) {
32767
+ if (!data || typeof data.page === "undefined" || typeof data.size === "undefined") {
32768
+ throw new ApacuanaAPIError("Los parámetros 'page' y 'size' son requeridos.", 400, "INVALID_PARAMETER");
32769
+ }
32770
+ if (typeof data.status !== "undefined" && ![-1, 0, 1, 2].includes(data.status)) {
32771
+ throw new ApacuanaAPIError("El parámetro 'status' no es válido. Los valores permitidos son: -1, 0, 1, 2.", 400, "INVALID_PARAMETER");
32772
+ }
32773
+ };
32774
+ var helpers = {
32775
+ getCertificateStatus: getCertificateStatus,
32776
+ exportPrivateKey: exportPrivateKey,
32777
+ arrayBufferToBase64: arrayBufferToBase64,
32778
+ encryptedCsr: encryptedCsr,
32779
+ validateOnBoardingSignerData: validateOnBoardingSignerData,
32780
+ validateCsr: validateCsr,
32781
+ validateGetDocsData: validateGetDocsData
32782
+ };
32783
+
32784
+ var getCertStatus = function getCertStatus() {
32785
+ var isCertificateInDevice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
32786
+ var config = getConfig();
32787
+ var status = helpers.getCertificateStatus(config.userData, isCertificateInDevice);
32788
+ return {
32789
+ status: status,
32790
+ success: true
32791
+ };
32792
+ };
32793
+
32794
+ /*
32795
+ const signDocumentOnBoarding = async (documentData, signatureData) => {
32796
+ try {
32797
+ const response = await httpRequest(
32798
+ "/docs/sign",
32799
+ { documentData, signatureData },
32800
+ "POST"
32801
+ );
32802
+ if (!response.success) {
32803
+ throw new ApacuanaAPIError(
32804
+ response.message || "Error desconocido al firmar documento."
32805
+ );
32806
+ }
32807
+ return { signedDocId: response.id, status: response.message };
32808
+ } catch (error) {
32809
+ if (error.name === "ApacuanaAPIError") {
32810
+ throw error;
32811
+ }
32812
+ throw new ApacuanaAPIError(
32813
+ `Fallo en la firma del documento (on-boarding): ${error.message}`
32814
+ );
32815
+ }
32816
+ };
32817
+
32818
+ const signDocumentOnPremise = async (signature, cert, privateKey) => {
32819
+ helpers.validateSignOnPremiseData({ signature, cert, privateKey });
32820
+ try {
32821
+ const digestBody = {
32822
+ publickey: cert,
32823
+ };
32824
+
32825
+ const digestResponse = await httpRequest(
32826
+ `services/api/documents/getdigest/${signature.id}`,
32827
+ digestBody,
32828
+ "POST"
32829
+ );
32830
+
32831
+ const digest = digestResponse.data?.digest || digestResponse.digest;
32832
+ if (!digest) {
32833
+ throw new ApacuanaAPIError(
32834
+ "La generación de firma ha fallado: no se pudo obtener el digest del documento."
32835
+ );
32836
+ }
32837
+
32838
+ const signedDigest = await helpers.signDigest(digest, privateKey);
32839
+
32840
+ const signBody = {
32841
+ positions: JSON.stringify(
32842
+ signature.positions.map((p) => ({
32843
+ x: p.x,
32844
+ y: p.y,
32845
+ page: p.page,
32846
+ status: 1,
32847
+ }))
32848
+ ),
32849
+ publickey: cert,
32850
+ signeddigest: signedDigest,
32851
+ };
32852
+
32853
+ const signResponse = await httpRequest(
32854
+ `services/api/documents/sign/${signature.id}`,
32855
+ signBody,
32856
+ "PUT"
32857
+ );
32858
+
32859
+ return signResponse;
32860
+ } catch (error) {
32861
+ if (error.name === "ApacuanaAPIError") {
32862
+ throw error;
32863
+ }
32864
+ throw new ApacuanaAPIError(
32865
+ `Fallo en la firma del documento (on-premise): ${error.message}`
32866
+ );
32867
+ }
32868
+ };
32869
+ */
32870
+
32871
+ /**
32872
+ * Firma un documento PDF con un certificado digital.
32873
+ * @param {object} data - Datos para la firma. Para 'on-boarding', debe contener {documentData, signatureData}. Para 'on-premise', debe contener {signature, cert, privateKey}.
32874
+ * @returns {Promise<object>} Objeto con el resultado de la firma.
32875
+ */
32876
+ /*
32877
+ export const signDocument = async (signData) => {
32878
+ if (
32879
+ !signData ||
32880
+ typeof signData !== "object" ||
32881
+ Object.keys(signData).length === 0
32882
+ ) {
32883
+ throw new ApacuanaAPIError(
32884
+ "El parámetro 'data' es requerido y debe ser un objeto no vacío.",
32885
+ 400,
32886
+ "INVALID_PARAMETER"
32887
+ );
32888
+ }
32889
+
32890
+ const { integrationType } = getConfig();
32891
+
32892
+ if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
32893
+ return signDocumentOnBoarding(signData);
32894
+ }
32895
+
32896
+ if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
32897
+ return signDocumentOnPremise(signData);
32898
+ }
32899
+
32900
+ throw new ApacuanaAPIError(
32901
+ `Tipo de integración no soportado: ${integrationType}`,
32902
+ 400,
32903
+ "UNSUPPORTED_INTEGRATION_TYPE"
32904
+ );
32905
+ };
32906
+ */
32907
+
32908
+ var addSignerOnBoarding = /*#__PURE__*/function () {
32909
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signerData) {
32910
+ var _t;
32677
32911
  return _regenerator().w(function (_context) {
32678
32912
  while (1) switch (_context.p = _context.n) {
32679
32913
  case 0:
32680
- signAlg = _args.length > 0 && _args[0] !== undefined ? _args[0] : "RSASSA-PKCS1-v1_5";
32681
- hashAlg = _args.length > 1 && _args[1] !== undefined ? _args[1] : "SHA-256";
32914
+ helpers.validateOnBoardingSignerData(signerData);
32682
32915
  _context.p = 1;
32683
- crypto = getCrypto();
32684
- if (crypto) {
32685
- _context.n = 2;
32686
- break;
32687
- }
32688
- throw new Error("API criptográfica no disponible a través de pkijs.");
32916
+ _context.n = 2;
32917
+ return httpRequest("services/api/documents/signing", signerData, "POST");
32689
32918
  case 2:
32690
- _context.n = 3;
32691
- return crypto.generateKey({
32692
- name: signAlg,
32693
- modulusLength: 2048,
32694
- publicExponent: new Uint8Array([1, 0, 1]),
32695
- hash: {
32696
- name: hashAlg
32697
- }
32698
- }, true, ["sign", "verify"]);
32919
+ return _context.a(2, {
32920
+ signer: signerData.typedoc + signerData.doc,
32921
+ success: true
32922
+ });
32699
32923
  case 3:
32700
- keyPair = _context.v;
32701
- return _context.a(2, keyPair);
32702
- case 4:
32703
- _context.p = 4;
32924
+ _context.p = 3;
32704
32925
  _t = _context.v;
32705
- console.error("Error durante la generación del par de claves:", _t);
32706
- throw new ApacuanaAPIError("Fallo en la generaci\xF3n del par de claves: ".concat(_t.message), 0, "KEY_PAIR_GENERATION_ERROR");
32926
+ if (!(_t instanceof ApacuanaAPIError)) {
32927
+ _context.n = 4;
32928
+ break;
32929
+ }
32930
+ throw _t;
32931
+ case 4:
32932
+ throw new Error("Fallo al agregar firmante en On-Boarding: ".concat(_t.message));
32707
32933
  case 5:
32708
32934
  return _context.a(2);
32709
32935
  }
32710
- }, _callee, null, [[1, 4]]);
32936
+ }, _callee, null, [[1, 3]]);
32711
32937
  }));
32712
- return function generateKeyPair() {
32938
+ return function addSignerOnBoarding(_x) {
32713
32939
  return _ref.apply(this, arguments);
32714
32940
  };
32715
32941
  }();
32716
- var generateCSR = /*#__PURE__*/function () {
32717
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(keyPair, userData) {
32718
- var hashAlg,
32719
- publicKey,
32720
- privateKey,
32721
- pkcs10,
32722
- subjectAttributes,
32723
- csr,
32724
- _args2 = arguments,
32725
- _t2;
32942
+ var addSignerOnPremise = /*#__PURE__*/function () {
32943
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
32726
32944
  return _regenerator().w(function (_context2) {
32727
- while (1) switch (_context2.p = _context2.n) {
32945
+ while (1) switch (_context2.n) {
32728
32946
  case 0:
32729
- hashAlg = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : "SHA-256";
32730
- _context2.p = 1;
32731
- publicKey = keyPair.publicKey, privateKey = keyPair.privateKey; // 1. Validar los parámetros de entrada.
32732
- if (!(!keyPair || !publicKey || !privateKey)) {
32733
- _context2.n = 2;
32947
+ return _context2.a(2, Promise.resolve({
32948
+ signerId: "on-premise-signer-id",
32949
+ status: "added"
32950
+ }));
32951
+ }
32952
+ }, _callee2);
32953
+ }));
32954
+ return function addSignerOnPremise() {
32955
+ return _ref2.apply(this, arguments);
32956
+ };
32957
+ }();
32958
+
32959
+ /**
32960
+ * Agrega un firmante a un documento, manejando diferentes tipos de integración.
32961
+ * @param {object} signerData - Datos del firmante a agregar.
32962
+ * @returns {Promise<object>} Objeto con el resultado de agregar el firmante.
32963
+ */
32964
+ var addSigner = /*#__PURE__*/function () {
32965
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(signerData) {
32966
+ var _getConfig, integrationType;
32967
+ return _regenerator().w(function (_context3) {
32968
+ while (1) switch (_context3.n) {
32969
+ case 0:
32970
+ if (!(!signerData || _typeof(signerData) !== "object" || Object.keys(signerData).length === 0)) {
32971
+ _context3.n = 1;
32734
32972
  break;
32735
32973
  }
32736
- throw new Error("Par de claves no válido. Es necesario un CryptoKeyPair.");
32974
+ throw new ApacuanaAPIError("Los datos del firmante (signerData) son requeridos y deben ser un objeto no vacío.", 400, "INVALID_PARAMETER");
32975
+ case 1:
32976
+ _getConfig = getConfig(), integrationType = _getConfig.integrationType;
32977
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
32978
+ _context3.n = 2;
32979
+ break;
32980
+ }
32981
+ return _context3.a(2, addSignerOnBoarding(signerData));
32737
32982
  case 2:
32738
- if (!(!userData || !userData.email)) {
32739
- _context2.n = 3;
32983
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
32984
+ _context3.n = 3;
32740
32985
  break;
32741
32986
  }
32742
- throw new Error("Datos de usuario incompletos. El correo electrónico es requerido.");
32987
+ return _context3.a(2, addSignerOnPremise(signerData));
32743
32988
  case 3:
32744
- pkcs10 = new CertificationRequest();
32745
- pkcs10.version = 0;
32746
- subjectAttributes = [{
32747
- type: "2.5.4.6",
32748
- // OID para 'Country' (C)
32749
- value: new PrintableString({
32750
- value: userData.country || "VE"
32751
- })
32752
- }, {
32753
- type: "2.5.4.3",
32754
- // OID para 'Common Name' (CN)
32755
- value: new Utf8String({
32756
- value: userData.commonName || "N/A"
32757
- })
32758
- }, {
32759
- type: "1.2.840.113549.1.9.1",
32760
- // OID para 'E-mail' (E)
32761
- value: new IA5String({
32762
- value: userData.email
32763
- })
32989
+ throw new ApacuanaAPIError("Tipo de integraci\xF3n no soportado: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
32990
+ case 4:
32991
+ return _context3.a(2);
32992
+ }
32993
+ }, _callee3);
32994
+ }));
32995
+ return function addSigner(_x2) {
32996
+ return _ref3.apply(this, arguments);
32997
+ };
32998
+ }();
32999
+ var getDocsOnPremise = /*#__PURE__*/function () {
33000
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
33001
+ return _regenerator().w(function (_context4) {
33002
+ while (1) switch (_context4.n) {
33003
+ case 0:
33004
+ throw new ApacuanaAPIError("La obtención de documentos no está soportada para el tipo de integración: ONBOARDING", 501, "NOT_IMPLEMENTED");
33005
+ case 1:
33006
+ return _context4.a(2);
33007
+ }
33008
+ }, _callee4);
33009
+ }));
33010
+ return function getDocsOnPremise() {
33011
+ return _ref4.apply(this, arguments);
33012
+ };
33013
+ }();
33014
+ var getDocsOnBoarding = /*#__PURE__*/function () {
33015
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(data) {
33016
+ var _getConfig2, customerId, apiUrl, response, _t2;
33017
+ return _regenerator().w(function (_context5) {
33018
+ while (1) switch (_context5.p = _context5.n) {
33019
+ case 0:
33020
+ _getConfig2 = getConfig(), customerId = _getConfig2.customerId;
33021
+ if (customerId) {
33022
+ _context5.n = 1;
33023
+ break;
32764
33024
  }
32765
- // Puedes agregar más atributos aquí, como:
32766
- // {
32767
- // type: '2.5.4.8', // OID para 'State or Province' (ST)
32768
- // value: new asn1js.Utf8String({ value: userData.state || 'N/A' }),
32769
- // },
32770
- // {
32771
- // type: '2.5.4.7', // OID para 'Locality' (L)
32772
- // value: new asn1js.Utf8String({ value: userData.locality || 'N/A' }),
32773
- // },
32774
- ].filter(function (attr) {
32775
- return attr.value.value;
32776
- }); // Filtra atributos sin valor.
32777
- // 3. Asignar los atributos al Subject.
32778
- subjectAttributes.forEach(function (attr) {
32779
- return pkcs10.subject.typesAndValues.push(new AttributeTypeAndValue(attr));
32780
- });
32781
-
32782
- // 4. Importar la clave pública y firmar la solicitud con la clave privada.
32783
- _context2.n = 4;
32784
- return pkcs10.subjectPublicKeyInfo.importKey(publicKey);
33025
+ throw new ApacuanaAPIError("El 'customerId' no está configurado. Por favor, configure el SDK.", 400, "CONFIGURATION_ERROR");
33026
+ case 1:
33027
+ _context5.p = 1;
33028
+ apiUrl = "services/api/documents/listcustomer?page=".concat(data.page, "&customerid=").concat(customerId, "&size=").concat(data.size, "&status=").concat(data.status);
33029
+ _context5.n = 2;
33030
+ return httpRequest(apiUrl, {}, "GET");
33031
+ case 2:
33032
+ response = _context5.v;
33033
+ return _context5.a(2, response);
33034
+ case 3:
33035
+ _context5.p = 3;
33036
+ _t2 = _context5.v;
33037
+ if (!(_t2.name === "ApacuanaAPIError")) {
33038
+ _context5.n = 4;
33039
+ break;
33040
+ }
33041
+ throw _t2;
32785
33042
  case 4:
32786
- _context2.n = 5;
32787
- return pkcs10.sign(privateKey, hashAlg);
33043
+ throw new ApacuanaAPIError("Fallo al obtener la lista de documentos (on-premise): ".concat(_t2.message));
32788
33044
  case 5:
32789
- // 5. Codificar el CSR para el envío.
32790
- csr = pkcs10.toSchema().toBER(false); // 6. Retornar el CSR y el Subject.
32791
- return _context2.a(2, {
32792
- csr: csr,
32793
- subject: pkcs10.subject
32794
- });
32795
- case 6:
32796
- _context2.p = 6;
32797
- _t2 = _context2.v;
32798
- // Manejo de errores centralizado.
32799
- console.error("Error durante la generación del CSR:", _t2);
32800
- throw new ApacuanaAPIError("Fallo en la generaci\xF3n del CSR: ".concat(_t2.message), 0, "CSR_GENERATION_ERROR");
32801
- case 7:
32802
- return _context2.a(2);
33045
+ return _context5.a(2);
32803
33046
  }
32804
- }, _callee2, null, [[1, 6]]);
33047
+ }, _callee5, null, [[1, 3]]);
32805
33048
  }));
32806
- return function generateCSR(_x, _x2) {
32807
- return _ref2.apply(this, arguments);
33049
+ return function getDocsOnBoarding(_x3) {
33050
+ return _ref5.apply(this, arguments);
32808
33051
  };
32809
33052
  }();
32810
33053
 
32811
- // Función para convertir ArrayBuffer a Base64
32812
- var arrayBufferToBase64 = function arrayBufferToBase64(buffer) {
32813
- var binary = String.fromCharCode.apply(null, new Uint8Array(buffer));
32814
- return window.btoa(binary);
32815
- };
32816
- function exportPrivateKey(_x3) {
32817
- return _exportPrivateKey.apply(this, arguments);
32818
- }
32819
- function _exportPrivateKey() {
32820
- _exportPrivateKey = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(key) {
32821
- var crypto, exported, exportablePrivateKey;
32822
- return _regenerator().w(function (_context3) {
32823
- while (1) switch (_context3.n) {
33054
+ /**
33055
+ * Obtiene una lista de documentos.
33056
+ * @param {object} data - Objeto con los parámetros de paginación. Debe contener {page, size}.
33057
+ * @returns {Promise<object>} Objeto con la lista de documentos.
33058
+ */
33059
+ var getDocs = /*#__PURE__*/function () {
33060
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(data) {
33061
+ var _getConfig3, integrationType;
33062
+ return _regenerator().w(function (_context6) {
33063
+ while (1) switch (_context6.n) {
32824
33064
  case 0:
32825
- crypto = getCrypto();
32826
- _context3.n = 1;
32827
- return crypto.exportKey("pkcs8", key);
33065
+ helpers.validateGetDocsData(data);
33066
+ _getConfig3 = getConfig(), integrationType = _getConfig3.integrationType;
33067
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33068
+ _context6.n = 1;
33069
+ break;
33070
+ }
33071
+ return _context6.a(2, getDocsOnBoarding(data));
32828
33072
  case 1:
32829
- exported = _context3.v;
32830
- exportablePrivateKey = new Uint8Array(exported);
32831
- return _context3.a(2, arrayBufferToBase64(exportablePrivateKey));
33073
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33074
+ _context6.n = 2;
33075
+ break;
33076
+ }
33077
+ return _context6.a(2, getDocsOnPremise());
33078
+ case 2:
33079
+ throw new ApacuanaAPIError("La obtenci\xF3n de documentos no est\xE1 soportada para un tipo de integraci\xF3n desconocido: ".concat(integrationType), 501, "NOT_IMPLEMENTED");
33080
+ case 3:
33081
+ return _context6.a(2);
32832
33082
  }
32833
- }, _callee3);
33083
+ }, _callee6);
32834
33084
  }));
32835
- return _exportPrivateKey.apply(this, arguments);
32836
- }
32837
- var helpers = {
32838
- getCertificateStatus: getCertificateStatus,
32839
- generateKeyPair: generateKeyPair,
32840
- generateCSR: generateCSR,
32841
- exportPrivateKey: exportPrivateKey,
32842
- arrayBufferToBase64: arrayBufferToBase64
32843
- };
32844
-
32845
- var getCertStatus = function getCertStatus() {
32846
- var config = getConfig();
32847
- var status = helpers.getCertificateStatus(config.userData, false);
32848
- return {
32849
- status: status
33085
+ return function getDocs(_x4) {
33086
+ return _ref6.apply(this, arguments);
32850
33087
  };
32851
- };
33088
+ }();
32852
33089
 
32853
33090
  var apacuana = {
32854
33091
  /**
@@ -32920,7 +33157,10 @@ var apacuana = {
32920
33157
  }(),
32921
33158
  getConfig: getConfig,
32922
33159
  requestRevocation: requestRevocation,
32923
- getCertStatus: getCertStatus
33160
+ getCertStatus: getCertStatus,
33161
+ getCustomer: getCustomer,
33162
+ addSigner: addSigner,
33163
+ getDocs: getDocs
32924
33164
  };
32925
33165
 
32926
33166
  module.exports = apacuana;