apacuana-sdk-core 0.10.0 → 0.11.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 (56) hide show
  1. package/README.md +305 -286
  2. package/coverage/clover.xml +337 -243
  3. package/coverage/coverage-final.json +9 -7
  4. package/coverage/lcov-report/index.html +34 -19
  5. package/coverage/lcov-report/src/api/certs.js.html +162 -87
  6. package/coverage/lcov-report/src/api/faceLiveness.js.html +496 -0
  7. package/coverage/lcov-report/src/api/index.html +43 -28
  8. package/coverage/lcov-report/src/api/revocations.js.html +103 -106
  9. package/coverage/lcov-report/src/api/signatures.js.html +25 -253
  10. package/coverage/lcov-report/src/api/users.js.html +7 -13
  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 +8 -8
  15. package/coverage/lcov-report/src/index.html +1 -1
  16. package/coverage/lcov-report/src/index.js.html +26 -2
  17. package/coverage/lcov-report/src/success/index.html +116 -0
  18. package/coverage/lcov-report/src/success/index.js.html +106 -0
  19. package/coverage/lcov-report/src/utils/constant.js.html +4 -4
  20. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  21. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  22. package/coverage/lcov-report/src/utils/index.html +1 -1
  23. package/coverage/lcov.info +582 -406
  24. package/dist/api/certs.d.ts +9 -70
  25. package/dist/api/faceLiveness.d.ts +6 -0
  26. package/dist/api/revocations.d.ts +3 -42
  27. package/dist/api/signatures.d.ts +11 -153
  28. package/dist/index.d.ts +6 -0
  29. package/dist/index.js +463 -252
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +463 -252
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/success/index.d.ts +7 -0
  34. package/dist/types/certs.d.ts +97 -0
  35. package/dist/types/faceLiveness.d.ts +10 -0
  36. package/dist/types/revocations.d.ts +40 -0
  37. package/dist/types/signatures.d.ts +152 -0
  38. package/dist/types/users.d.ts +260 -0
  39. package/package.json +1 -1
  40. package/src/api/certs.js +74 -49
  41. package/src/api/faceLiveness.js +137 -0
  42. package/src/api/revocations.js +66 -67
  43. package/src/api/signatures.js +21 -97
  44. package/src/api/users.js +4 -6
  45. package/src/index.js +8 -0
  46. package/src/success/index.js +8 -0
  47. package/src/types/certs.js +56 -0
  48. package/src/types/faceLiveness.js +7 -0
  49. package/src/types/revocations.js +25 -0
  50. package/src/types/signatures.js +77 -0
  51. package/src/types/users.js +73 -0
  52. package/tests/api/certs.test.js +99 -6
  53. package/tests/api/faceLiveness.test.js +172 -0
  54. package/tests/api/revocations.test.js +37 -37
  55. package/tests/api/signatures.test.js +11 -5
  56. package/tests/api/users.test.js +3 -2
package/dist/index.js CHANGED
@@ -531,6 +531,15 @@ var httpRequest = /*#__PURE__*/function () {
531
531
  };
532
532
  }();
533
533
 
534
+ var ApacuanaSuccess = /*#__PURE__*/_createClass(function ApacuanaSuccess(data) {
535
+ var statusCode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
536
+ _classCallCheck(this, ApacuanaSuccess);
537
+ this.success = true;
538
+ this.statusCode = statusCode;
539
+ this.name = "ApacuanaSuccess";
540
+ this.data = data;
541
+ });
542
+
534
543
  /**
535
544
  * @typedef {object} GetCustomerResponse
536
545
  * @property {string} token - El token de sesión del usuario.
@@ -575,11 +584,10 @@ var getCustomer = /*#__PURE__*/function () {
575
584
  }
576
585
  throw new ApacuanaAPIError("The API response does not contain the user.", 200, "INVALID_API_RESPONSE");
577
586
  case 4:
578
- return _context.a(2, {
587
+ return _context.a(2, new ApacuanaSuccess({
579
588
  token: response.sessionid,
580
- userData: response.entry,
581
- success: true
582
- });
589
+ userData: response.entry
590
+ }));
583
591
  case 5:
584
592
  _context.p = 5;
585
593
  _t = _context.v;
@@ -600,122 +608,166 @@ var getCustomer = /*#__PURE__*/function () {
600
608
  };
601
609
  }();
602
610
 
603
- /**
604
- * @typedef {object} RequestRevocationResponse
605
- * @property {string} revocationStatus - El estado de la solicitud de revocación (e.g., "pending").
606
- * @property {string|number} requestId - El ID de la solicitud de revocación.
607
- */
608
-
609
- /**
610
- * Simula la solicitud de revocación de un certificado.
611
- * @param {string} reasonCode - Código o descripción del motivo de la revocación.
612
- * @returns {Promise<RequestRevocationResponse>} Objeto con el estado de la solicitud de revocación.
613
- */
614
- /**
615
- * @typedef {object} RevocationResponse
616
- * @property {boolean} success - Indicates if the revocation request was successful.
617
- * @property {string} [message] - A message providing details about the outcome.
618
- */
619
-
620
- /**
621
- * @typedef {object} RevocationReason
622
- * @property {string} code - The code for the revocation reason.
623
- * @property {string} description - The description of the revocation reason.
624
- */
625
-
626
- /**
627
- * @typedef {object} RevocationReasonsResponse
628
- * @property {boolean} success - Indicates if the request was successful.
629
- * @property {RevocationReason[]} reasons - A list of revocation reasons.
630
- */
631
-
632
- /**
633
- * Requests the revocation of a certificate.
634
- * @param {number} reasonCode - Código o descripción del motivo de la revocación.
635
- * @returns {Promise<RevocationResponse>} An object indicating the success of the request.
636
- * @throws {ApacuanaAPIError} If the revocation request fails.
637
- */
638
- var requestRevocation = /*#__PURE__*/function () {
639
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(reasonCode) {
611
+ var requestRevocationOnBoarding = /*#__PURE__*/function () {
612
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
640
613
  var response, _t;
641
614
  return _regenerator().w(function (_context) {
642
615
  while (1) switch (_context.p = _context.n) {
643
616
  case 0:
644
- if (reasonCode) {
645
- _context.n = 1;
646
- break;
647
- }
648
- throw new Error("Código de motivo es requerido para requestRevocation.");
617
+ _context.p = 0;
618
+ _context.n = 1;
619
+ return httpRequest("services/api/certificate/revocation", params, "POST");
649
620
  case 1:
650
- _context.p = 1;
651
- _context.n = 2;
652
- return httpRequest("services/api/onboardingclient/requestcert", {
653
- reason: reasonCode
654
- }, "POST");
655
- case 2:
656
621
  response = _context.v;
657
- return _context.a(2, response);
658
- case 3:
659
- _context.p = 3;
622
+ return _context.a(2, new ApacuanaSuccess(response));
623
+ case 2:
624
+ _context.p = 2;
660
625
  _t = _context.v;
661
- throw new Error("Fallo en la solicitud de revocaci\xF3n: ".concat(_t.message));
626
+ if (!(_t instanceof ApacuanaAPIError)) {
627
+ _context.n = 3;
628
+ break;
629
+ }
630
+ throw _t;
631
+ case 3:
632
+ throw new Error("Failed to request revocation: ".concat(_t.message));
662
633
  case 4:
663
634
  return _context.a(2);
664
635
  }
665
- }, _callee, null, [[1, 3]]);
636
+ }, _callee, null, [[0, 2]]);
666
637
  }));
667
- return function requestRevocation(_x) {
638
+ return function requestRevocationOnBoarding(_x) {
668
639
  return _ref.apply(this, arguments);
669
640
  };
670
641
  }();
671
-
672
- /**
673
- * Retrieves the available reasons for certificate revocation.
674
- * @returns {Promise<RevocationReasonsResponse>} An object containing the list of revocation reasons.
675
- * @throws {ApacuanaAPIError} If fetching the reasons fails.
676
- */
677
- var getRevocationReasons = /*#__PURE__*/function () {
642
+ var requestRevocationOnPremise = /*#__PURE__*/function () {
678
643
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
679
- var _getConfig, integrationType, response, _t2;
680
644
  return _regenerator().w(function (_context2) {
681
- while (1) switch (_context2.p = _context2.n) {
645
+ while (1) switch (_context2.n) {
682
646
  case 0:
647
+ throw new ApacuanaAPIError("Requesting revocation is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
648
+ case 1:
649
+ return _context2.a(2);
650
+ }
651
+ }, _callee2);
652
+ }));
653
+ return function requestRevocationOnPremise() {
654
+ return _ref2.apply(this, arguments);
655
+ };
656
+ }();
657
+ var requestRevocation = /*#__PURE__*/function () {
658
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(params) {
659
+ var _getConfig, integrationType;
660
+ return _regenerator().w(function (_context3) {
661
+ while (1) switch (_context3.n) {
662
+ case 0:
663
+ if (!(!params || typeof params.reasonCode !== "number")) {
664
+ _context3.n = 1;
665
+ break;
666
+ }
667
+ throw new Error('The "params" object with a numeric "reasonCode" property is required.');
668
+ case 1:
683
669
  _getConfig = getConfig(), integrationType = _getConfig.integrationType;
670
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
671
+ _context3.n = 2;
672
+ break;
673
+ }
674
+ return _context3.a(2, requestRevocationOnBoarding(params));
675
+ case 2:
684
676
  if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
685
- _context2.n = 1;
677
+ _context3.n = 3;
686
678
  break;
687
679
  }
688
- throw new ApacuanaAPIError("Get revocation reasons is not supported for integration type: ".concat(integrationType), 501, "NOT_IMPLEMENTED");
680
+ return _context3.a(2, requestRevocationOnPremise(params));
681
+ case 3:
682
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
683
+ case 4:
684
+ return _context3.a(2);
685
+ }
686
+ }, _callee3);
687
+ }));
688
+ return function requestRevocation(_x2) {
689
+ return _ref3.apply(this, arguments);
690
+ };
691
+ }();
692
+ var getRevocationReasonsOnBoarding = /*#__PURE__*/function () {
693
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
694
+ var response, _t2;
695
+ return _regenerator().w(function (_context4) {
696
+ while (1) switch (_context4.p = _context4.n) {
697
+ case 0:
698
+ _context4.p = 0;
699
+ _context4.n = 1;
700
+ return httpRequest("services/api/certificate/revocation-reasons", {}, "GET");
689
701
  case 1:
690
- _context2.p = 1;
691
- _context2.n = 2;
692
- return httpRequest("GET", "config/api/revocation/reasonsonboarding", {});
693
- case 2:
694
- response = _context2.v;
695
- if (response.records) {
696
- _context2.n = 3;
702
+ response = _context4.v;
703
+ if (!(!response || !response.records)) {
704
+ _context4.n = 2;
697
705
  break;
698
706
  }
699
707
  throw new ApacuanaAPIError("Failed to fetch revocation reasons.");
708
+ case 2:
709
+ return _context4.a(2, new ApacuanaSuccess(response.records));
700
710
  case 3:
701
- return _context2.a(2, response.records);
702
- case 4:
703
- _context2.p = 4;
704
- _t2 = _context2.v;
711
+ _context4.p = 3;
712
+ _t2 = _context4.v;
705
713
  if (!(_t2 instanceof ApacuanaAPIError)) {
706
- _context2.n = 5;
714
+ _context4.n = 4;
707
715
  break;
708
716
  }
709
717
  throw _t2;
718
+ case 4:
719
+ throw new Error("Failed to get revocation reasons: ".concat(_t2.message));
710
720
  case 5:
711
- throw new Error("Failed to get revocation reasons. Please try again later.");
712
- case 6:
713
- return _context2.a(2);
721
+ return _context4.a(2);
714
722
  }
715
- }, _callee2, null, [[1, 4]]);
723
+ }, _callee4, null, [[0, 3]]);
724
+ }));
725
+ return function getRevocationReasonsOnBoarding() {
726
+ return _ref4.apply(this, arguments);
727
+ };
728
+ }();
729
+ var getRevocationReasonsOnPremise = /*#__PURE__*/function () {
730
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
731
+ return _regenerator().w(function (_context5) {
732
+ while (1) switch (_context5.n) {
733
+ case 0:
734
+ throw new ApacuanaAPIError("Getting revocation reasons is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
735
+ case 1:
736
+ return _context5.a(2);
737
+ }
738
+ }, _callee5);
739
+ }));
740
+ return function getRevocationReasonsOnPremise() {
741
+ return _ref5.apply(this, arguments);
742
+ };
743
+ }();
744
+ var getRevocationReasons = /*#__PURE__*/function () {
745
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
746
+ var _getConfig2, integrationType;
747
+ return _regenerator().w(function (_context6) {
748
+ while (1) switch (_context6.n) {
749
+ case 0:
750
+ _getConfig2 = getConfig(), integrationType = _getConfig2.integrationType;
751
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
752
+ _context6.n = 1;
753
+ break;
754
+ }
755
+ return _context6.a(2, getRevocationReasonsOnBoarding());
756
+ case 1:
757
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
758
+ _context6.n = 2;
759
+ break;
760
+ }
761
+ return _context6.a(2, getRevocationReasonsOnPremise());
762
+ case 2:
763
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
764
+ case 3:
765
+ return _context6.a(2);
766
+ }
767
+ }, _callee6);
716
768
  }));
717
769
  return function getRevocationReasons() {
718
- return _ref2.apply(this, arguments);
770
+ return _ref6.apply(this, arguments);
719
771
  };
720
772
  }();
721
773
 
@@ -32953,24 +33005,6 @@ var helpers = {
32953
33005
  validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData
32954
33006
  };
32955
33007
 
32956
- /**
32957
- * @typedef {object} GenerateCertResponse
32958
- * @property {string} cert - El certificado generado en formato string.
32959
- * @property {string} certifiedid - El ID del certificado generado.
32960
- * @property {boolean} success - Indica si la operación fue exitosa.
32961
- */
32962
-
32963
- /**
32964
- * @typedef {object} GetCertStatusResponse
32965
- * @property {string} status - El estado actual del certificado del usuario.
32966
- * @property {boolean} success - Indica si la operación fue exitosa.
32967
- */
32968
-
32969
- /**
32970
- * @typedef {object} EncryptedCSRObject
32971
- * @property {string} csr - The encrypted Certificate Signing Request.
32972
- */
32973
-
32974
33008
  /**
32975
33009
  * @param {EncryptedCSRObject} encryptedCSR
32976
33010
  */
@@ -32992,11 +33026,10 @@ var generateCertOnBoarding = /*#__PURE__*/function () {
32992
33026
  }
32993
33027
  throw new ApacuanaAPIError("The API response does not contain the certificate.", response.status, "INVALID_API_RESPONSE");
32994
33028
  case 2:
32995
- return _context.a(2, {
33029
+ return _context.a(2, new ApacuanaSuccess({
32996
33030
  cert: cert,
32997
- certifiedid: certifiedid,
32998
- success: true
32999
- });
33031
+ certifiedid: certifiedid
33032
+ }));
33000
33033
  case 3:
33001
33034
  _context.p = 3;
33002
33035
  _t = _context.v;
@@ -33079,24 +33112,10 @@ var getCertStatus = function getCertStatus() {
33079
33112
  var isCertificateInDevice = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
33080
33113
  var config = getConfig();
33081
33114
  var status = helpers.getCertificateStatus(config.userData, isCertificateInDevice);
33082
- return {
33083
- status: status,
33084
- success: true
33085
- };
33115
+ return new ApacuanaSuccess({
33116
+ status: status
33117
+ });
33086
33118
  };
33087
-
33088
- /**
33089
- * @typedef {object} CertType
33090
- * @property {string} id - The ID of the certificate type.
33091
- * @property {string} name - The name of the certificate type.
33092
- */
33093
-
33094
- /**
33095
- * @typedef {object} GetCertTypesResponse
33096
- * @property {Array<CertType>} types - A list of available certificate types.
33097
- * @property {boolean} success - Indicates if the operation was successful.
33098
- */
33099
-
33100
33119
  var getCertTypesOnBoarding = /*#__PURE__*/function () {
33101
33120
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
33102
33121
  var response, _t2;
@@ -33108,9 +33127,7 @@ var getCertTypesOnBoarding = /*#__PURE__*/function () {
33108
33127
  return httpRequest("services/api/customer/typeusers", {}, "GET");
33109
33128
  case 1:
33110
33129
  response = _context4.v;
33111
- return _context4.a(2, _objectSpread2(_objectSpread2({}, response), {}, {
33112
- success: true
33113
- }));
33130
+ return _context4.a(2, new ApacuanaSuccess(response));
33114
33131
  case 2:
33115
33132
  _context4.p = 2;
33116
33133
  _t2 = _context4.v;
@@ -33181,19 +33198,6 @@ var getCertTypes = /*#__PURE__*/function () {
33181
33198
  return _ref6.apply(this, arguments);
33182
33199
  };
33183
33200
  }();
33184
-
33185
- /**
33186
- * @typedef {object} Requirement
33187
- * @property {string} id - The ID of the requirement.
33188
- * @property {string} description - The description of the requirement.
33189
- */
33190
-
33191
- /**
33192
- * @typedef {object} GetRequirementsResponse
33193
- * @property {Array<Requirement>} requirements - A list of requirements for the user type.
33194
- * @property {boolean} success - Indicates if the operation was successful.
33195
- */
33196
-
33197
33201
  var getRequerimentsByTypeUserOnBoarding = /*#__PURE__*/function () {
33198
33202
  var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(type) {
33199
33203
  var response, _t3;
@@ -33205,9 +33209,7 @@ var getRequerimentsByTypeUserOnBoarding = /*#__PURE__*/function () {
33205
33209
  return httpRequest("services/api/customer/documentspref?typeuser=".concat(type), {}, "GET");
33206
33210
  case 1:
33207
33211
  response = _context7.v;
33208
- return _context7.a(2, _objectSpread2(_objectSpread2({}, response), {}, {
33209
- success: true
33210
- }));
33212
+ return _context7.a(2, new ApacuanaSuccess(response));
33211
33213
  case 2:
33212
33214
  _context7.p = 2;
33213
33215
  _t3 = _context7.v;
@@ -33287,70 +33289,106 @@ var getRequerimentsByTypeUser = /*#__PURE__*/function () {
33287
33289
  return _ref9.apply(this, arguments);
33288
33290
  };
33289
33291
  }();
33290
-
33291
- // =================================================================
33292
- // Type Definitions
33293
- // =================================================================
33294
-
33295
- /**
33296
- * Define la estructura de un objeto Firmante.
33297
- * @typedef {object} Signer
33298
- * @property {string} name - Nombre completo del firmante.
33299
- * @property {string} email - Correo electrónico del firmante.
33300
- * @property {string} document - Documento de identidad del firmante.
33301
- */
33302
-
33303
- /**
33304
- * Define la estructura de datos para añadir un firmante.
33305
- * @typedef {object} SignerData
33306
- * @property {string} docId - Identificador único del documento.
33307
- */
33308
-
33309
- /**
33310
- * Define la estructura de la respuesta al añadir un firmante.
33311
- * @typedef {object} AddSignerResponse
33312
- * @property {string} signer - Identificador de confirmación del firmante añadido.
33313
- * @property {boolean} success - Indica si la operación fue exitosa.
33314
- */
33315
-
33316
- /**
33317
- * Define la estructura de datos para obtener el digest de un documento.
33318
- * @typedef {object} GetDigestData
33319
- * @property {string} cert - Certificado del firmante en formato base64.
33320
- * @property {string} signatureId - Identificador único del proceso de firma.
33321
- */
33322
-
33323
- /**
33324
- * Define la estructura de la respuesta al obtener el digest.
33325
- * @typedef {object} GetDigestResponse
33326
- * @property {string} digest - El digest del documento que se va a firmar.
33327
- * @property {boolean} success - Indica si la operación fue exitosa.
33328
- */
33329
-
33330
- /**
33331
- * Define la estructura de los parámetros para obtener documentos.
33332
- * @typedef {object} GetDocsParams
33333
- * @property {number} page - Número de página para la paginación.
33334
- * @property {number} size - Cantidad de registros por página.
33335
- * @property {string} [status] - (Opcional) Estado para filtrar los documentos.
33336
- */
33292
+ var requestCertificateOnBoarding = /*#__PURE__*/function () {
33293
+ var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(params) {
33294
+ var response, _t4;
33295
+ return _regenerator().w(function (_context0) {
33296
+ while (1) switch (_context0.p = _context0.n) {
33297
+ case 0:
33298
+ _context0.p = 0;
33299
+ _context0.n = 1;
33300
+ return httpRequest("services/api/customer/request-certificate", params, "POST");
33301
+ case 1:
33302
+ response = _context0.v;
33303
+ return _context0.a(2, new ApacuanaSuccess(response));
33304
+ case 2:
33305
+ _context0.p = 2;
33306
+ _t4 = _context0.v;
33307
+ if (!(_t4 instanceof ApacuanaAPIError)) {
33308
+ _context0.n = 3;
33309
+ break;
33310
+ }
33311
+ throw _t4;
33312
+ case 3:
33313
+ throw new Error("Failed to request certificate: ".concat(_t4.message));
33314
+ case 4:
33315
+ return _context0.a(2);
33316
+ }
33317
+ }, _callee0, null, [[0, 2]]);
33318
+ }));
33319
+ return function requestCertificateOnBoarding(_x5) {
33320
+ return _ref0.apply(this, arguments);
33321
+ };
33322
+ }();
33323
+ var requestCertificateOnPremise = /*#__PURE__*/function () {
33324
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
33325
+ return _regenerator().w(function (_context1) {
33326
+ while (1) switch (_context1.n) {
33327
+ case 0:
33328
+ throw new ApacuanaAPIError("Requesting a certificate is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
33329
+ case 1:
33330
+ return _context1.a(2);
33331
+ }
33332
+ }, _callee1);
33333
+ }));
33334
+ return function requestCertificateOnPremise() {
33335
+ return _ref1.apply(this, arguments);
33336
+ };
33337
+ }();
33337
33338
 
33338
33339
  /**
33339
- * Define la estructura de la respuesta al obtener documentos.
33340
- * @typedef {object} GetDocsResponse
33341
- * @property {number} totalRecords - El número total de registros encontrados.
33342
- * @property {Array<object>} records - Un arreglo con los registros de los documentos.
33343
- * @property {boolean} success - Indica si la operación fue exitosa.
33340
+ * Requests a certificate for the user.
33341
+ * @param {CertificateRequestParams} params - The parameters for the certificate request.
33342
+ * @returns {Promise<RequestCertificateResponse>} Object with a confirmation message and a success indicator.
33343
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
33344
+ * @throws {Error} If the request fails for another reason or the params are invalid.
33344
33345
  */
33346
+ var requestCertificate = /*#__PURE__*/function () {
33347
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(params) {
33348
+ var _getConfig4, integrationType;
33349
+ return _regenerator().w(function (_context10) {
33350
+ while (1) switch (_context10.n) {
33351
+ case 0:
33352
+ if (!(!params || typeof params.type !== "number" || !Array.isArray(params.documents))) {
33353
+ _context10.n = 1;
33354
+ break;
33355
+ }
33356
+ throw new Error('The "params" object with a numeric "type" property and a "documents" array is required.');
33357
+ case 1:
33358
+ _getConfig4 = getConfig(), integrationType = _getConfig4.integrationType;
33359
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33360
+ _context10.n = 2;
33361
+ break;
33362
+ }
33363
+ return _context10.a(2, requestCertificateOnBoarding(params));
33364
+ case 2:
33365
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33366
+ _context10.n = 3;
33367
+ break;
33368
+ }
33369
+ return _context10.a(2, requestCertificateOnPremise());
33370
+ case 3:
33371
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
33372
+ case 4:
33373
+ return _context10.a(2);
33374
+ }
33375
+ }, _callee10);
33376
+ }));
33377
+ return function requestCertificate(_x6) {
33378
+ return _ref10.apply(this, arguments);
33379
+ };
33380
+ }();
33345
33381
 
33346
- /**
33347
- * @typedef {object} SignDocumentData
33348
- * @property {object} signature - Objeto con información de la firma.
33349
- * @property {string} signature.id - ID de la firma.
33350
- * @property {Array<object>} signature.positions - Posiciones de la firma.
33351
- * @property {string} cert - Certificado en base64.
33352
- * @property {string} signedDigest - Digest firmado.
33353
- */
33382
+ /** @typedef {import("../types/signatures").Signer} Signer */
33383
+ /** @typedef {import("../types/signatures").SignerData} SignerData */
33384
+ /** @typedef {import("../types/signatures").AddSignerResponse} AddSignerResponse */
33385
+ /** @typedef {import("../types/signatures").GetDigestData} GetDigestData */
33386
+ /** @typedef {import("../types/signatures").GetDigestResponse} GetDigestResponse */
33387
+ /** @typedef {import("../types/signatures").GetDocsParams} GetDocsParams */
33388
+ /** @typedef {import("../types/signatures").GetDocsResponse} GetDocsResponse */
33389
+ /** @typedef {import("../types/signatures").SignDocumentData} SignDocumentData */
33390
+ /** @typedef {import("../types/signatures").SignaturePosition} SignaturePosition */
33391
+ /** @typedef {import("../types/signatures").OnboardingSignerData} OnboardingSignerData */
33354
33392
 
33355
33393
  // =================================================================
33356
33394
  // Internal Functions
@@ -33381,7 +33419,7 @@ var signDocumentOnBoarding = /*#__PURE__*/function () {
33381
33419
  return httpRequest("services/api/documents/sign/".concat(signature.id), signBody, "PUT");
33382
33420
  case 2:
33383
33421
  response = _context.v;
33384
- return _context.a(2, response);
33422
+ return _context.a(2, new ApacuanaSuccess(response));
33385
33423
  case 3:
33386
33424
  _context.p = 3;
33387
33425
  _t = _context.v;
@@ -33436,10 +33474,9 @@ var getDigestToSignOnBoarding = /*#__PURE__*/function () {
33436
33474
  }
33437
33475
  throw new ApacuanaAPIError("Signature generation failed: digest not found in the response.", 500, "API_RESPONSE_ERROR");
33438
33476
  case 2:
33439
- return _context3.a(2, {
33440
- digest: digest,
33441
- success: true
33442
- });
33477
+ return _context3.a(2, new ApacuanaSuccess({
33478
+ digest: digest
33479
+ }));
33443
33480
  case 3:
33444
33481
  _context3.p = 3;
33445
33482
  _t2 = _context3.v;
@@ -33485,10 +33522,9 @@ var addSignerOnBoarding = /*#__PURE__*/function () {
33485
33522
  _context5.n = 2;
33486
33523
  return httpRequest("services/api/documents/signing", signerData, "POST");
33487
33524
  case 2:
33488
- return _context5.a(2, {
33489
- signer: signerData.typedoc + signerData.doc,
33490
- success: true
33491
- });
33525
+ return _context5.a(2, new ApacuanaSuccess({
33526
+ signer: signerData.typedoc + signerData.doc
33527
+ }));
33492
33528
  case 3:
33493
33529
  _context5.p = 3;
33494
33530
  _t3 = _context5.v;
@@ -33565,11 +33601,10 @@ var getDocsOnBoarding = /*#__PURE__*/function () {
33565
33601
  return httpRequest(apiUrl, {}, "GET");
33566
33602
  case 2:
33567
33603
  response = _context8.v;
33568
- return _context8.a(2, {
33604
+ return _context8.a(2, new ApacuanaSuccess({
33569
33605
  totalRecords: response.numofrecords,
33570
- records: response.records,
33571
- success: true
33572
- });
33606
+ records: response.records
33607
+ }));
33573
33608
  case 3:
33574
33609
  _context8.p = 3;
33575
33610
  _t4 = _context8.v;
@@ -33603,9 +33638,7 @@ var uploadSignatureVariantOnBoarding = /*#__PURE__*/function () {
33603
33638
  }, "POST");
33604
33639
  case 2:
33605
33640
  response = _context9.v;
33606
- return _context9.a(2, _objectSpread2(_objectSpread2({}, response), {}, {
33607
- success: true
33608
- }));
33641
+ return _context9.a(2, new ApacuanaSuccess(response));
33609
33642
  case 3:
33610
33643
  _context9.p = 3;
33611
33644
  _t5 = _context9.v;
@@ -33652,9 +33685,7 @@ var getSignatureVariantOnBoarding = /*#__PURE__*/function () {
33652
33685
  return httpRequest("services/api/customer/getsignaturephotosdk/".concat(customerId), {}, "GET");
33653
33686
  case 2:
33654
33687
  response = _context1.v;
33655
- return _context1.a(2, _objectSpread2(_objectSpread2({}, response), {}, {
33656
- success: true
33657
- }));
33688
+ return _context1.a(2, new ApacuanaSuccess(response));
33658
33689
  case 3:
33659
33690
  _context1.p = 3;
33660
33691
  _t6 = _context1.v;
@@ -33700,9 +33731,7 @@ var deleteSignatureVariantOnBoarding = /*#__PURE__*/function () {
33700
33731
  return httpRequest("services/api/customer/cleansignaturephoto", {}, "DELETE");
33701
33732
  case 1:
33702
33733
  response = _context11.v;
33703
- return _context11.a(2, _objectSpread2(_objectSpread2({}, response), {}, {
33704
- success: true
33705
- }));
33734
+ return _context11.a(2, new ApacuanaSuccess(response));
33706
33735
  case 2:
33707
33736
  _context11.p = 2;
33708
33737
  _t7 = _context11.v;
@@ -33822,31 +33851,6 @@ var getDigest = /*#__PURE__*/function () {
33822
33851
  * @returns {Promise<AddSignerResponse>} Una promesa que resuelve a un objeto con el resultado de la operación.
33823
33852
  * @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.
33824
33853
  */
33825
- /**
33826
- * @typedef {object} SignaturePosition
33827
- * @property {number} page - The page number for the signature.
33828
- * @property {number} x - The x-coordinate for the signature's position (from 0 to 1).
33829
- * @property {number} y - The y-coordinate for the signature's position (from 0 to 1).
33830
- */
33831
-
33832
- /**
33833
- * @typedef {object} OnboardingSignerData
33834
- * @property {string} name - The name of the document.
33835
- * @property {string} reference - An external reference for the document.
33836
- * @property {string} typedoc - The type of document of the signer (e.g., "V", "E", "J").
33837
- * @property {string} doc - The document number of the signer.
33838
- * @property {SignaturePosition[]} signature - An array of signature positions.
33839
- */
33840
-
33841
- /**
33842
- * Adds a new signer to the signature process.
33843
- * This function acts as a dispatcher, delegating to the appropriate implementation
33844
- * based on the configured integration type.
33845
- *
33846
- * @param {OnboardingSignerData | object} signerData - The signer's data. The structure depends on the integration type.
33847
- * @returns {Promise<object>} The result from the API.
33848
- * @throws {ApacuanaAPIError} If signerData is invalid or if the integration type is not supported.
33849
- */
33850
33854
  var addSigner = /*#__PURE__*/function () {
33851
33855
  var _ref16 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(signerData) {
33852
33856
  var _getConfig5, integrationType;
@@ -34045,6 +34049,210 @@ var deleteSignatureVariant = /*#__PURE__*/function () {
34045
34049
  };
34046
34050
  }();
34047
34051
 
34052
+ var createFaceLivenessSessionOnBoarding = /*#__PURE__*/function () {
34053
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
34054
+ var response, _t;
34055
+ return _regenerator().w(function (_context) {
34056
+ while (1) switch (_context.p = _context.n) {
34057
+ case 0:
34058
+ _context.p = 0;
34059
+ _context.n = 1;
34060
+ return httpRequest("services/api/faceliveness/create", {}, "POST");
34061
+ case 1:
34062
+ response = _context.v;
34063
+ if (response.sessionId) {
34064
+ _context.n = 2;
34065
+ break;
34066
+ }
34067
+ throw new ApacuanaAPIError("The API response does not contain the session ID.", response.status, "INVALID_API_RESPONSE");
34068
+ case 2:
34069
+ return _context.a(2, new ApacuanaSuccess({
34070
+ sessionId: response.sessionId
34071
+ }));
34072
+ case 3:
34073
+ _context.p = 3;
34074
+ _t = _context.v;
34075
+ if (!(_t instanceof ApacuanaAPIError)) {
34076
+ _context.n = 4;
34077
+ break;
34078
+ }
34079
+ throw _t;
34080
+ case 4:
34081
+ throw new Error("Failed to create Face Liveness session: ".concat(_t.message));
34082
+ case 5:
34083
+ return _context.a(2);
34084
+ }
34085
+ }, _callee, null, [[0, 3]]);
34086
+ }));
34087
+ return function createFaceLivenessSessionOnBoarding() {
34088
+ return _ref.apply(this, arguments);
34089
+ };
34090
+ }();
34091
+ var createFaceLivenessSessionOnPremise = /*#__PURE__*/function () {
34092
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
34093
+ return _regenerator().w(function (_context2) {
34094
+ while (1) switch (_context2.n) {
34095
+ case 0:
34096
+ throw new ApacuanaAPIError("Creating a Face Liveness session is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
34097
+ case 1:
34098
+ return _context2.a(2);
34099
+ }
34100
+ }, _callee2);
34101
+ }));
34102
+ return function createFaceLivenessSessionOnPremise() {
34103
+ return _ref2.apply(this, arguments);
34104
+ };
34105
+ }();
34106
+ var validateFaceLivenessOnBoarding = /*#__PURE__*/function () {
34107
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(sessionId) {
34108
+ var response, status, _t2, _t3;
34109
+ return _regenerator().w(function (_context3) {
34110
+ while (1) switch (_context3.p = _context3.n) {
34111
+ case 0:
34112
+ _context3.p = 0;
34113
+ _context3.n = 1;
34114
+ return httpRequest("services/api/faceliveness/validate", {
34115
+ sessionid: sessionId
34116
+ }, "POST");
34117
+ case 1:
34118
+ response = _context3.v;
34119
+ return _context3.a(2, new ApacuanaSuccess(_objectSpread2({
34120
+ status: "verified"
34121
+ }, response)));
34122
+ case 2:
34123
+ _context3.p = 2;
34124
+ _t2 = _context3.v;
34125
+ if (!(_t2 instanceof ApacuanaAPIError)) {
34126
+ _context3.n = 9;
34127
+ break;
34128
+ }
34129
+ _t3 = _t2.statusCode;
34130
+ _context3.n = _t3 === 402 ? 3 : _t3 === 403 ? 4 : _t3 === 406 ? 5 : _t3 === 408 ? 6 : 7;
34131
+ break;
34132
+ case 3:
34133
+ status = "waitingForScan";
34134
+ return _context3.a(3, 8);
34135
+ case 4:
34136
+ status = "rejected";
34137
+ return _context3.a(3, 8);
34138
+ case 5:
34139
+ status = "processing";
34140
+ return _context3.a(3, 8);
34141
+ case 6:
34142
+ status = "expired";
34143
+ return _context3.a(3, 8);
34144
+ case 7:
34145
+ throw _t2;
34146
+ case 8:
34147
+ return _context3.a(2, new ApacuanaSuccess({
34148
+ status: status
34149
+ }));
34150
+ case 9:
34151
+ throw _t2;
34152
+ case 10:
34153
+ return _context3.a(2);
34154
+ }
34155
+ }, _callee3, null, [[0, 2]]);
34156
+ }));
34157
+ return function validateFaceLivenessOnBoarding(_x) {
34158
+ return _ref3.apply(this, arguments);
34159
+ };
34160
+ }();
34161
+ var validateFaceLivenessOnPremise = /*#__PURE__*/function () {
34162
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
34163
+ return _regenerator().w(function (_context4) {
34164
+ while (1) switch (_context4.n) {
34165
+ case 0:
34166
+ throw new ApacuanaAPIError("Validating a Face Liveness session is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
34167
+ case 1:
34168
+ return _context4.a(2);
34169
+ }
34170
+ }, _callee4);
34171
+ }));
34172
+ return function validateFaceLivenessOnPremise() {
34173
+ return _ref4.apply(this, arguments);
34174
+ };
34175
+ }();
34176
+
34177
+ /**
34178
+ * Creates a new Face Liveness session.
34179
+ * @returns {Promise<CreateFaceLivenessSessionResponse>} Object with the session ID and a success indicator.
34180
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
34181
+ * @throws {Error} If the request fails for another reason.
34182
+ */
34183
+ var createFaceLivenessSession = /*#__PURE__*/function () {
34184
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
34185
+ var _getConfig, integrationType;
34186
+ return _regenerator().w(function (_context5) {
34187
+ while (1) switch (_context5.n) {
34188
+ case 0:
34189
+ _getConfig = getConfig(), integrationType = _getConfig.integrationType;
34190
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
34191
+ _context5.n = 1;
34192
+ break;
34193
+ }
34194
+ return _context5.a(2, createFaceLivenessSessionOnBoarding());
34195
+ case 1:
34196
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
34197
+ _context5.n = 2;
34198
+ break;
34199
+ }
34200
+ return _context5.a(2, createFaceLivenessSessionOnPremise());
34201
+ case 2:
34202
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
34203
+ case 3:
34204
+ return _context5.a(2);
34205
+ }
34206
+ }, _callee5);
34207
+ }));
34208
+ return function createFaceLivenessSession() {
34209
+ return _ref5.apply(this, arguments);
34210
+ };
34211
+ }();
34212
+
34213
+ /**
34214
+ * Validates a Face Liveness session and returns its status.
34215
+ * @param {{sessionId: string}} params - Object containing the session ID.
34216
+ * @returns {Promise<ApacuanaSuccess>} Object with the validation status.
34217
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
34218
+ */
34219
+ var validateFaceLiveness = /*#__PURE__*/function () {
34220
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref6) {
34221
+ var sessionId, _getConfig2, integrationType;
34222
+ return _regenerator().w(function (_context6) {
34223
+ while (1) switch (_context6.n) {
34224
+ case 0:
34225
+ sessionId = _ref6.sessionId;
34226
+ if (sessionId) {
34227
+ _context6.n = 1;
34228
+ break;
34229
+ }
34230
+ throw new ApacuanaAPIError("sessionId is a required parameter.", 400, "INVALID_PARAMETER");
34231
+ case 1:
34232
+ _getConfig2 = getConfig(), integrationType = _getConfig2.integrationType;
34233
+ if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
34234
+ _context6.n = 2;
34235
+ break;
34236
+ }
34237
+ return _context6.a(2, validateFaceLivenessOnBoarding(sessionId));
34238
+ case 2:
34239
+ if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
34240
+ _context6.n = 3;
34241
+ break;
34242
+ }
34243
+ return _context6.a(2, validateFaceLivenessOnPremise());
34244
+ case 3:
34245
+ throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
34246
+ case 4:
34247
+ return _context6.a(2);
34248
+ }
34249
+ }, _callee6);
34250
+ }));
34251
+ return function validateFaceLiveness(_x2) {
34252
+ return _ref7.apply(this, arguments);
34253
+ };
34254
+ }();
34255
+
34048
34256
  var apacuana = {
34049
34257
  /**
34050
34258
  * Inicializa el Apacuana SDK con la configuración necesaria y obtiene
@@ -34119,7 +34327,10 @@ var apacuana = {
34119
34327
  getSignatureVariant: getSignatureVariant,
34120
34328
  deleteSignatureVariant: deleteSignatureVariant,
34121
34329
  getCertTypes: getCertTypes,
34122
- getRequerimentsByTypeUser: getRequerimentsByTypeUser
34330
+ getRequerimentsByTypeUser: getRequerimentsByTypeUser,
34331
+ createFaceLivenessSession: createFaceLivenessSession,
34332
+ validateFaceLiveness: validateFaceLiveness,
34333
+ requestCertificate: requestCertificate
34123
34334
  };
34124
34335
 
34125
34336
  module.exports = apacuana;