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