apacuana-sdk-core 0.11.0 → 0.12.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 (42) hide show
  1. package/coverage/clover.xml +117 -114
  2. package/coverage/coverage-final.json +6 -6
  3. package/coverage/lcov-report/index.html +12 -12
  4. package/coverage/lcov-report/src/api/certs.js.html +1 -1
  5. package/coverage/lcov-report/src/api/faceLiveness.js.html +34 -7
  6. package/coverage/lcov-report/src/api/index.html +1 -1
  7. package/coverage/lcov-report/src/api/revocations.js.html +50 -5
  8. package/coverage/lcov-report/src/api/signatures.js.html +1 -1
  9. package/coverage/lcov-report/src/api/users.js.html +20 -5
  10. package/coverage/lcov-report/src/config/index.html +1 -1
  11. package/coverage/lcov-report/src/config/index.js.html +1 -1
  12. package/coverage/lcov-report/src/errors/index.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.js.html +8 -8
  14. package/coverage/lcov-report/src/index.html +13 -13
  15. package/coverage/lcov-report/src/index.js.html +72 -12
  16. package/coverage/lcov-report/src/success/index.html +1 -1
  17. package/coverage/lcov-report/src/success/index.js.html +5 -5
  18. package/coverage/lcov-report/src/utils/constant.js.html +1 -1
  19. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  20. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  21. package/coverage/lcov-report/src/utils/index.html +1 -1
  22. package/coverage/lcov.info +195 -188
  23. package/dist/api/revocations.d.ts +6 -3
  24. package/dist/api/users.d.ts +16 -6
  25. package/dist/index.js +58 -15
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +58 -15
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/types/faceLiveness.d.ts +6 -5
  30. package/dist/types/revocations.d.ts +26 -15
  31. package/dist/types/signatures.d.ts +60 -65
  32. package/package.json +1 -1
  33. package/src/api/faceLiveness.js +13 -4
  34. package/src/api/revocations.js +18 -3
  35. package/src/api/users.js +8 -3
  36. package/src/index.js +25 -5
  37. package/src/types/faceLiveness.js +11 -2
  38. package/src/types/revocations.js +29 -9
  39. package/src/types/signatures.js +42 -28
  40. package/tests/api/faceLiveness.test.js +28 -30
  41. package/tests/api/revocations.test.js +4 -4
  42. package/tests/index.test.js +16 -8
@@ -1,8 +1,11 @@
1
- import * as faceLiveness from "../../src/api/faceLiveness";
1
+ import {
2
+ createFaceLivenessSession,
3
+ validateFaceLiveness,
4
+ } from "../../src/api/faceLiveness";
2
5
  import { httpRequest } from "../../src/utils/httpClient";
3
- import { getConfig } from "../../src/config";
4
- import { ApacuanaAPIError } from "../../src/errors";
5
6
  import ApacuanaSuccess from "../../src/success";
7
+ import { setConfig, getConfig } from "../../src/config";
8
+ import { ApacuanaAPIError } from "../../src/errors";
6
9
  import { INTEGRATION_TYPE } from "../../src/utils/constant";
7
10
 
8
11
  jest.mock("../../src/utils/httpClient", () => ({
@@ -11,6 +14,7 @@ jest.mock("../../src/utils/httpClient", () => ({
11
14
 
12
15
  jest.mock("../../src/config", () => ({
13
16
  getConfig: jest.fn(),
17
+ setConfig: jest.fn(),
14
18
  }));
15
19
 
16
20
  describe("FaceLiveness API", () => {
@@ -21,23 +25,25 @@ describe("FaceLiveness API", () => {
21
25
 
22
26
  describe("createFaceLivenessSession", () => {
23
27
  it("should create a session for ONBOARDING integration", async () => {
24
- httpRequest.mockResolvedValue({ sessionId: "test-session-id" });
28
+ const mockSessionId = "session-onboarding-123";
29
+ httpRequest.mockResolvedValue({ sessionid: mockSessionId });
30
+ setConfig({ onboardingId: "some-onboarding-id" });
25
31
 
26
- const result = await faceLiveness.createFaceLivenessSession();
32
+ const result = await createFaceLivenessSession();
27
33
 
28
- expect(result).toBeInstanceOf(ApacuanaSuccess);
29
- expect(result.data).toEqual({ sessionId: "test-session-id" });
30
34
  expect(httpRequest).toHaveBeenCalledWith(
31
35
  "services/api/faceliveness/create",
32
36
  {},
33
37
  "POST"
34
38
  );
39
+ expect(result).toBeInstanceOf(ApacuanaSuccess);
40
+ expect(result.data).toEqual({ sessionId: mockSessionId });
35
41
  });
36
42
 
37
- it("should throw an error if API response does not contain sessionId for ONBOARDING", async () => {
43
+ it("should throw an error if session ID is missing for ONBOARDING", async () => {
38
44
  httpRequest.mockResolvedValue({}); // No sessionId
39
45
 
40
- await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
46
+ await expect(createFaceLivenessSession()).rejects.toThrow(
41
47
  new ApacuanaAPIError(
42
48
  "The API response does not contain the session ID.",
43
49
  undefined,
@@ -51,7 +57,7 @@ describe("FaceLiveness API", () => {
51
57
  integrationType: INTEGRATION_TYPE.ONPREMISE,
52
58
  });
53
59
 
54
- await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
60
+ await expect(createFaceLivenessSession()).rejects.toThrow(
55
61
  new ApacuanaAPIError(
56
62
  "Creating a Face Liveness session is not supported for integration type: ONPREMISE",
57
63
  501,
@@ -63,7 +69,7 @@ describe("FaceLiveness API", () => {
63
69
  it("should throw an UNSUPPORTED_INTEGRATION_TYPE error for unsupported integration types", async () => {
64
70
  getConfig.mockReturnValue({ integrationType: "unsupported-type" });
65
71
 
66
- await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
72
+ await expect(createFaceLivenessSession()).rejects.toThrow(
67
73
  new ApacuanaAPIError(
68
74
  "Unsupported integration type: unsupported-type",
69
75
  400,
@@ -76,16 +82,14 @@ describe("FaceLiveness API", () => {
76
82
  const apiError = new ApacuanaAPIError("API Error", 500, "API_ERROR");
77
83
  httpRequest.mockRejectedValue(apiError);
78
84
 
79
- await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
80
- apiError
81
- );
85
+ await expect(createFaceLivenessSession()).rejects.toThrow(apiError);
82
86
  });
83
87
 
84
88
  it("should throw a generic error for other failures during session creation", async () => {
85
89
  const genericError = new Error("Network Error");
86
90
  httpRequest.mockRejectedValue(genericError);
87
91
 
88
- await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
92
+ await expect(createFaceLivenessSession()).rejects.toThrow(
89
93
  `Failed to create Face Liveness session: ${genericError.message}`
90
94
  );
91
95
  });
@@ -95,7 +99,7 @@ describe("FaceLiveness API", () => {
95
99
  const sessionId = "test-session-id";
96
100
 
97
101
  it("should throw an error if sessionId is not provided", async () => {
98
- await expect(faceLiveness.validateFaceLiveness({})).rejects.toThrow(
102
+ await expect(validateFaceLiveness({})).rejects.toThrow(
99
103
  new ApacuanaAPIError(
100
104
  "sessionId is a required parameter.",
101
105
  400,
@@ -107,7 +111,7 @@ describe("FaceLiveness API", () => {
107
111
  it("should return 'verified' on status 200", async () => {
108
112
  httpRequest.mockResolvedValue({ someData: "data" });
109
113
 
110
- const result = await faceLiveness.validateFaceLiveness({ sessionId });
114
+ const result = await validateFaceLiveness({ sessionId });
111
115
 
112
116
  expect(result).toBeInstanceOf(ApacuanaSuccess);
113
117
  expect(result.data).toEqual({ status: "verified", someData: "data" });
@@ -126,14 +130,10 @@ describe("FaceLiveness API", () => {
126
130
  ])(
127
131
  "should return status '%s' for statusCode %i",
128
132
  async (statusCode, status) => {
129
- const apiError = new ApacuanaAPIError(
130
- "Error",
131
- statusCode,
132
- "API_ERROR"
133
- );
133
+ const apiError = new ApacuanaAPIError("Error", statusCode, "API_ERROR");
134
134
  httpRequest.mockRejectedValue(apiError);
135
135
 
136
- const result = await faceLiveness.validateFaceLiveness({ sessionId });
136
+ const result = await validateFaceLiveness({ sessionId });
137
137
 
138
138
  expect(result).toBeInstanceOf(ApacuanaSuccess);
139
139
  expect(result.data).toEqual({ status });
@@ -148,9 +148,9 @@ describe("FaceLiveness API", () => {
148
148
  );
149
149
  httpRequest.mockRejectedValue(apiError);
150
150
 
151
- await expect(
152
- faceLiveness.validateFaceLiveness({ sessionId })
153
- ).rejects.toThrow(apiError);
151
+ await expect(validateFaceLiveness({ sessionId })).rejects.toThrow(
152
+ apiError
153
+ );
154
154
  });
155
155
 
156
156
  it("should throw a NOT_IMPLEMENTED error for ONPREMISE integration", async () => {
@@ -158,9 +158,7 @@ describe("FaceLiveness API", () => {
158
158
  integrationType: INTEGRATION_TYPE.ONPREMISE,
159
159
  });
160
160
 
161
- await expect(
162
- faceLiveness.validateFaceLiveness({ sessionId })
163
- ).rejects.toThrow(
161
+ await expect(validateFaceLiveness({ sessionId })).rejects.toThrow(
164
162
  new ApacuanaAPIError(
165
163
  "Validating a Face Liveness session is not supported for integration type: ONPREMISE",
166
164
  501,
@@ -169,4 +167,4 @@ describe("FaceLiveness API", () => {
169
167
  );
170
168
  });
171
169
  });
172
- });
170
+ });
@@ -35,7 +35,7 @@ describe("Revocations API", () => {
35
35
  const result = await requestRevocation(params);
36
36
 
37
37
  expect(httpRequest).toHaveBeenCalledWith(
38
- "services/api/certificate/revocation",
38
+ "services/api/onboardingclient/requestcert",
39
39
  params,
40
40
  "POST"
41
41
  );
@@ -64,18 +64,18 @@ describe("Revocations API", () => {
64
64
 
65
65
  describe("getRevocationReasons", () => {
66
66
  it("should make a GET request and return the reasons for ONBOARDING", async () => {
67
- const mockReasons = [{ code: 1, reason: "Test Reason" }];
67
+ const mockReasons = [{ code: "01", description: "Test Reason" }];
68
68
  httpRequest.mockResolvedValue({ records: mockReasons });
69
69
 
70
70
  const result = await getRevocationReasons();
71
71
 
72
72
  expect(httpRequest).toHaveBeenCalledWith(
73
- "services/api/certificate/revocation-reasons",
73
+ "config/api/revocation/reasonsonboarding",
74
74
  {},
75
75
  "GET"
76
76
  );
77
77
  expect(result).toBeInstanceOf(ApacuanaSuccess);
78
- expect(result.data).toEqual(mockReasons);
78
+ expect(result.data).toEqual({ reasons: mockReasons });
79
79
  });
80
80
 
81
81
  it("should throw an error if the API response does not contain 'records'", async () => {
@@ -1,8 +1,9 @@
1
1
  // tests/index.test.js
2
2
  import apacuana from "../src/index.js";
3
3
  import { setConfig, getConfig } from "../src/config/index.js";
4
- import { initHttpClient } from "../src/utils/httpClient.js";
4
+ import { initHttpClient, setAuthToken } from "../src/utils/httpClient.js";
5
5
  import getCustomer from "../src/api/users.js";
6
+ import ApacuanaSuccess from "../src/success/index.js";
6
7
 
7
8
  // Mockear todas las dependencias del index.js
8
9
  jest.mock("../src/config/index.js", () => ({
@@ -36,8 +37,11 @@ describe("Apacuana SDK Initialization (init)", () => {
36
37
 
37
38
  // Mockear la respuesta exitosa de getCustomer para la mayoría de las pruebas.
38
39
  getCustomer.mockResolvedValue({
39
- token: "mock-session-token",
40
- userData: { id: "mock-user-id" }
40
+ success: true,
41
+ data: {
42
+ token: "mock-session-token",
43
+ userData: { id: "mock-user-id" },
44
+ },
41
45
  });
42
46
 
43
47
  // Opcional: Mockear console.log para no ensuciar la consola durante las pruebas.
@@ -63,8 +67,12 @@ describe("Apacuana SDK Initialization (init)", () => {
63
67
  // 3. Verificar que getCustomer fue llamado.
64
68
  expect(getCustomer).toHaveBeenCalledWith();
65
69
 
66
- // 4. Verificar que se retorna true al finalizar la inicialización.
67
- expect(result).toBe(true);
70
+ // 4. Verificar que se retorna una instancia de ApacuanaSuccess al finalizar la inicialización.
71
+ expect(result).toBeInstanceOf(ApacuanaSuccess);
72
+ expect(result.data).toEqual({
73
+ initialized: true,
74
+ message: "SDK inicializado correctamente.",
75
+ });
68
76
 
69
77
  // 5. Verificar que las funciones se llamaron el número correcto de veces.
70
78
  expect(setConfig).toHaveBeenCalledTimes(2); // Una vez inicial, una vez para guardar token
@@ -113,10 +121,10 @@ describe("Apacuana SDK Initialization (init)", () => {
113
121
  expect(setConfig).toHaveBeenLastCalledWith({
114
122
  ...mockConfig,
115
123
  token: "mock-session-token",
116
- userData: { id: "mock-user-id" }
124
+ userData: { id: "mock-user-id" },
117
125
  });
118
126
 
119
- // Verificar que el token es devuelto.
120
- expect(result).toBe(true);
127
+ // Verificar que la respuesta es una instancia de ApacuanaSuccess.
128
+ expect(result).toBeInstanceOf(ApacuanaSuccess);
121
129
  });
122
130
  });