apacuana-sdk-core 0.15.0 → 0.17.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 (32) hide show
  1. package/README.md +30 -100
  2. package/coverage/clover.xml +150 -147
  3. package/coverage/coverage-final.json +2 -2
  4. package/coverage/lcov-report/index.html +13 -13
  5. package/coverage/lcov-report/src/api/certs.js.html +6 -3
  6. package/coverage/lcov-report/src/api/faceLiveness.js.html +1 -1
  7. package/coverage/lcov-report/src/api/index.html +1 -1
  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 +1 -1
  15. package/coverage/lcov-report/src/index.html +1 -1
  16. package/coverage/lcov-report/src/index.js.html +1 -1
  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 +112 -40
  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 +312 -311
  24. package/dist/index.js +18 -13
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +18 -13
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/utils/helpers.d.ts +1 -1
  29. package/package.json +1 -1
  30. package/src/api/certs.js +2 -1
  31. package/src/utils/helpers.js +54 -30
  32. package/tests/api/certs.test.js +6 -2
@@ -11,7 +11,7 @@ declare namespace _default {
11
11
  export { createPayloadGetDigest };
12
12
  }
13
13
  export default _default;
14
- declare function getCertificateStatus(userData: any, certificateInDevice: any): any;
14
+ declare function getCertificateStatus(userData: any, certificateInDevice: any, integrationType: any): string;
15
15
  declare function exportPrivateKey(key: any): Promise<string>;
16
16
  declare function arrayBufferToBase64(buffer: any): string;
17
17
  declare function encryptedCsr(csr: any, encryptKey?: string): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apacuana-sdk-core",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Core SDK para interacciones con las APIs de Apacuana.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/api/certs.js CHANGED
@@ -86,7 +86,8 @@ export const getCertStatus = (isCertificateInDevice = false) => {
86
86
  const config = getConfig();
87
87
  const status = helpers.getCertificateStatus(
88
88
  config.userData,
89
- isCertificateInDevice
89
+ isCertificateInDevice,
90
+ config.integrationType
90
91
  );
91
92
  const parseStatus = PARSE_STATUS[status];
92
93
 
@@ -1,46 +1,70 @@
1
1
  import CryptoJS from "crypto-js";
2
2
  import { getCrypto } from "pkijs";
3
- import { STATUS_CERTIFICATE, VERIFICATION_STATUS } from "./constant";
3
+ import {
4
+ INTEGRATION_TYPE,
5
+ STATUS_CERTIFICATE,
6
+ VERIFICATION_STATUS,
7
+ } from "./constant";
4
8
  import { ApacuanaAPIError } from "../errors/index";
5
9
 
6
10
  const KEY_HEX = "dRgUkXp2s5v8y/B?";
7
11
 
8
- const getCertificateStatus = (userData, certificateInDevice) => {
12
+ const getCertificateStatus = (
13
+ userData,
14
+ certificateInDevice,
15
+ integrationType
16
+ ) => {
9
17
  if (!userData) {
10
- throw new Error("El parámetro userData es requerido.");
18
+ throw new ApacuanaAPIError(
19
+ "El parámetro userData es requerido.",
20
+ 404,
21
+ "INVALID_USER_DATA"
22
+ );
11
23
  }
12
24
  if (typeof certificateInDevice !== "boolean") {
13
- throw new Error(
14
- "El parámetro certificateInDevice es requerido y debe ser un valor booleano."
25
+ throw new ApacuanaAPIError(
26
+ "El parámetro certificateInDevice es requerido y debe ser un valor booleano.",
27
+ 404,
28
+ "INVALID_CERTIFICATE_IN_DEVICE"
15
29
  );
16
30
  }
17
31
 
18
- if (userData?.verificationstatus?.id !== VERIFICATION_STATUS.APPROVED)
19
- return STATUS_CERTIFICATE.request;
20
- if (
21
- !userData?.certificationId &&
22
- userData?.requestscert?.requests.length === 0
23
- )
24
- return STATUS_CERTIFICATE.request_cert;
25
- if (
26
- userData?.certificationId &&
27
- !userData?.cangenerate &&
28
- !userData?.requestscert?.pending &&
29
- !certificateInDevice &&
30
- userData?.certificatestatus !== STATUS_CERTIFICATE.revoque
31
- )
32
- return STATUS_CERTIFICATE.certificate_another_device;
33
- if (userData?.requestscert?.pending && userData?.certificationId)
34
- return STATUS_CERTIFICATE.request_revoque;
35
- if (
36
- !userData?.cangenerate &&
37
- userData?.certificatestatus === STATUS_CERTIFICATE.revoque
38
- )
39
- return STATUS_CERTIFICATE.revoque;
40
- if (userData?.cangenerate) return STATUS_CERTIFICATE.generate;
41
- if (userData?.certificationId) return STATUS_CERTIFICATE.current;
32
+ if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
33
+ if (userData?.verificationstatus?.id !== VERIFICATION_STATUS.APPROVED)
34
+ return STATUS_CERTIFICATE.request;
35
+ if (
36
+ userData?.certifiedid &&
37
+ !userData?.certificatestatus?.cangenerate &&
38
+ !userData?.requestscert?.pending &&
39
+ !certificateInDevice &&
40
+ userData?.certificatestatus !== STATUS_CERTIFICATE.revoque
41
+ )
42
+ return STATUS_CERTIFICATE.certificate_another_device;
43
+ if (userData?.requestscert?.pending)
44
+ return STATUS_CERTIFICATE.request_revoque;
45
+ if (
46
+ !userData?.certificatestatus?.cangenerate &&
47
+ userData?.certificatestatus === STATUS_CERTIFICATE.revoque
48
+ )
49
+ return STATUS_CERTIFICATE.revoque;
50
+ if (userData?.certificatestatus?.cangenerate)
51
+ return STATUS_CERTIFICATE.generate;
52
+ if (userData?.certifiedid) return STATUS_CERTIFICATE.current;
42
53
 
43
- return STATUS_CERTIFICATE.revoque;
54
+ return STATUS_CERTIFICATE.revoque;
55
+ }
56
+ if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
57
+ throw new ApacuanaAPIError(
58
+ "Getting certificate status is not supported for integration type: ONPREMISE",
59
+ 501,
60
+ "NOT_IMPLEMENTED"
61
+ );
62
+ }
63
+ throw new ApacuanaAPIError(
64
+ `Unsupported integration type: ${integrationType}`,
65
+ 400,
66
+ "UNSUPPORTED_INTEGRATION_TYPE"
67
+ );
44
68
  };
45
69
 
46
70
  // Función para convertir ArrayBuffer a Base64
@@ -86,14 +86,18 @@ describe("Certificate API - certs.js", () => {
86
86
  describe("getCertStatus", () => {
87
87
  it("should return the certificate status from helpers", () => {
88
88
  const mockUserData = { certStatus: "SOLICITUD" };
89
- getConfig.mockReturnValue({ userData: mockUserData });
89
+ getConfig.mockReturnValue({
90
+ userData: mockUserData,
91
+ integrationType: INTEGRATION_TYPE.ONBOARDING,
92
+ });
90
93
  helpers.getCertificateStatus.mockReturnValue("SOLICITUD");
91
94
 
92
95
  const result = getCertStatus(true);
93
96
 
94
97
  expect(helpers.getCertificateStatus).toHaveBeenCalledWith(
95
98
  mockUserData,
96
- true
99
+ true,
100
+ INTEGRATION_TYPE.ONBOARDING
97
101
  );
98
102
  expect(result).toBeInstanceOf(ApacuanaSuccess);
99
103