apacuana-sdk-core 0.11.0 → 0.13.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 (49) hide show
  1. package/README.md +131 -164
  2. package/coverage/clover.xml +338 -302
  3. package/coverage/coverage-final.json +9 -9
  4. package/coverage/lcov-report/index.html +31 -31
  5. package/coverage/lcov-report/src/api/certs.js.html +1 -1
  6. package/coverage/lcov-report/src/api/faceLiveness.js.html +34 -7
  7. package/coverage/lcov-report/src/api/index.html +13 -13
  8. package/coverage/lcov-report/src/api/revocations.js.html +50 -5
  9. package/coverage/lcov-report/src/api/signatures.js.html +17 -56
  10. package/coverage/lcov-report/src/api/users.js.html +20 -5
  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 +13 -13
  16. package/coverage/lcov-report/src/index.js.html +59 -14
  17. package/coverage/lcov-report/src/success/index.html +1 -1
  18. package/coverage/lcov-report/src/success/index.js.html +5 -5
  19. package/coverage/lcov-report/src/utils/constant.js.html +1 -1
  20. package/coverage/lcov-report/src/utils/helpers.js.html +277 -16
  21. package/coverage/lcov-report/src/utils/httpClient.js.html +32 -17
  22. package/coverage/lcov-report/src/utils/index.html +22 -22
  23. package/coverage/lcov.info +641 -561
  24. package/dist/api/revocations.d.ts +6 -3
  25. package/dist/api/users.d.ts +16 -6
  26. package/dist/index.d.ts +0 -2
  27. package/dist/index.js +149 -147
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +149 -147
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/types/faceLiveness.d.ts +6 -5
  32. package/dist/types/revocations.d.ts +26 -15
  33. package/dist/types/signatures.d.ts +73 -63
  34. package/dist/utils/helpers.d.ts +4 -2
  35. package/package.json +1 -1
  36. package/src/api/faceLiveness.js +13 -4
  37. package/src/api/revocations.js +18 -3
  38. package/src/api/signatures.js +8 -21
  39. package/src/api/users.js +8 -3
  40. package/src/index.js +22 -7
  41. package/src/types/faceLiveness.js +11 -2
  42. package/src/types/revocations.js +29 -9
  43. package/src/types/signatures.js +47 -28
  44. package/src/utils/helpers.js +95 -8
  45. package/src/utils/httpClient.js +15 -10
  46. package/tests/api/faceLiveness.test.js +28 -30
  47. package/tests/api/revocations.test.js +4 -4
  48. package/tests/api/signatures.test.js +73 -16
  49. package/tests/index.test.js +16 -8
@@ -1,3 +1,6 @@
1
- export function requestRevocation(params: any): Promise<ApacuanaSuccess>;
2
- export function getRevocationReasons(): Promise<ApacuanaSuccess>;
3
- import ApacuanaSuccess from "../success";
1
+ export function requestRevocation(params: {
2
+ reasonCode: number;
3
+ }): Promise<RequestRevocationResponse>;
4
+ export function getRevocationReasons(): Promise<GetRevocationReasonsResponse>;
5
+ export type RequestRevocationResponse = import("../types/revocations").RequestRevocationResponse;
6
+ export type GetRevocationReasonsResponse = import("../types/revocations").GetRevocationReasonsResponse;
@@ -1,5 +1,5 @@
1
1
  export default getCustomer;
2
- export type GetCustomerResponse = {
2
+ export type GetCustomerData = {
3
3
  /**
4
4
  * - El token de sesión del usuario.
5
5
  */
@@ -8,23 +8,33 @@ export type GetCustomerResponse = {
8
8
  * - Los datos del usuario obtenidos.
9
9
  */
10
10
  userData: object;
11
+ };
12
+ export type GetCustomerResponse = {
13
+ /**
14
+ * - Indica que la operación fue exitosa.
15
+ */
16
+ success: true;
11
17
  /**
12
- * - Indica si la operación fue exitosa.
18
+ * - El payload de la respuesta.
13
19
  */
14
- success: boolean;
20
+ data: GetCustomerData;
15
21
  };
16
22
  /**
17
- * @typedef {object} GetCustomerResponse
23
+ * @typedef {object} GetCustomerData
18
24
  * @property {string} token - El token de sesión del usuario.
19
25
  * @property {object} userData - Los datos del usuario obtenidos.
20
- * @property {boolean} success - Indica si la operación fue exitosa.
26
+ */
27
+ /**
28
+ * @typedef {object} GetCustomerResponse
29
+ * @property {true} success - Indica que la operación fue exitosa.
30
+ * @property {GetCustomerData} data - El payload de la respuesta.
21
31
  */
22
32
  /**
23
33
  * Obtiene el token de un usuario a través de una petición POST.
24
34
  * Este método es útil para endpoints que requieren datos en el cuerpo de la petición
25
35
  * para buscar un usuario, como un ID de sesión o un token de acceso.
26
36
  *
27
- * @returns {Promise<GetCustomerResponse>} Objeto con el token de sesión, los datos del usuario y un indicador de éxito.
37
+ * @returns {Promise<GetCustomerResponse>} Una promesa que resuelve a un objeto con la respuesta exitosa.
28
38
  * @throws {Error} Si los parámetros de entrada son inválidos.
29
39
  * @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
30
40
  */
package/dist/index.d.ts CHANGED
@@ -26,7 +26,6 @@ declare namespace apacuana {
26
26
  export { getRequerimentsByTypeUser };
27
27
  export { createFaceLivenessSession };
28
28
  export { validateFaceLiveness };
29
- export { requestCertificate };
30
29
  }
31
30
  import { getConfig } from "./config/index";
32
31
  import { requestRevocation } from "./api/revocations";
@@ -45,4 +44,3 @@ import { getCertTypes } from "./api/certs";
45
44
  import { getRequerimentsByTypeUser } from "./api/certs";
46
45
  import { createFaceLivenessSession } from "./api/faceLiveness";
47
46
  import { validateFaceLiveness } from "./api/faceLiveness";
48
- import { requestCertificate } from "./api/certs";
package/dist/index.js CHANGED
@@ -468,17 +468,21 @@ var httpRequest = /*#__PURE__*/function () {
468
468
  throw new Error("Apacuana SDK: Cliente HTTP no inicializado. " + "Llama a apacuana.init() primero.");
469
469
  case 1:
470
470
  requestConfig = {};
471
- hasFile = Object.values(data).some(function (value) {
472
- return typeof File !== "undefined" && value instanceof File;
473
- });
474
- if (hasFile) {
475
- formData = new FormData();
476
- Object.keys(data).forEach(function (key) {
477
- formData.append(key, data[key]);
478
- });
479
- dataToSend = formData;
471
+ if (typeof FormData !== "undefined" && data instanceof FormData) {
472
+ dataToSend = data;
480
473
  } else {
481
- dataToSend = _objectSpread2({}, data);
474
+ hasFile = Object.values(data).some(function (value) {
475
+ return typeof File !== "undefined" && value instanceof File;
476
+ });
477
+ if (hasFile) {
478
+ formData = new FormData();
479
+ Object.keys(data).forEach(function (key) {
480
+ formData.append(key, data[key]);
481
+ });
482
+ dataToSend = formData;
483
+ } else {
484
+ dataToSend = _objectSpread2({}, data);
485
+ }
482
486
  }
483
487
  _context.p = 2;
484
488
  _t = method.toUpperCase();
@@ -541,10 +545,15 @@ var ApacuanaSuccess = /*#__PURE__*/_createClass(function ApacuanaSuccess(data) {
541
545
  });
542
546
 
543
547
  /**
544
- * @typedef {object} GetCustomerResponse
548
+ * @typedef {object} GetCustomerData
545
549
  * @property {string} token - El token de sesión del usuario.
546
550
  * @property {object} userData - Los datos del usuario obtenidos.
547
- * @property {boolean} success - Indica si la operación fue exitosa.
551
+ */
552
+
553
+ /**
554
+ * @typedef {object} GetCustomerResponse
555
+ * @property {true} success - Indica que la operación fue exitosa.
556
+ * @property {GetCustomerData} data - El payload de la respuesta.
548
557
  */
549
558
 
550
559
  /**
@@ -552,7 +561,7 @@ var ApacuanaSuccess = /*#__PURE__*/_createClass(function ApacuanaSuccess(data) {
552
561
  * Este método es útil para endpoints que requieren datos en el cuerpo de la petición
553
562
  * para buscar un usuario, como un ID de sesión o un token de acceso.
554
563
  *
555
- * @returns {Promise<GetCustomerResponse>} Objeto con el token de sesión, los datos del usuario y un indicador de éxito.
564
+ * @returns {Promise<GetCustomerResponse>} Una promesa que resuelve a un objeto con la respuesta exitosa.
556
565
  * @throws {Error} Si los parámetros de entrada son inválidos.
557
566
  * @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
558
567
  */
@@ -608,6 +617,9 @@ var getCustomer = /*#__PURE__*/function () {
608
617
  };
609
618
  }();
610
619
 
620
+ /** @typedef {import("../types/revocations").RequestRevocationResponse} RequestRevocationResponse */
621
+ /** @typedef {import("../types/revocations").GetRevocationReasonsResponse} GetRevocationReasonsResponse */
622
+
611
623
  var requestRevocationOnBoarding = /*#__PURE__*/function () {
612
624
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
613
625
  var response, _t;
@@ -616,7 +628,7 @@ var requestRevocationOnBoarding = /*#__PURE__*/function () {
616
628
  case 0:
617
629
  _context.p = 0;
618
630
  _context.n = 1;
619
- return httpRequest("services/api/certificate/revocation", params, "POST");
631
+ return httpRequest("services/api/onboardingclient/requestcert", params, "POST");
620
632
  case 1:
621
633
  response = _context.v;
622
634
  return _context.a(2, new ApacuanaSuccess(response));
@@ -654,6 +666,14 @@ var requestRevocationOnPremise = /*#__PURE__*/function () {
654
666
  return _ref2.apply(this, arguments);
655
667
  };
656
668
  }();
669
+
670
+ /**
671
+ * Solicita la revocación de un certificado.
672
+ * @param {object} params - Parámetros para la solicitud.
673
+ * @param {number} params.reasonCode - El código de la razón de la revocación.
674
+ * @returns {Promise<RequestRevocationResponse>} Una promesa que resuelve con la confirmación de la solicitud.
675
+ * @throws {Error} Si los parámetros son inválidos.
676
+ */
657
677
  var requestRevocation = /*#__PURE__*/function () {
658
678
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(params) {
659
679
  var _getConfig, integrationType;
@@ -697,7 +717,7 @@ var getRevocationReasonsOnBoarding = /*#__PURE__*/function () {
697
717
  case 0:
698
718
  _context4.p = 0;
699
719
  _context4.n = 1;
700
- return httpRequest("services/api/certificate/revocation-reasons", {}, "GET");
720
+ return httpRequest("config/api/revocation/reasonsonboarding", {}, "GET");
701
721
  case 1:
702
722
  response = _context4.v;
703
723
  if (!(!response || !response.records)) {
@@ -706,7 +726,9 @@ var getRevocationReasonsOnBoarding = /*#__PURE__*/function () {
706
726
  }
707
727
  throw new ApacuanaAPIError("Failed to fetch revocation reasons.");
708
728
  case 2:
709
- return _context4.a(2, new ApacuanaSuccess(response.records));
729
+ return _context4.a(2, new ApacuanaSuccess({
730
+ reasons: response.records
731
+ }));
710
732
  case 3:
711
733
  _context4.p = 3;
712
734
  _t2 = _context4.v;
@@ -741,6 +763,12 @@ var getRevocationReasonsOnPremise = /*#__PURE__*/function () {
741
763
  return _ref5.apply(this, arguments);
742
764
  };
743
765
  }();
766
+
767
+ /**
768
+ * Obtiene la lista de razones de revocación de certificados.
769
+ * @returns {Promise<GetRevocationReasonsResponse>} Una promesa que resuelve con la lista de razones de revocación.
770
+ * @throws {ApacuanaAPIError} Si la llamada a la API falla o el tipo de integración no es soportado.
771
+ */
744
772
  var getRevocationReasons = /*#__PURE__*/function () {
745
773
  var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
746
774
  var _getConfig2, integrationType;
@@ -32924,24 +32952,57 @@ var encryptedCsr = function encryptedCsr(csr) {
32924
32952
  };
32925
32953
  return body;
32926
32954
  };
32955
+ var createPayloadGetDigest = function createPayloadGetDigest(signData) {
32956
+ var formData = new FormData();
32957
+
32958
+ // Iterate over the object's own properties
32959
+ Object.keys(signData).forEach(function (key) {
32960
+ // Conditionally handle the 'document' field
32961
+
32962
+ if (key === "document" && signData[key] instanceof File) {
32963
+ // Append the file directly
32964
+ formData.append(key, signData[key]);
32965
+ } else if (key === "cert") {
32966
+ formData.append("publickey", signData[key]);
32967
+ }
32968
+ });
32969
+ return formData;
32970
+ };
32927
32971
  var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerData) {
32928
- if (!signerData.name || typeof signerData.name !== "string") {
32972
+ // Create a copy of the original object to avoid modifying the function parameter
32973
+ var validatedSignerData = _objectSpread2({}, signerData);
32974
+ if (!validatedSignerData.name || typeof validatedSignerData.name !== "string") {
32929
32975
  throw new ApacuanaAPIError('El campo "name" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32930
32976
  }
32931
- if (!signerData.reference || typeof signerData.reference !== "string") {
32932
- throw new ApacuanaAPIError('El campo "reference" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32977
+
32978
+ // Limpia 'reference' si es inválido o está vacío.
32979
+ if (!validatedSignerData.reference || typeof validatedSignerData.reference !== "string" || validatedSignerData.reference.trim() === "") {
32980
+ delete validatedSignerData.reference;
32981
+ }
32982
+
32983
+ // Limpia 'file' si no es una instancia de File.
32984
+ if (typeof File === "undefined" || !validatedSignerData.file || !(validatedSignerData.file instanceof File)) {
32985
+ delete validatedSignerData.file;
32986
+ }
32987
+
32988
+ // Valida que solo uno de los dos campos exista después de la limpieza.
32989
+ if (validatedSignerData.reference && validatedSignerData.file) {
32990
+ throw new ApacuanaAPIError("No se pueden proporcionar 'reference' y 'file' simultáneamente.", 400, "INVALID_PARAMETER_FORMAT");
32991
+ }
32992
+ if (!validatedSignerData.reference && !validatedSignerData.file) {
32993
+ throw new ApacuanaAPIError("Se debe proporcionar un campo 'reference' o 'file' válido.", 400, "INVALID_PARAMETER_FORMAT");
32933
32994
  }
32934
32995
  var validDocTypes = ["V", "P", "E"];
32935
- if (!signerData.typedoc || !validDocTypes.includes(signerData.typedoc)) {
32996
+ if (!validatedSignerData.typedoc || !validDocTypes.includes(validatedSignerData.typedoc)) {
32936
32997
  throw new ApacuanaAPIError('El campo "typedoc" es requerido y debe ser uno de los siguientes valores: V, P, E.', 400, "INVALID_PARAMETER_FORMAT");
32937
32998
  }
32938
- if (!signerData.doc || typeof signerData.doc !== "string") {
32999
+ if (!validatedSignerData.doc || typeof validatedSignerData.doc !== "string") {
32939
33000
  throw new ApacuanaAPIError('El campo "doc" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32940
33001
  }
32941
- if (!Array.isArray(signerData.signature) || signerData.signature.length === 0) {
33002
+ if (!Array.isArray(validatedSignerData.signature) || validatedSignerData.signature.length === 0) {
32942
33003
  throw new ApacuanaAPIError('El campo "signature" es requerido y debe ser un array no vacío.', 400, "INVALID_PARAMETER_FORMAT");
32943
33004
  }
32944
- signerData.signature.forEach(function (sig, index) {
33005
+ validatedSignerData.signature.forEach(function (sig, index) {
32945
33006
  if (!Number.isInteger(sig.page) || sig.page < 1) {
32946
33007
  throw new ApacuanaAPIError("La p\xE1gina de la firma ".concat(index + 1, " debe ser un n\xFAmero entero positivo."), 400, "INVALID_PARAMETER_FORMAT");
32947
33008
  }
@@ -32952,6 +33013,17 @@ var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerD
32952
33013
  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");
32953
33014
  }
32954
33015
  });
33016
+ var formData = new FormData();
33017
+ Object.keys(validatedSignerData).forEach(function (key) {
33018
+ if (key === "signature") {
33019
+ formData.append(key, JSON.stringify(validatedSignerData[key]));
33020
+ } else if (key === "file") {
33021
+ formData.append("document", validatedSignerData[key]);
33022
+ } else if (validatedSignerData[key] !== undefined) {
33023
+ formData.append(key, validatedSignerData[key]);
33024
+ }
33025
+ });
33026
+ return formData;
32955
33027
  };
32956
33028
  var validateCsr = function validateCsr(encryptedCSR) {
32957
33029
  if (!encryptedCSR || _typeof(encryptedCSR) !== "object" || !encryptedCSR.csr || typeof encryptedCSR.csr !== "string" || encryptedCSR.csr.trim() === "") {
@@ -32992,6 +33064,21 @@ var validateOnBoardingSignDocumentData = function validateOnBoardingSignDocument
32992
33064
  if (!signedDigest || typeof signedDigest !== "string") {
32993
33065
  throw new ApacuanaAPIError("Signed digest 'signedDigest' is required and must be a string.", 400, "INVALID_PARAMETER");
32994
33066
  }
33067
+ var formData = new FormData();
33068
+ formData.append("positions", JSON.stringify(signature.positions.map(function (p) {
33069
+ return {
33070
+ x: p.x,
33071
+ y: p.y,
33072
+ page: p.page,
33073
+ status: 1
33074
+ };
33075
+ })));
33076
+ formData.append("publickey", cert);
33077
+ formData.append("signeddigest", signedDigest);
33078
+ if (signData.document && signData.document instanceof File) {
33079
+ formData.append("document", signData.document);
33080
+ }
33081
+ return formData;
32995
33082
  };
32996
33083
  var helpers = {
32997
33084
  getCertificateStatus: getCertificateStatus,
@@ -33002,7 +33089,8 @@ var helpers = {
33002
33089
  validateCsr: validateCsr,
33003
33090
  validateGetDocsData: validateGetDocsData,
33004
33091
  validateGetDigestData: validateGetDigestData,
33005
- validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData
33092
+ validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData,
33093
+ createPayloadGetDigest: createPayloadGetDigest
33006
33094
  };
33007
33095
 
33008
33096
  /**
@@ -33289,95 +33377,6 @@ var getRequerimentsByTypeUser = /*#__PURE__*/function () {
33289
33377
  return _ref9.apply(this, arguments);
33290
33378
  };
33291
33379
  }();
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
- }();
33338
-
33339
- /**
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.
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
- }();
33381
33380
 
33382
33381
  /** @typedef {import("../types/signatures").Signer} Signer */
33383
33382
  /** @typedef {import("../types/signatures").SignerData} SignerData */
@@ -33396,27 +33395,15 @@ var requestCertificate = /*#__PURE__*/function () {
33396
33395
 
33397
33396
  var signDocumentOnBoarding = /*#__PURE__*/function () {
33398
33397
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signData) {
33399
- var signature, cert, signedDigest, signBody, response, _t;
33398
+ var payload, signature, response, _t;
33400
33399
  return _regenerator().w(function (_context) {
33401
33400
  while (1) switch (_context.p = _context.n) {
33402
33401
  case 0:
33403
- helpers.validateOnBoardingSignDocumentData(signData);
33404
- signature = signData.signature, cert = signData.cert, signedDigest = signData.signedDigest;
33402
+ payload = helpers.validateOnBoardingSignDocumentData(signData);
33403
+ signature = signData.signature;
33405
33404
  _context.p = 1;
33406
- signBody = {
33407
- positions: JSON.stringify(signature.positions.map(function (p) {
33408
- return {
33409
- x: p.x,
33410
- y: p.y,
33411
- page: p.page,
33412
- status: 1
33413
- };
33414
- })),
33415
- publickey: cert,
33416
- signeddigest: signedDigest
33417
- };
33418
33405
  _context.n = 2;
33419
- return httpRequest("services/api/documents/sign/".concat(signature.id), signBody, "PUT");
33406
+ return httpRequest("services/api/documents/sign/".concat(signature.id), payload, "PUT");
33420
33407
  case 2:
33421
33408
  response = _context.v;
33422
33409
  return _context.a(2, new ApacuanaSuccess(response));
@@ -33456,15 +33443,14 @@ var signDocumentOnPremise = /*#__PURE__*/function () {
33456
33443
  }();
33457
33444
  var getDigestToSignOnBoarding = /*#__PURE__*/function () {
33458
33445
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(signData) {
33459
- var _response$data, response, digest, _t2;
33446
+ var _response$data, formData, response, digest, _t2;
33460
33447
  return _regenerator().w(function (_context3) {
33461
33448
  while (1) switch (_context3.p = _context3.n) {
33462
33449
  case 0:
33463
33450
  _context3.p = 0;
33451
+ formData = helpers.createPayloadGetDigest(signData);
33464
33452
  _context3.n = 1;
33465
- return httpRequest("services/api/documents/getdigest/".concat(signData.signatureId), {
33466
- publickey: signData.cert
33467
- }, "POST");
33453
+ return httpRequest("services/api/documents/getdigest/".concat(signData.signatureId), formData, "POST");
33468
33454
  case 1:
33469
33455
  response = _context3.v;
33470
33456
  digest = ((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.digest) || response.digest;
@@ -33513,14 +33499,14 @@ var getDigestToSignOnPremise = /*#__PURE__*/function () {
33513
33499
  }();
33514
33500
  var addSignerOnBoarding = /*#__PURE__*/function () {
33515
33501
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(signerData) {
33516
- var _t3;
33502
+ var payload, _t3;
33517
33503
  return _regenerator().w(function (_context5) {
33518
33504
  while (1) switch (_context5.p = _context5.n) {
33519
33505
  case 0:
33520
- helpers.validateOnBoardingSignerData(signerData);
33506
+ payload = helpers.validateOnBoardingSignerData(signerData);
33521
33507
  _context5.p = 1;
33522
33508
  _context5.n = 2;
33523
- return httpRequest("services/api/documents/signing", signerData, "POST");
33509
+ return httpRequest("services/api/documents/signingsdk", payload, "POST");
33524
33510
  case 2:
33525
33511
  return _context5.a(2, new ApacuanaSuccess({
33526
33512
  signer: signerData.typedoc + signerData.doc
@@ -34049,6 +34035,12 @@ var deleteSignatureVariant = /*#__PURE__*/function () {
34049
34035
  };
34050
34036
  }();
34051
34037
 
34038
+ /**
34039
+ * Creates a new Face Liveness session.
34040
+ * @returns {Promise<CreateFaceLivenessSessionResponse>} Object with the session ID and a success indicator.
34041
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
34042
+ * @throws {Error} If the request fails for another reason.
34043
+ */
34052
34044
  var createFaceLivenessSessionOnBoarding = /*#__PURE__*/function () {
34053
34045
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
34054
34046
  var response, _t;
@@ -34060,14 +34052,14 @@ var createFaceLivenessSessionOnBoarding = /*#__PURE__*/function () {
34060
34052
  return httpRequest("services/api/faceliveness/create", {}, "POST");
34061
34053
  case 1:
34062
34054
  response = _context.v;
34063
- if (response.sessionId) {
34055
+ if (response.sessionid) {
34064
34056
  _context.n = 2;
34065
34057
  break;
34066
34058
  }
34067
34059
  throw new ApacuanaAPIError("The API response does not contain the session ID.", response.status, "INVALID_API_RESPONSE");
34068
34060
  case 2:
34069
34061
  return _context.a(2, new ApacuanaSuccess({
34070
- sessionId: response.sessionId
34062
+ sessionId: response.sessionid
34071
34063
  }));
34072
34064
  case 3:
34073
34065
  _context.p = 3;
@@ -34078,7 +34070,7 @@ var createFaceLivenessSessionOnBoarding = /*#__PURE__*/function () {
34078
34070
  }
34079
34071
  throw _t;
34080
34072
  case 4:
34081
- throw new Error("Failed to create Face Liveness session: ".concat(_t.message));
34073
+ throw new ApacuanaAPIError("Failed to create Face Liveness session: ".concat(_t.message));
34082
34074
  case 5:
34083
34075
  return _context.a(2);
34084
34076
  }
@@ -34268,7 +34260,7 @@ var apacuana = {
34268
34260
  */
34269
34261
  init: function () {
34270
34262
  var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config) {
34271
- var currentConfig, _yield$getCustomer, token, userData, _t;
34263
+ var currentConfig, customer, _customer$data, token, userData, _t;
34272
34264
  return _regenerator().w(function (_context) {
34273
34265
  while (1) switch (_context.p = _context.n) {
34274
34266
  case 0:
@@ -34280,27 +34272,37 @@ var apacuana = {
34280
34272
  _context.n = 1;
34281
34273
  break;
34282
34274
  }
34283
- throw new Error("Apacuana SDK: La configuración de CustomerId no se ha guardado" + " correctamente.");
34275
+ throw new ApacuanaAPIError("Apacuana SDK: La configuración de CustomerId no se ha guardado" + " correctamente.", 400, {
34276
+ code: "CONFIG_ERROR"
34277
+ });
34284
34278
  case 1:
34285
34279
  _context.n = 2;
34286
34280
  return getCustomer();
34287
34281
  case 2:
34288
- _yield$getCustomer = _context.v;
34289
- token = _yield$getCustomer.token;
34290
- userData = _yield$getCustomer.userData;
34282
+ customer = _context.v;
34283
+ _customer$data = customer.data, token = _customer$data.token, userData = _customer$data.userData;
34291
34284
  setConfig(_objectSpread2(_objectSpread2({}, currentConfig), {}, {
34292
34285
  token: token,
34293
34286
  userData: userData
34294
34287
  }));
34295
34288
  setAuthToken(token);
34296
- return _context.a(2, true);
34289
+ return _context.a(2, new ApacuanaSuccess({
34290
+ initialized: true,
34291
+ message: "SDK inicializado correctamente."
34292
+ }));
34297
34293
  case 3:
34298
34294
  _context.p = 3;
34299
34295
  _t = _context.v;
34300
34296
  // eslint-disable-next-line no-console
34301
34297
  console.error("Error durante la inicialización del SDK:", _t);
34298
+ if (!(_t instanceof ApacuanaAPIError)) {
34299
+ _context.n = 4;
34300
+ break;
34301
+ }
34302
34302
  throw _t;
34303
34303
  case 4:
34304
+ throw new ApacuanaAPIError(_t.message || "Error desconocido durante la inicialización.", 500, _t);
34305
+ case 5:
34304
34306
  return _context.a(2);
34305
34307
  }
34306
34308
  }, _callee, null, [[0, 3]]);
@@ -34329,8 +34331,8 @@ var apacuana = {
34329
34331
  getCertTypes: getCertTypes,
34330
34332
  getRequerimentsByTypeUser: getRequerimentsByTypeUser,
34331
34333
  createFaceLivenessSession: createFaceLivenessSession,
34332
- validateFaceLiveness: validateFaceLiveness,
34333
- requestCertificate: requestCertificate
34334
+ validateFaceLiveness: validateFaceLiveness
34335
+ // requestCertificate,
34334
34336
  };
34335
34337
 
34336
34338
  module.exports = apacuana;