apacuana-sdk-core 0.3.0 → 0.4.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 (40) hide show
  1. package/coverage/clover.xml +12 -12
  2. package/coverage/coverage-final.json +2 -2
  3. package/coverage/lcov-report/block-navigation.js +1 -1
  4. package/coverage/lcov-report/index.html +1 -1
  5. package/coverage/lcov-report/sorter.js +21 -7
  6. package/coverage/lcov-report/src/api/certs.js.html +2 -2
  7. package/coverage/lcov-report/src/api/index.html +1 -1
  8. package/coverage/lcov-report/src/api/revocations.js.html +12 -15
  9. package/coverage/lcov-report/src/api/signatures.js.html +1 -1
  10. package/coverage/lcov-report/src/api/users.js.html +1 -1
  11. package/coverage/lcov-report/src/config/index.html +1 -1
  12. package/coverage/lcov-report/src/config/index.js.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.html +1 -1
  14. package/coverage/lcov-report/src/errors/index.js.html +1 -1
  15. package/coverage/lcov-report/src/index.html +1 -1
  16. package/coverage/lcov-report/src/index.js.html +6 -3
  17. package/coverage/lcov-report/src/utils/constant.js.html +1 -1
  18. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  19. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  20. package/coverage/lcov-report/src/utils/index.html +1 -1
  21. package/coverage/lcov.info +16 -16
  22. package/dist/api/certs.d.ts +8 -0
  23. package/dist/api/revocations.d.ts +7 -0
  24. package/dist/api/signatures.d.ts +16 -0
  25. package/dist/api/users.d.ts +15 -0
  26. package/dist/config/index.d.ts +11 -0
  27. package/dist/errors/index.d.ts +10 -0
  28. package/dist/index.d.ts +25 -0
  29. package/dist/index.js +116 -9
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +116 -9
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/utils/constant.d.ts +18 -0
  34. package/dist/utils/helpers.d.ts +21 -0
  35. package/dist/utils/httpClient.d.ts +3 -0
  36. package/package.json +9 -4
  37. package/src/api/certs.js +1 -1
  38. package/src/api/revocations.js +10 -11
  39. package/src/index.js +2 -1
  40. package/tsconfig.json +15 -0
@@ -0,0 +1,11 @@
1
+ export function setConfig(newConfig: any): void;
2
+ export function getConfig(): {
3
+ apiUrl: string;
4
+ secretKey: string;
5
+ apiKey: string;
6
+ verificationId: string;
7
+ customerId: string;
8
+ integrationType: string;
9
+ userData: undefined;
10
+ token: undefined;
11
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Clase de error personalizada para errores de la API de Apacuana.
3
+ */
4
+ export class ApacuanaAPIError extends Error {
5
+ constructor(message: any, statusCode?: number, errorCode?: null);
6
+ statusCode: number;
7
+ errorCode: any;
8
+ success: boolean;
9
+ }
10
+ export default ApacuanaAPIError;
@@ -0,0 +1,25 @@
1
+ export default apacuana;
2
+ declare namespace apacuana {
3
+ export function init(config: {
4
+ apiUrl: string;
5
+ secretKey: string;
6
+ apiKey: string;
7
+ verificationId: string;
8
+ customerId: string;
9
+ integrationType: string;
10
+ }): Promise<object>;
11
+ export { getConfig };
12
+ export { requestRevocation };
13
+ export { getCertStatus };
14
+ export { getCustomer };
15
+ export { addSigner };
16
+ export { getDocs };
17
+ export { generateCert };
18
+ }
19
+ import { getConfig } from "./config/index";
20
+ import requestRevocation from "./api/revocations";
21
+ import { getCertStatus } from "./api/certs";
22
+ import getCustomer from "./api/users";
23
+ import { addSigner } from "./api/signatures";
24
+ import { getDocs } from "./api/signatures";
25
+ import { generateCert } from "./api/certs";
package/dist/index.js CHANGED
@@ -590,32 +590,32 @@ var requestRevocation = /*#__PURE__*/function () {
590
590
  return _regenerator().w(function (_context) {
591
591
  while (1) switch (_context.p = _context.n) {
592
592
  case 0:
593
- console.log('-> Función \'requestRevocation\' ejecutada.');
594
- console.log('Parámetros recibidos para solicitud de revocación:', {
593
+ console.log("-> Función 'requestRevocation' ejecutada.");
594
+ console.log("Parámetros recibidos para solicitud de revocación:", {
595
595
  reasonCode: reasonCode
596
596
  });
597
597
  if (reasonCode) {
598
598
  _context.n = 1;
599
599
  break;
600
600
  }
601
- throw new Error('ID de certificado y motivo son requeridos para requestRevocation.');
601
+ throw new Error("ID de certificado y motivo son requeridos para requestRevocation.");
602
602
  case 1:
603
603
  _context.p = 1;
604
604
  _context.n = 2;
605
- return httpRequest('users/api/customers/requestcert', {
605
+ return httpRequest("users/api/customers/requestcert", {
606
606
  reason: reasonCode
607
- }, 'POST');
607
+ }, "POST");
608
608
  case 2:
609
609
  response = _context.v;
610
- console.log('Respuesta del servidor', response);
610
+ console.log("Respuesta del servidor", response);
611
611
  if (response.success) {
612
612
  _context.n = 3;
613
613
  break;
614
614
  }
615
- throw new ApacuanaAPIError(response.message || 'Error desconocido al solicitar revocación.');
615
+ throw new ApacuanaAPIError(response.message || "Error desconocido al solicitar revocación.");
616
616
  case 3:
617
617
  return _context.a(2, {
618
- revocationStatus: response.status || 'pending',
618
+ revocationStatus: response.status || "pending",
619
619
  requestId: response.id
620
620
  });
621
621
  case 4:
@@ -32771,6 +32771,112 @@ var helpers = {
32771
32771
  validateGetDigestData: validateGetDigestData
32772
32772
  };
32773
32773
 
32774
+ var generateCertOnBoarding = /*#__PURE__*/function () {
32775
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
32776
+ var csr,
32777
+ encryptedCSR,
32778
+ response,
32779
+ cert,
32780
+ _args = arguments,
32781
+ _t;
32782
+ return _regenerator().w(function (_context) {
32783
+ while (1) switch (_context.p = _context.n) {
32784
+ case 0:
32785
+ csr = _args.length > 0 && _args[0] !== undefined ? _args[0] : undefined;
32786
+ _context.p = 1;
32787
+ encryptedCSR = helpers.encryptedCsr(csr);
32788
+ _context.n = 2;
32789
+ return httpRequest("services/api/register/certificate", encryptedCSR, "POST");
32790
+ case 2:
32791
+ response = _context.v;
32792
+ cert = response.cert;
32793
+ if (cert) {
32794
+ _context.n = 3;
32795
+ break;
32796
+ }
32797
+ throw new ApacuanaAPIError("The API response does not contain the certificate.", response.status, "INVALID_API_RESPONSE");
32798
+ case 3:
32799
+ return _context.a(2, {
32800
+ cert: cert,
32801
+ success: true
32802
+ });
32803
+ case 4:
32804
+ _context.p = 4;
32805
+ _t = _context.v;
32806
+ if (!(_t instanceof ApacuanaAPIError)) {
32807
+ _context.n = 5;
32808
+ break;
32809
+ }
32810
+ throw _t;
32811
+ case 5:
32812
+ throw new Error("Certificate generation failed: ".concat(_t.message));
32813
+ case 6:
32814
+ return _context.a(2);
32815
+ }
32816
+ }, _callee, null, [[1, 4]]);
32817
+ }));
32818
+ return function generateCertOnBoarding() {
32819
+ return _ref.apply(this, arguments);
32820
+ };
32821
+ }();
32822
+ var generateCertOnPremise = /*#__PURE__*/function () {
32823
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
32824
+ return _regenerator().w(function (_context2) {
32825
+ while (1) switch (_context2.n) {
32826
+ case 0:
32827
+ throw new ApacuanaAPIError("Certificate generation is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
32828
+ case 1:
32829
+ return _context2.a(2);
32830
+ }
32831
+ }, _callee2);
32832
+ }));
32833
+ return function generateCertOnPremise() {
32834
+ return _ref2.apply(this, arguments);
32835
+ };
32836
+ }();
32837
+
32838
+ /**
32839
+ * Generates a digital certificate.
32840
+ * @param {string} [csr] - Certificate Signing Request (CSR).
32841
+ * @returns {Promise<{cert: string, success: boolean}>} Object with the generated certificate and a success indicator.
32842
+ * @throws {ApacuanaAPIError} If the CSR is invalid, if the API response does not contain the certificate, or if the integration type is not supported.
32843
+ * @throws {Error} If certificate generation fails for another reason.
32844
+ */
32845
+ var generateCert = /*#__PURE__*/function () {
32846
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
32847
+ var csr,
32848
+ _getConfig,
32849
+ integrationType,
32850
+ _args3 = arguments;
32851
+ return _regenerator().w(function (_context3) {
32852
+ while (1) switch (_context3.n) {
32853
+ case 0:
32854
+ csr = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : undefined;
32855
+ _getConfig = getConfig(), integrationType = _getConfig.integrationType;
32856
+ helpers.validateCsr(csr);
32857
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
32858
+ _context3.n = 1;
32859
+ break;
32860
+ }
32861
+ return _context3.a(2, generateCertOnBoarding(csr));
32862
+ case 1:
32863
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
32864
+ _context3.n = 2;
32865
+ break;
32866
+ }
32867
+ return _context3.a(2, generateCertOnPremise());
32868
+ case 2:
32869
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
32870
+ case 3:
32871
+ return _context3.a(2);
32872
+ }
32873
+ }, _callee3);
32874
+ }));
32875
+ return function generateCert() {
32876
+ return _ref3.apply(this, arguments);
32877
+ };
32878
+ }();
32879
+
32774
32880
  /**
32775
32881
  * Gets the user's certificate status.
32776
32882
  * @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
@@ -33054,7 +33160,8 @@ var apacuana = {
33054
33160
  getCertStatus: getCertStatus,
33055
33161
  getCustomer: getCustomer,
33056
33162
  addSigner: addSigner,
33057
- getDocs: getDocs
33163
+ getDocs: getDocs,
33164
+ generateCert: generateCert
33058
33165
  };
33059
33166
 
33060
33167
  module.exports = apacuana;