apacuana-sdk-core 0.12.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 (37) hide show
  1. package/README.md +131 -164
  2. package/coverage/clover.xml +238 -205
  3. package/coverage/coverage-final.json +4 -4
  4. package/coverage/lcov-report/index.html +24 -24
  5. package/coverage/lcov-report/src/api/certs.js.html +1 -1
  6. package/coverage/lcov-report/src/api/faceLiveness.js.html +1 -1
  7. package/coverage/lcov-report/src/api/index.html +13 -13
  8. package/coverage/lcov-report/src/api/revocations.js.html +1 -1
  9. package/coverage/lcov-report/src/api/signatures.js.html +17 -56
  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 +3 -18
  17. package/coverage/lcov-report/src/success/index.html +1 -1
  18. package/coverage/lcov-report/src/success/index.js.html +1 -1
  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 +466 -393
  24. package/dist/index.d.ts +0 -2
  25. package/dist/index.js +94 -135
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +94 -135
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/types/signatures.d.ts +19 -4
  30. package/dist/utils/helpers.d.ts +4 -2
  31. package/package.json +1 -1
  32. package/src/api/signatures.js +8 -21
  33. package/src/index.js +1 -6
  34. package/src/types/signatures.js +6 -1
  35. package/src/utils/helpers.js +95 -8
  36. package/src/utils/httpClient.js +15 -10
  37. package/tests/api/signatures.test.js +73 -16
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();
@@ -32948,24 +32952,57 @@ var encryptedCsr = function encryptedCsr(csr) {
32948
32952
  };
32949
32953
  return body;
32950
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
+ };
32951
32971
  var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerData) {
32952
- 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") {
32953
32975
  throw new ApacuanaAPIError('El campo "name" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32954
32976
  }
32955
- if (!signerData.reference || typeof signerData.reference !== "string") {
32956
- 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");
32957
32994
  }
32958
32995
  var validDocTypes = ["V", "P", "E"];
32959
- if (!signerData.typedoc || !validDocTypes.includes(signerData.typedoc)) {
32996
+ if (!validatedSignerData.typedoc || !validDocTypes.includes(validatedSignerData.typedoc)) {
32960
32997
  throw new ApacuanaAPIError('El campo "typedoc" es requerido y debe ser uno de los siguientes valores: V, P, E.', 400, "INVALID_PARAMETER_FORMAT");
32961
32998
  }
32962
- if (!signerData.doc || typeof signerData.doc !== "string") {
32999
+ if (!validatedSignerData.doc || typeof validatedSignerData.doc !== "string") {
32963
33000
  throw new ApacuanaAPIError('El campo "doc" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32964
33001
  }
32965
- if (!Array.isArray(signerData.signature) || signerData.signature.length === 0) {
33002
+ if (!Array.isArray(validatedSignerData.signature) || validatedSignerData.signature.length === 0) {
32966
33003
  throw new ApacuanaAPIError('El campo "signature" es requerido y debe ser un array no vacío.', 400, "INVALID_PARAMETER_FORMAT");
32967
33004
  }
32968
- signerData.signature.forEach(function (sig, index) {
33005
+ validatedSignerData.signature.forEach(function (sig, index) {
32969
33006
  if (!Number.isInteger(sig.page) || sig.page < 1) {
32970
33007
  throw new ApacuanaAPIError("La p\xE1gina de la firma ".concat(index + 1, " debe ser un n\xFAmero entero positivo."), 400, "INVALID_PARAMETER_FORMAT");
32971
33008
  }
@@ -32976,6 +33013,17 @@ var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerD
32976
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");
32977
33014
  }
32978
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;
32979
33027
  };
32980
33028
  var validateCsr = function validateCsr(encryptedCSR) {
32981
33029
  if (!encryptedCSR || _typeof(encryptedCSR) !== "object" || !encryptedCSR.csr || typeof encryptedCSR.csr !== "string" || encryptedCSR.csr.trim() === "") {
@@ -33016,6 +33064,21 @@ var validateOnBoardingSignDocumentData = function validateOnBoardingSignDocument
33016
33064
  if (!signedDigest || typeof signedDigest !== "string") {
33017
33065
  throw new ApacuanaAPIError("Signed digest 'signedDigest' is required and must be a string.", 400, "INVALID_PARAMETER");
33018
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;
33019
33082
  };
33020
33083
  var helpers = {
33021
33084
  getCertificateStatus: getCertificateStatus,
@@ -33026,7 +33089,8 @@ var helpers = {
33026
33089
  validateCsr: validateCsr,
33027
33090
  validateGetDocsData: validateGetDocsData,
33028
33091
  validateGetDigestData: validateGetDigestData,
33029
- validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData
33092
+ validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData,
33093
+ createPayloadGetDigest: createPayloadGetDigest
33030
33094
  };
33031
33095
 
33032
33096
  /**
@@ -33313,95 +33377,6 @@ var getRequerimentsByTypeUser = /*#__PURE__*/function () {
33313
33377
  return _ref9.apply(this, arguments);
33314
33378
  };
33315
33379
  }();
33316
- var requestCertificateOnBoarding = /*#__PURE__*/function () {
33317
- var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(params) {
33318
- var response, _t4;
33319
- return _regenerator().w(function (_context0) {
33320
- while (1) switch (_context0.p = _context0.n) {
33321
- case 0:
33322
- _context0.p = 0;
33323
- _context0.n = 1;
33324
- return httpRequest("services/api/customer/request-certificate", params, "POST");
33325
- case 1:
33326
- response = _context0.v;
33327
- return _context0.a(2, new ApacuanaSuccess(response));
33328
- case 2:
33329
- _context0.p = 2;
33330
- _t4 = _context0.v;
33331
- if (!(_t4 instanceof ApacuanaAPIError)) {
33332
- _context0.n = 3;
33333
- break;
33334
- }
33335
- throw _t4;
33336
- case 3:
33337
- throw new Error("Failed to request certificate: ".concat(_t4.message));
33338
- case 4:
33339
- return _context0.a(2);
33340
- }
33341
- }, _callee0, null, [[0, 2]]);
33342
- }));
33343
- return function requestCertificateOnBoarding(_x5) {
33344
- return _ref0.apply(this, arguments);
33345
- };
33346
- }();
33347
- var requestCertificateOnPremise = /*#__PURE__*/function () {
33348
- var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
33349
- return _regenerator().w(function (_context1) {
33350
- while (1) switch (_context1.n) {
33351
- case 0:
33352
- throw new ApacuanaAPIError("Requesting a certificate is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
33353
- case 1:
33354
- return _context1.a(2);
33355
- }
33356
- }, _callee1);
33357
- }));
33358
- return function requestCertificateOnPremise() {
33359
- return _ref1.apply(this, arguments);
33360
- };
33361
- }();
33362
-
33363
- /**
33364
- * Requests a certificate for the user.
33365
- * @param {CertificateRequestParams} params - The parameters for the certificate request.
33366
- * @returns {Promise<RequestCertificateResponse>} Object with a confirmation message and a success indicator.
33367
- * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
33368
- * @throws {Error} If the request fails for another reason or the params are invalid.
33369
- */
33370
- var requestCertificate = /*#__PURE__*/function () {
33371
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(params) {
33372
- var _getConfig4, integrationType;
33373
- return _regenerator().w(function (_context10) {
33374
- while (1) switch (_context10.n) {
33375
- case 0:
33376
- if (!(!params || typeof params.type !== "number" || !Array.isArray(params.documents))) {
33377
- _context10.n = 1;
33378
- break;
33379
- }
33380
- throw new Error('The "params" object with a numeric "type" property and a "documents" array is required.');
33381
- case 1:
33382
- _getConfig4 = getConfig(), integrationType = _getConfig4.integrationType;
33383
- if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33384
- _context10.n = 2;
33385
- break;
33386
- }
33387
- return _context10.a(2, requestCertificateOnBoarding(params));
33388
- case 2:
33389
- if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33390
- _context10.n = 3;
33391
- break;
33392
- }
33393
- return _context10.a(2, requestCertificateOnPremise());
33394
- case 3:
33395
- throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
33396
- case 4:
33397
- return _context10.a(2);
33398
- }
33399
- }, _callee10);
33400
- }));
33401
- return function requestCertificate(_x6) {
33402
- return _ref10.apply(this, arguments);
33403
- };
33404
- }();
33405
33380
 
33406
33381
  /** @typedef {import("../types/signatures").Signer} Signer */
33407
33382
  /** @typedef {import("../types/signatures").SignerData} SignerData */
@@ -33420,27 +33395,15 @@ var requestCertificate = /*#__PURE__*/function () {
33420
33395
 
33421
33396
  var signDocumentOnBoarding = /*#__PURE__*/function () {
33422
33397
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signData) {
33423
- var signature, cert, signedDigest, signBody, response, _t;
33398
+ var payload, signature, response, _t;
33424
33399
  return _regenerator().w(function (_context) {
33425
33400
  while (1) switch (_context.p = _context.n) {
33426
33401
  case 0:
33427
- helpers.validateOnBoardingSignDocumentData(signData);
33428
- signature = signData.signature, cert = signData.cert, signedDigest = signData.signedDigest;
33402
+ payload = helpers.validateOnBoardingSignDocumentData(signData);
33403
+ signature = signData.signature;
33429
33404
  _context.p = 1;
33430
- signBody = {
33431
- positions: JSON.stringify(signature.positions.map(function (p) {
33432
- return {
33433
- x: p.x,
33434
- y: p.y,
33435
- page: p.page,
33436
- status: 1
33437
- };
33438
- })),
33439
- publickey: cert,
33440
- signeddigest: signedDigest
33441
- };
33442
33405
  _context.n = 2;
33443
- return httpRequest("services/api/documents/sign/".concat(signature.id), signBody, "PUT");
33406
+ return httpRequest("services/api/documents/sign/".concat(signature.id), payload, "PUT");
33444
33407
  case 2:
33445
33408
  response = _context.v;
33446
33409
  return _context.a(2, new ApacuanaSuccess(response));
@@ -33480,15 +33443,14 @@ var signDocumentOnPremise = /*#__PURE__*/function () {
33480
33443
  }();
33481
33444
  var getDigestToSignOnBoarding = /*#__PURE__*/function () {
33482
33445
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(signData) {
33483
- var _response$data, response, digest, _t2;
33446
+ var _response$data, formData, response, digest, _t2;
33484
33447
  return _regenerator().w(function (_context3) {
33485
33448
  while (1) switch (_context3.p = _context3.n) {
33486
33449
  case 0:
33487
33450
  _context3.p = 0;
33451
+ formData = helpers.createPayloadGetDigest(signData);
33488
33452
  _context3.n = 1;
33489
- return httpRequest("services/api/documents/getdigest/".concat(signData.signatureId), {
33490
- publickey: signData.cert
33491
- }, "POST");
33453
+ return httpRequest("services/api/documents/getdigest/".concat(signData.signatureId), formData, "POST");
33492
33454
  case 1:
33493
33455
  response = _context3.v;
33494
33456
  digest = ((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.digest) || response.digest;
@@ -33537,14 +33499,14 @@ var getDigestToSignOnPremise = /*#__PURE__*/function () {
33537
33499
  }();
33538
33500
  var addSignerOnBoarding = /*#__PURE__*/function () {
33539
33501
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(signerData) {
33540
- var _t3;
33502
+ var payload, _t3;
33541
33503
  return _regenerator().w(function (_context5) {
33542
33504
  while (1) switch (_context5.p = _context5.n) {
33543
33505
  case 0:
33544
- helpers.validateOnBoardingSignerData(signerData);
33506
+ payload = helpers.validateOnBoardingSignerData(signerData);
33545
33507
  _context5.p = 1;
33546
33508
  _context5.n = 2;
33547
- return httpRequest("services/api/documents/signing", signerData, "POST");
33509
+ return httpRequest("services/api/documents/signingsdk", payload, "POST");
33548
33510
  case 2:
33549
33511
  return _context5.a(2, new ApacuanaSuccess({
33550
33512
  signer: signerData.typedoc + signerData.doc
@@ -34350,9 +34312,6 @@ var apacuana = {
34350
34312
  }
34351
34313
  return init;
34352
34314
  }(),
34353
- /**
34354
- * Permite obtener la configuración actual del SDK.
34355
- */
34356
34315
  close: function close$1() {
34357
34316
  return close();
34358
34317
  },
@@ -34372,8 +34331,8 @@ var apacuana = {
34372
34331
  getCertTypes: getCertTypes,
34373
34332
  getRequerimentsByTypeUser: getRequerimentsByTypeUser,
34374
34333
  createFaceLivenessSession: createFaceLivenessSession,
34375
- validateFaceLiveness: validateFaceLiveness,
34376
- requestCertificate: requestCertificate
34334
+ validateFaceLiveness: validateFaceLiveness
34335
+ // requestCertificate,
34377
34336
  };
34378
34337
 
34379
34338
  module.exports = apacuana;