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.mjs CHANGED
@@ -466,17 +466,21 @@ var httpRequest = /*#__PURE__*/function () {
466
466
  throw new Error("Apacuana SDK: Cliente HTTP no inicializado. " + "Llama a apacuana.init() primero.");
467
467
  case 1:
468
468
  requestConfig = {};
469
- hasFile = Object.values(data).some(function (value) {
470
- return typeof File !== "undefined" && value instanceof File;
471
- });
472
- if (hasFile) {
473
- formData = new FormData();
474
- Object.keys(data).forEach(function (key) {
475
- formData.append(key, data[key]);
476
- });
477
- dataToSend = formData;
469
+ if (typeof FormData !== "undefined" && data instanceof FormData) {
470
+ dataToSend = data;
478
471
  } else {
479
- dataToSend = _objectSpread2({}, data);
472
+ hasFile = Object.values(data).some(function (value) {
473
+ return typeof File !== "undefined" && value instanceof File;
474
+ });
475
+ if (hasFile) {
476
+ formData = new FormData();
477
+ Object.keys(data).forEach(function (key) {
478
+ formData.append(key, data[key]);
479
+ });
480
+ dataToSend = formData;
481
+ } else {
482
+ dataToSend = _objectSpread2({}, data);
483
+ }
480
484
  }
481
485
  _context.p = 2;
482
486
  _t = method.toUpperCase();
@@ -32946,24 +32950,57 @@ var encryptedCsr = function encryptedCsr(csr) {
32946
32950
  };
32947
32951
  return body;
32948
32952
  };
32953
+ var createPayloadGetDigest = function createPayloadGetDigest(signData) {
32954
+ var formData = new FormData();
32955
+
32956
+ // Iterate over the object's own properties
32957
+ Object.keys(signData).forEach(function (key) {
32958
+ // Conditionally handle the 'document' field
32959
+
32960
+ if (key === "document" && signData[key] instanceof File) {
32961
+ // Append the file directly
32962
+ formData.append(key, signData[key]);
32963
+ } else if (key === "cert") {
32964
+ formData.append("publickey", signData[key]);
32965
+ }
32966
+ });
32967
+ return formData;
32968
+ };
32949
32969
  var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerData) {
32950
- if (!signerData.name || typeof signerData.name !== "string") {
32970
+ // Create a copy of the original object to avoid modifying the function parameter
32971
+ var validatedSignerData = _objectSpread2({}, signerData);
32972
+ if (!validatedSignerData.name || typeof validatedSignerData.name !== "string") {
32951
32973
  throw new ApacuanaAPIError('El campo "name" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32952
32974
  }
32953
- if (!signerData.reference || typeof signerData.reference !== "string") {
32954
- throw new ApacuanaAPIError('El campo "reference" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32975
+
32976
+ // Limpia 'reference' si es inválido o está vacío.
32977
+ if (!validatedSignerData.reference || typeof validatedSignerData.reference !== "string" || validatedSignerData.reference.trim() === "") {
32978
+ delete validatedSignerData.reference;
32979
+ }
32980
+
32981
+ // Limpia 'file' si no es una instancia de File.
32982
+ if (typeof File === "undefined" || !validatedSignerData.file || !(validatedSignerData.file instanceof File)) {
32983
+ delete validatedSignerData.file;
32984
+ }
32985
+
32986
+ // Valida que solo uno de los dos campos exista después de la limpieza.
32987
+ if (validatedSignerData.reference && validatedSignerData.file) {
32988
+ throw new ApacuanaAPIError("No se pueden proporcionar 'reference' y 'file' simultáneamente.", 400, "INVALID_PARAMETER_FORMAT");
32989
+ }
32990
+ if (!validatedSignerData.reference && !validatedSignerData.file) {
32991
+ throw new ApacuanaAPIError("Se debe proporcionar un campo 'reference' o 'file' válido.", 400, "INVALID_PARAMETER_FORMAT");
32955
32992
  }
32956
32993
  var validDocTypes = ["V", "P", "E"];
32957
- if (!signerData.typedoc || !validDocTypes.includes(signerData.typedoc)) {
32994
+ if (!validatedSignerData.typedoc || !validDocTypes.includes(validatedSignerData.typedoc)) {
32958
32995
  throw new ApacuanaAPIError('El campo "typedoc" es requerido y debe ser uno de los siguientes valores: V, P, E.', 400, "INVALID_PARAMETER_FORMAT");
32959
32996
  }
32960
- if (!signerData.doc || typeof signerData.doc !== "string") {
32997
+ if (!validatedSignerData.doc || typeof validatedSignerData.doc !== "string") {
32961
32998
  throw new ApacuanaAPIError('El campo "doc" es requerido y debe ser una cadena de texto.', 400, "INVALID_PARAMETER_FORMAT");
32962
32999
  }
32963
- if (!Array.isArray(signerData.signature) || signerData.signature.length === 0) {
33000
+ if (!Array.isArray(validatedSignerData.signature) || validatedSignerData.signature.length === 0) {
32964
33001
  throw new ApacuanaAPIError('El campo "signature" es requerido y debe ser un array no vacío.', 400, "INVALID_PARAMETER_FORMAT");
32965
33002
  }
32966
- signerData.signature.forEach(function (sig, index) {
33003
+ validatedSignerData.signature.forEach(function (sig, index) {
32967
33004
  if (!Number.isInteger(sig.page) || sig.page < 1) {
32968
33005
  throw new ApacuanaAPIError("La p\xE1gina de la firma ".concat(index + 1, " debe ser un n\xFAmero entero positivo."), 400, "INVALID_PARAMETER_FORMAT");
32969
33006
  }
@@ -32974,6 +33011,17 @@ var validateOnBoardingSignerData = function validateOnBoardingSignerData(signerD
32974
33011
  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");
32975
33012
  }
32976
33013
  });
33014
+ var formData = new FormData();
33015
+ Object.keys(validatedSignerData).forEach(function (key) {
33016
+ if (key === "signature") {
33017
+ formData.append(key, JSON.stringify(validatedSignerData[key]));
33018
+ } else if (key === "file") {
33019
+ formData.append("document", validatedSignerData[key]);
33020
+ } else if (validatedSignerData[key] !== undefined) {
33021
+ formData.append(key, validatedSignerData[key]);
33022
+ }
33023
+ });
33024
+ return formData;
32977
33025
  };
32978
33026
  var validateCsr = function validateCsr(encryptedCSR) {
32979
33027
  if (!encryptedCSR || _typeof(encryptedCSR) !== "object" || !encryptedCSR.csr || typeof encryptedCSR.csr !== "string" || encryptedCSR.csr.trim() === "") {
@@ -33014,6 +33062,21 @@ var validateOnBoardingSignDocumentData = function validateOnBoardingSignDocument
33014
33062
  if (!signedDigest || typeof signedDigest !== "string") {
33015
33063
  throw new ApacuanaAPIError("Signed digest 'signedDigest' is required and must be a string.", 400, "INVALID_PARAMETER");
33016
33064
  }
33065
+ var formData = new FormData();
33066
+ formData.append("positions", JSON.stringify(signature.positions.map(function (p) {
33067
+ return {
33068
+ x: p.x,
33069
+ y: p.y,
33070
+ page: p.page,
33071
+ status: 1
33072
+ };
33073
+ })));
33074
+ formData.append("publickey", cert);
33075
+ formData.append("signeddigest", signedDigest);
33076
+ if (signData.document && signData.document instanceof File) {
33077
+ formData.append("document", signData.document);
33078
+ }
33079
+ return formData;
33017
33080
  };
33018
33081
  var helpers = {
33019
33082
  getCertificateStatus: getCertificateStatus,
@@ -33024,7 +33087,8 @@ var helpers = {
33024
33087
  validateCsr: validateCsr,
33025
33088
  validateGetDocsData: validateGetDocsData,
33026
33089
  validateGetDigestData: validateGetDigestData,
33027
- validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData
33090
+ validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData,
33091
+ createPayloadGetDigest: createPayloadGetDigest
33028
33092
  };
33029
33093
 
33030
33094
  /**
@@ -33311,95 +33375,6 @@ var getRequerimentsByTypeUser = /*#__PURE__*/function () {
33311
33375
  return _ref9.apply(this, arguments);
33312
33376
  };
33313
33377
  }();
33314
- var requestCertificateOnBoarding = /*#__PURE__*/function () {
33315
- var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(params) {
33316
- var response, _t4;
33317
- return _regenerator().w(function (_context0) {
33318
- while (1) switch (_context0.p = _context0.n) {
33319
- case 0:
33320
- _context0.p = 0;
33321
- _context0.n = 1;
33322
- return httpRequest("services/api/customer/request-certificate", params, "POST");
33323
- case 1:
33324
- response = _context0.v;
33325
- return _context0.a(2, new ApacuanaSuccess(response));
33326
- case 2:
33327
- _context0.p = 2;
33328
- _t4 = _context0.v;
33329
- if (!(_t4 instanceof ApacuanaAPIError)) {
33330
- _context0.n = 3;
33331
- break;
33332
- }
33333
- throw _t4;
33334
- case 3:
33335
- throw new Error("Failed to request certificate: ".concat(_t4.message));
33336
- case 4:
33337
- return _context0.a(2);
33338
- }
33339
- }, _callee0, null, [[0, 2]]);
33340
- }));
33341
- return function requestCertificateOnBoarding(_x5) {
33342
- return _ref0.apply(this, arguments);
33343
- };
33344
- }();
33345
- var requestCertificateOnPremise = /*#__PURE__*/function () {
33346
- var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
33347
- return _regenerator().w(function (_context1) {
33348
- while (1) switch (_context1.n) {
33349
- case 0:
33350
- throw new ApacuanaAPIError("Requesting a certificate is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
33351
- case 1:
33352
- return _context1.a(2);
33353
- }
33354
- }, _callee1);
33355
- }));
33356
- return function requestCertificateOnPremise() {
33357
- return _ref1.apply(this, arguments);
33358
- };
33359
- }();
33360
-
33361
- /**
33362
- * Requests a certificate for the user.
33363
- * @param {CertificateRequestParams} params - The parameters for the certificate request.
33364
- * @returns {Promise<RequestCertificateResponse>} Object with a confirmation message and a success indicator.
33365
- * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
33366
- * @throws {Error} If the request fails for another reason or the params are invalid.
33367
- */
33368
- var requestCertificate = /*#__PURE__*/function () {
33369
- var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(params) {
33370
- var _getConfig4, integrationType;
33371
- return _regenerator().w(function (_context10) {
33372
- while (1) switch (_context10.n) {
33373
- case 0:
33374
- if (!(!params || typeof params.type !== "number" || !Array.isArray(params.documents))) {
33375
- _context10.n = 1;
33376
- break;
33377
- }
33378
- throw new Error('The "params" object with a numeric "type" property and a "documents" array is required.');
33379
- case 1:
33380
- _getConfig4 = getConfig(), integrationType = _getConfig4.integrationType;
33381
- if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
33382
- _context10.n = 2;
33383
- break;
33384
- }
33385
- return _context10.a(2, requestCertificateOnBoarding(params));
33386
- case 2:
33387
- if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
33388
- _context10.n = 3;
33389
- break;
33390
- }
33391
- return _context10.a(2, requestCertificateOnPremise());
33392
- case 3:
33393
- throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
33394
- case 4:
33395
- return _context10.a(2);
33396
- }
33397
- }, _callee10);
33398
- }));
33399
- return function requestCertificate(_x6) {
33400
- return _ref10.apply(this, arguments);
33401
- };
33402
- }();
33403
33378
 
33404
33379
  /** @typedef {import("../types/signatures").Signer} Signer */
33405
33380
  /** @typedef {import("../types/signatures").SignerData} SignerData */
@@ -33418,27 +33393,15 @@ var requestCertificate = /*#__PURE__*/function () {
33418
33393
 
33419
33394
  var signDocumentOnBoarding = /*#__PURE__*/function () {
33420
33395
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(signData) {
33421
- var signature, cert, signedDigest, signBody, response, _t;
33396
+ var payload, signature, response, _t;
33422
33397
  return _regenerator().w(function (_context) {
33423
33398
  while (1) switch (_context.p = _context.n) {
33424
33399
  case 0:
33425
- helpers.validateOnBoardingSignDocumentData(signData);
33426
- signature = signData.signature, cert = signData.cert, signedDigest = signData.signedDigest;
33400
+ payload = helpers.validateOnBoardingSignDocumentData(signData);
33401
+ signature = signData.signature;
33427
33402
  _context.p = 1;
33428
- signBody = {
33429
- positions: JSON.stringify(signature.positions.map(function (p) {
33430
- return {
33431
- x: p.x,
33432
- y: p.y,
33433
- page: p.page,
33434
- status: 1
33435
- };
33436
- })),
33437
- publickey: cert,
33438
- signeddigest: signedDigest
33439
- };
33440
33403
  _context.n = 2;
33441
- return httpRequest("services/api/documents/sign/".concat(signature.id), signBody, "PUT");
33404
+ return httpRequest("services/api/documents/sign/".concat(signature.id), payload, "PUT");
33442
33405
  case 2:
33443
33406
  response = _context.v;
33444
33407
  return _context.a(2, new ApacuanaSuccess(response));
@@ -33478,15 +33441,14 @@ var signDocumentOnPremise = /*#__PURE__*/function () {
33478
33441
  }();
33479
33442
  var getDigestToSignOnBoarding = /*#__PURE__*/function () {
33480
33443
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(signData) {
33481
- var _response$data, response, digest, _t2;
33444
+ var _response$data, formData, response, digest, _t2;
33482
33445
  return _regenerator().w(function (_context3) {
33483
33446
  while (1) switch (_context3.p = _context3.n) {
33484
33447
  case 0:
33485
33448
  _context3.p = 0;
33449
+ formData = helpers.createPayloadGetDigest(signData);
33486
33450
  _context3.n = 1;
33487
- return httpRequest("services/api/documents/getdigest/".concat(signData.signatureId), {
33488
- publickey: signData.cert
33489
- }, "POST");
33451
+ return httpRequest("services/api/documents/getdigest/".concat(signData.signatureId), formData, "POST");
33490
33452
  case 1:
33491
33453
  response = _context3.v;
33492
33454
  digest = ((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.digest) || response.digest;
@@ -33535,14 +33497,14 @@ var getDigestToSignOnPremise = /*#__PURE__*/function () {
33535
33497
  }();
33536
33498
  var addSignerOnBoarding = /*#__PURE__*/function () {
33537
33499
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(signerData) {
33538
- var _t3;
33500
+ var payload, _t3;
33539
33501
  return _regenerator().w(function (_context5) {
33540
33502
  while (1) switch (_context5.p = _context5.n) {
33541
33503
  case 0:
33542
- helpers.validateOnBoardingSignerData(signerData);
33504
+ payload = helpers.validateOnBoardingSignerData(signerData);
33543
33505
  _context5.p = 1;
33544
33506
  _context5.n = 2;
33545
- return httpRequest("services/api/documents/signing", signerData, "POST");
33507
+ return httpRequest("services/api/documents/signingsdk", payload, "POST");
33546
33508
  case 2:
33547
33509
  return _context5.a(2, new ApacuanaSuccess({
33548
33510
  signer: signerData.typedoc + signerData.doc
@@ -34348,9 +34310,6 @@ var apacuana = {
34348
34310
  }
34349
34311
  return init;
34350
34312
  }(),
34351
- /**
34352
- * Permite obtener la configuración actual del SDK.
34353
- */
34354
34313
  close: function close$1() {
34355
34314
  return close();
34356
34315
  },
@@ -34370,8 +34329,8 @@ var apacuana = {
34370
34329
  getCertTypes: getCertTypes,
34371
34330
  getRequerimentsByTypeUser: getRequerimentsByTypeUser,
34372
34331
  createFaceLivenessSession: createFaceLivenessSession,
34373
- validateFaceLiveness: validateFaceLiveness,
34374
- requestCertificate: requestCertificate
34332
+ validateFaceLiveness: validateFaceLiveness
34333
+ // requestCertificate,
34375
34334
  };
34376
34335
 
34377
34336
  export { apacuana as default };