apacuana-sdk-core 1.24.0 → 1.25.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 +39 -27
  2. package/coverage/clover.xml +195 -214
  3. package/coverage/coverage-final.json +5 -5
  4. package/coverage/lcov-report/index.html +33 -33
  5. package/coverage/lcov-report/src/api/certs.js.html +1 -1
  6. package/coverage/lcov-report/src/api/faceLiveness.js.html +35 -269
  7. package/coverage/lcov-report/src/api/index.html +18 -18
  8. package/coverage/lcov-report/src/api/revocations.js.html +1 -1
  9. package/coverage/lcov-report/src/api/signatures.js.html +1 -1
  10. package/coverage/lcov-report/src/api/users.js.html +1 -1
  11. package/coverage/lcov-report/src/config/index.html +1 -1
  12. package/coverage/lcov-report/src/config/index.js.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.html +1 -1
  14. package/coverage/lcov-report/src/errors/index.js.html +8 -8
  15. package/coverage/lcov-report/src/index.html +15 -15
  16. package/coverage/lcov-report/src/index.js.html +12 -42
  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 +59 -8
  21. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  22. package/coverage/lcov-report/src/utils/index.html +12 -12
  23. package/coverage/lcov.info +398 -434
  24. package/dist/api/faceLiveness.d.ts +3 -4
  25. package/dist/index.d.ts +1 -2
  26. package/dist/index.js +61 -165
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +61 -165
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/types/faceLiveness.d.ts +0 -10
  31. package/dist/utils/helpers.d.ts +2 -0
  32. package/package.json +1 -1
  33. package/src/api/faceLiveness.js +20 -98
  34. package/src/index.js +4 -14
  35. package/src/types/faceLiveness.js +1 -12
  36. package/src/utils/helpers.js +17 -0
  37. package/tests/api/faceLiveness.test.js +54 -115
@@ -1,6 +1,5 @@
1
- export function createFaceLivenessSession(): Promise<CreateFaceLivenessSessionResponse>;
2
- export function validateFaceLiveness({ sessionId }: {
3
- sessionId: string;
1
+ export function sendFaceLiveness({ faceLiveness, documentprefid }: {
2
+ faceLiveness: string;
3
+ documentprefid: string;
4
4
  }): Promise<ApacuanaSuccess>;
5
- export type CreateFaceLivenessSessionResponse = import("../types/faceLiveness").CreateFaceLivenessSessionResponse;
6
5
  import ApacuanaSuccess from "../success";
package/dist/index.d.ts CHANGED
@@ -15,9 +15,8 @@ declare namespace apacuana {
15
15
  export function signDocument(data: any): Promise<object>;
16
16
  export function uploadSignatureVariant(data: any): Promise<object>;
17
17
  export function getCustomer(): Promise<import("./api/users").GetCustomerResponse>;
18
- export function createFaceLivenessSession(): Promise<import("./types/faceLiveness").CreateFaceLivenessSessionResponse>;
19
18
  export function createApacuanaUser(data: any): Promise<ApacuanaSuccess>;
20
- export function validateFaceLiveness(data: any): Promise<ApacuanaSuccess>;
19
+ export function sendFaceLiveness(data: any): Promise<ApacuanaSuccess>;
21
20
  export function close(): void;
22
21
  export { getConfig };
23
22
  }
package/dist/index.js CHANGED
@@ -33041,6 +33041,22 @@ var validateOnBoardingSignDocumentData = function validateOnBoardingSignDocument
33041
33041
  }
33042
33042
  return formData;
33043
33043
  };
33044
+ var base64ToFile = function base64ToFile(dataurl, filename) {
33045
+ var arr = dataurl.split(",");
33046
+ var mime = arr[0].match(/:(.*?);/)[1];
33047
+ var bstr = atob(arr[1]);
33048
+ var n = bstr.length;
33049
+ var u8arr = new Uint8Array(n);
33050
+ while (n--) {
33051
+ u8arr[n] = bstr.charCodeAt(n);
33052
+ }
33053
+ var blob = new Blob([u8arr], {
33054
+ type: mime
33055
+ });
33056
+ return new File([blob], filename, {
33057
+ type: mime
33058
+ });
33059
+ };
33044
33060
  var helpers = {
33045
33061
  getCertificateStatus: getCertificateStatus,
33046
33062
  exportPrivateKey: exportPrivateKey,
@@ -33051,7 +33067,8 @@ var helpers = {
33051
33067
  validateGetDocsData: validateGetDocsData,
33052
33068
  validateGetDigestData: validateGetDigestData,
33053
33069
  validateOnBoardingSignDocumentData: validateOnBoardingSignDocumentData,
33054
- createPayloadGetDigest: createPayloadGetDigest
33070
+ createPayloadGetDigest: createPayloadGetDigest,
33071
+ base64ToFile: base64ToFile
33055
33072
  };
33056
33073
 
33057
33074
  /**
@@ -34212,213 +34229,101 @@ var deleteSignatureVariant = /*#__PURE__*/function () {
34212
34229
  };
34213
34230
  }();
34214
34231
 
34215
- /**
34216
- * Creates a new Face Liveness session.
34217
- * @returns {Promise<CreateFaceLivenessSessionResponse>} Object with the session ID and a success indicator.
34218
- * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
34219
- * @throws {Error} If the request fails for another reason.
34220
- */
34221
- var createFaceLivenessSessionOnBoarding = /*#__PURE__*/function () {
34222
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
34223
- var response, _t;
34232
+ var sendFaceLivenessOnBoarding = /*#__PURE__*/function () {
34233
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(faceliveness, documentprefid) {
34234
+ var file, response, _t;
34224
34235
  return _regenerator().w(function (_context) {
34225
34236
  while (1) switch (_context.p = _context.n) {
34226
34237
  case 0:
34227
34238
  _context.p = 0;
34239
+ file = helpers.base64ToFile(faceliveness, "liveness_capture_".concat(Date.now(), ".png"));
34228
34240
  _context.n = 1;
34229
- return httpRequest("services/api/faceliveness/create", {}, "POST");
34241
+ return httpRequest("services/api/faceliveness/uploadfaceliveness", {
34242
+ faceliveness: file,
34243
+ documentprefid: documentprefid
34244
+ }, "POST");
34230
34245
  case 1:
34231
34246
  response = _context.v;
34232
- if (response.sessionid) {
34233
- _context.n = 2;
34234
- break;
34235
- }
34236
- throw new ApacuanaAPIError("The API response does not contain the session ID.", response.status, "INVALID_API_RESPONSE");
34247
+ return _context.a(2, new ApacuanaSuccess(_objectSpread2({
34248
+ status: "verified"
34249
+ }, response)));
34237
34250
  case 2:
34238
- return _context.a(2, new ApacuanaSuccess({
34239
- sessionId: response.sessionid
34240
- }));
34241
- case 3:
34242
- _context.p = 3;
34251
+ _context.p = 2;
34243
34252
  _t = _context.v;
34244
34253
  if (!(_t instanceof ApacuanaAPIError)) {
34245
- _context.n = 4;
34254
+ _context.n = 3;
34246
34255
  break;
34247
34256
  }
34248
34257
  throw _t;
34258
+ case 3:
34259
+ throw new Error("Failed to send faceliveness: ".concat(_t.message));
34249
34260
  case 4:
34250
- throw new ApacuanaAPIError("Failed to create Face Liveness session: ".concat(_t.message));
34251
- case 5:
34252
34261
  return _context.a(2);
34253
34262
  }
34254
- }, _callee, null, [[0, 3]]);
34263
+ }, _callee, null, [[0, 2]]);
34255
34264
  }));
34256
- return function createFaceLivenessSessionOnBoarding() {
34265
+ return function sendFaceLivenessOnBoarding(_x, _x2) {
34257
34266
  return _ref.apply(this, arguments);
34258
34267
  };
34259
34268
  }();
34260
- var createFaceLivenessSessionOnPremise = /*#__PURE__*/function () {
34269
+ var sendFaceLivenessOnPremise = /*#__PURE__*/function () {
34261
34270
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
34262
34271
  return _regenerator().w(function (_context2) {
34263
34272
  while (1) switch (_context2.n) {
34264
34273
  case 0:
34265
- throw new ApacuanaAPIError("Creating a Face Liveness session is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
34274
+ throw new ApacuanaAPIError("Send a Face Liveness is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
34266
34275
  case 1:
34267
34276
  return _context2.a(2);
34268
34277
  }
34269
34278
  }, _callee2);
34270
34279
  }));
34271
- return function createFaceLivenessSessionOnPremise() {
34280
+ return function sendFaceLivenessOnPremise() {
34272
34281
  return _ref2.apply(this, arguments);
34273
34282
  };
34274
34283
  }();
34275
- var validateFaceLivenessOnBoarding = /*#__PURE__*/function () {
34276
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(sessionId) {
34277
- var response, status, _t2, _t3;
34278
- return _regenerator().w(function (_context3) {
34279
- while (1) switch (_context3.p = _context3.n) {
34280
- case 0:
34281
- _context3.p = 0;
34282
- _context3.n = 1;
34283
- return httpRequest("services/api/faceliveness/validate", {
34284
- sessionid: sessionId
34285
- }, "POST");
34286
- case 1:
34287
- response = _context3.v;
34288
- return _context3.a(2, new ApacuanaSuccess(_objectSpread2({
34289
- status: "verified"
34290
- }, response)));
34291
- case 2:
34292
- _context3.p = 2;
34293
- _t2 = _context3.v;
34294
- if (!(_t2 instanceof ApacuanaAPIError)) {
34295
- _context3.n = 9;
34296
- break;
34297
- }
34298
- _t3 = _t2.statusCode;
34299
- _context3.n = _t3 === 402 ? 3 : _t3 === 403 ? 4 : _t3 === 406 ? 5 : _t3 === 408 ? 6 : 7;
34300
- break;
34301
- case 3:
34302
- status = "waitingForScan";
34303
- return _context3.a(3, 8);
34304
- case 4:
34305
- status = "rejected";
34306
- return _context3.a(3, 8);
34307
- case 5:
34308
- status = "processing";
34309
- return _context3.a(3, 8);
34310
- case 6:
34311
- status = "expired";
34312
- return _context3.a(3, 8);
34313
- case 7:
34314
- throw _t2;
34315
- case 8:
34316
- return _context3.a(2, new ApacuanaSuccess({
34317
- status: status
34318
- }));
34319
- case 9:
34320
- throw _t2;
34321
- case 10:
34322
- return _context3.a(2);
34323
- }
34324
- }, _callee3, null, [[0, 2]]);
34325
- }));
34326
- return function validateFaceLivenessOnBoarding(_x) {
34327
- return _ref3.apply(this, arguments);
34328
- };
34329
- }();
34330
- var validateFaceLivenessOnPremise = /*#__PURE__*/function () {
34331
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
34332
- return _regenerator().w(function (_context4) {
34333
- while (1) switch (_context4.n) {
34334
- case 0:
34335
- throw new ApacuanaAPIError("Validating a Face Liveness session is not supported for integration type: ONPREMISE", 501, "NOT_IMPLEMENTED");
34336
- case 1:
34337
- return _context4.a(2);
34338
- }
34339
- }, _callee4);
34340
- }));
34341
- return function validateFaceLivenessOnPremise() {
34342
- return _ref4.apply(this, arguments);
34343
- };
34344
- }();
34345
-
34346
- /**
34347
- * Creates a new Face Liveness session.
34348
- * @returns {Promise<CreateFaceLivenessSessionResponse>} Object with the session ID and a success indicator.
34349
- * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
34350
- * @throws {Error} If the request fails for another reason.
34351
- */
34352
- var createFaceLivenessSession = /*#__PURE__*/function () {
34353
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
34354
- var _getConfig, integrationType;
34355
- return _regenerator().w(function (_context5) {
34356
- while (1) switch (_context5.n) {
34357
- case 0:
34358
- _getConfig = getConfig(), integrationType = _getConfig.integrationType;
34359
- if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
34360
- _context5.n = 1;
34361
- break;
34362
- }
34363
- return _context5.a(2, createFaceLivenessSessionOnBoarding());
34364
- case 1:
34365
- if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
34366
- _context5.n = 2;
34367
- break;
34368
- }
34369
- return _context5.a(2, createFaceLivenessSessionOnPremise());
34370
- case 2:
34371
- throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
34372
- case 3:
34373
- return _context5.a(2);
34374
- }
34375
- }, _callee5);
34376
- }));
34377
- return function createFaceLivenessSession() {
34378
- return _ref5.apply(this, arguments);
34379
- };
34380
- }();
34381
34284
 
34382
34285
  /**
34383
34286
  * Validates a Face Liveness session and returns its status.
34384
- * @param {{sessionId: string}} params - Object containing the session ID.
34287
+ * @param {object} params - Parámetros para la solicitud.
34288
+ * @param {string} params.faceLiveness - El faceLiveness.
34289
+ * @param {string} params.documentprefid - El documentprefid.
34385
34290
  * @returns {Promise<ApacuanaSuccess>} Object with the validation status.
34386
34291
  * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
34387
34292
  */
34388
- var validateFaceLiveness = /*#__PURE__*/function () {
34389
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref6) {
34390
- var sessionId, _getConfig2, integrationType;
34391
- return _regenerator().w(function (_context6) {
34392
- while (1) switch (_context6.n) {
34293
+ var sendFaceLiveness = /*#__PURE__*/function () {
34294
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_ref3) {
34295
+ var faceLiveness, documentprefid, _getConfig, integrationType;
34296
+ return _regenerator().w(function (_context3) {
34297
+ while (1) switch (_context3.n) {
34393
34298
  case 0:
34394
- sessionId = _ref6.sessionId;
34395
- if (sessionId) {
34396
- _context6.n = 1;
34299
+ faceLiveness = _ref3.faceLiveness, documentprefid = _ref3.documentprefid;
34300
+ if (!(!faceLiveness || !documentprefid)) {
34301
+ _context3.n = 1;
34397
34302
  break;
34398
34303
  }
34399
- throw new ApacuanaAPIError("sessionId is a required parameter.", 400, "INVALID_PARAMETER");
34304
+ throw new ApacuanaAPIError("faceLiveness and documentprefid is a required parameter.", 400, "INVALID_PARAMETER");
34400
34305
  case 1:
34401
- _getConfig2 = getConfig(), integrationType = _getConfig2.integrationType;
34306
+ _getConfig = getConfig(), integrationType = _getConfig.integrationType;
34402
34307
  if (!(integrationType === INTEGRATION_TYPE.ONBOARDING)) {
34403
- _context6.n = 2;
34308
+ _context3.n = 2;
34404
34309
  break;
34405
34310
  }
34406
- return _context6.a(2, validateFaceLivenessOnBoarding(sessionId));
34311
+ return _context3.a(2, sendFaceLivenessOnBoarding(faceLiveness, documentprefid));
34407
34312
  case 2:
34408
34313
  if (!(integrationType === INTEGRATION_TYPE.ONPREMISE)) {
34409
- _context6.n = 3;
34314
+ _context3.n = 3;
34410
34315
  break;
34411
34316
  }
34412
- return _context6.a(2, validateFaceLivenessOnPremise());
34317
+ return _context3.a(2, sendFaceLivenessOnPremise());
34413
34318
  case 3:
34414
34319
  throw new ApacuanaAPIError("Unsupported integration type: ".concat(integrationType), 400, "UNSUPPORTED_INTEGRATION_TYPE");
34415
34320
  case 4:
34416
- return _context6.a(2);
34321
+ return _context3.a(2);
34417
34322
  }
34418
- }, _callee6);
34323
+ }, _callee3);
34419
34324
  }));
34420
- return function validateFaceLiveness(_x2) {
34421
- return _ref7.apply(this, arguments);
34325
+ return function sendFaceLiveness(_x3) {
34326
+ return _ref4.apply(this, arguments);
34422
34327
  };
34423
34328
  }();
34424
34329
 
@@ -34554,23 +34459,14 @@ var apacuana = {
34554
34459
  checkSdk(true);
34555
34460
  return getCustomer();
34556
34461
  },
34557
- createFaceLivenessSession: function createFaceLivenessSession$1() {
34558
- checkSdk(true);
34559
- return createFaceLivenessSession();
34560
- },
34561
34462
  createApacuanaUser: function createApacuanaUser$1(data) {
34562
34463
  checkSdk(false);
34563
34464
  return createApacuanaUser(data);
34564
34465
  },
34565
- validateFaceLiveness: function validateFaceLiveness$1(data) {
34466
+ sendFaceLiveness: function sendFaceLiveness$1(data) {
34566
34467
  checkSdk(true);
34567
- return validateFaceLiveness(data);
34468
+ return sendFaceLiveness(data);
34568
34469
  },
34569
- // validateCertificate: (data) => {
34570
- // checkSdk(true);
34571
- // validateCertificate(data);
34572
- // },
34573
-
34574
34470
  close: function close$1() {
34575
34471
  return close();
34576
34472
  },