apacuana-sdk-core 0.10.0 → 0.11.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.
- package/README.md +305 -286
- package/coverage/clover.xml +337 -243
- package/coverage/coverage-final.json +9 -7
- package/coverage/lcov-report/index.html +34 -19
- package/coverage/lcov-report/src/api/certs.js.html +162 -87
- package/coverage/lcov-report/src/api/faceLiveness.js.html +496 -0
- package/coverage/lcov-report/src/api/index.html +43 -28
- package/coverage/lcov-report/src/api/revocations.js.html +103 -106
- package/coverage/lcov-report/src/api/signatures.js.html +25 -253
- package/coverage/lcov-report/src/api/users.js.html +7 -13
- package/coverage/lcov-report/src/config/index.html +1 -1
- package/coverage/lcov-report/src/config/index.js.html +1 -1
- package/coverage/lcov-report/src/errors/index.html +1 -1
- package/coverage/lcov-report/src/errors/index.js.html +8 -8
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.js.html +26 -2
- package/coverage/lcov-report/src/success/index.html +116 -0
- package/coverage/lcov-report/src/success/index.js.html +106 -0
- package/coverage/lcov-report/src/utils/constant.js.html +4 -4
- package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
- package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/coverage/lcov.info +582 -406
- package/dist/api/certs.d.ts +9 -70
- package/dist/api/faceLiveness.d.ts +6 -0
- package/dist/api/revocations.d.ts +3 -42
- package/dist/api/signatures.d.ts +11 -153
- package/dist/index.d.ts +6 -0
- package/dist/index.js +463 -252
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +463 -252
- package/dist/index.mjs.map +1 -1
- package/dist/success/index.d.ts +7 -0
- package/dist/types/certs.d.ts +97 -0
- package/dist/types/faceLiveness.d.ts +10 -0
- package/dist/types/revocations.d.ts +40 -0
- package/dist/types/signatures.d.ts +152 -0
- package/dist/types/users.d.ts +260 -0
- package/package.json +1 -1
- package/src/api/certs.js +74 -49
- package/src/api/faceLiveness.js +137 -0
- package/src/api/revocations.js +66 -67
- package/src/api/signatures.js +21 -97
- package/src/api/users.js +4 -6
- package/src/index.js +8 -0
- package/src/success/index.js +8 -0
- package/src/types/certs.js +56 -0
- package/src/types/faceLiveness.js +7 -0
- package/src/types/revocations.js +25 -0
- package/src/types/signatures.js +77 -0
- package/src/types/users.js +73 -0
- package/tests/api/certs.test.js +99 -6
- package/tests/api/faceLiveness.test.js +172 -0
- package/tests/api/revocations.test.js +37 -37
- package/tests/api/signatures.test.js +11 -5
- package/tests/api/users.test.js +3 -2
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { httpRequest } from "../../src/utils/httpClient";
|
|
2
|
-
import { ApacuanaAPIError } from "../../src/errors";
|
|
3
1
|
import {
|
|
4
2
|
requestRevocation,
|
|
5
3
|
getRevocationReasons,
|
|
6
4
|
} from "../../src/api/revocations";
|
|
5
|
+
import { httpRequest } from "../../src/utils/httpClient";
|
|
7
6
|
import { getConfig } from "../../src/config";
|
|
7
|
+
import { ApacuanaAPIError } from "../../src/errors";
|
|
8
|
+
import ApacuanaSuccess from "../../src/success";
|
|
8
9
|
import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
9
10
|
|
|
10
11
|
jest.mock("../../src/utils/httpClient");
|
|
@@ -13,67 +14,72 @@ jest.mock("../../src/config");
|
|
|
13
14
|
describe("Revocations API", () => {
|
|
14
15
|
beforeEach(() => {
|
|
15
16
|
jest.clearAllMocks();
|
|
17
|
+
getConfig.mockReturnValue({ integrationType: INTEGRATION_TYPE.ONBOARDING });
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
describe("requestRevocation", () => {
|
|
19
21
|
it("should throw an error if reasonCode is not provided", async () => {
|
|
20
22
|
await expect(requestRevocation(null)).rejects.toThrow(
|
|
21
|
-
"
|
|
23
|
+
'The "params" object with a numeric "reasonCode" property is required.'
|
|
24
|
+
);
|
|
25
|
+
await expect(requestRevocation({})).rejects.toThrow(
|
|
26
|
+
'The "params" object with a numeric "reasonCode" property is required.'
|
|
22
27
|
);
|
|
23
28
|
});
|
|
24
29
|
|
|
25
30
|
it("should make a POST request to the correct endpoint with the reasonCode", async () => {
|
|
26
|
-
const
|
|
27
|
-
const mockResponse = { success: true
|
|
31
|
+
const params = { reasonCode: 1 };
|
|
32
|
+
const mockResponse = { success: true };
|
|
28
33
|
httpRequest.mockResolvedValue(mockResponse);
|
|
29
34
|
|
|
30
|
-
const result = await requestRevocation(
|
|
35
|
+
const result = await requestRevocation(params);
|
|
31
36
|
|
|
32
37
|
expect(httpRequest).toHaveBeenCalledWith(
|
|
33
|
-
"services/api/
|
|
34
|
-
|
|
38
|
+
"services/api/certificate/revocation",
|
|
39
|
+
params,
|
|
35
40
|
"POST"
|
|
36
41
|
);
|
|
37
|
-
expect(result).
|
|
42
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
43
|
+
expect(result.data).toEqual(mockResponse);
|
|
38
44
|
});
|
|
39
45
|
|
|
40
46
|
it("should throw a generic error if the httpRequest fails", async () => {
|
|
41
|
-
const
|
|
42
|
-
const apiError = new Error("
|
|
47
|
+
const params = { reasonCode: 1 };
|
|
48
|
+
const apiError = new Error("Something went wrong");
|
|
43
49
|
httpRequest.mockRejectedValue(apiError);
|
|
44
50
|
|
|
45
|
-
await expect(requestRevocation(
|
|
46
|
-
`
|
|
51
|
+
await expect(requestRevocation(params)).rejects.toThrow(
|
|
52
|
+
`Failed to request revocation: ${apiError.message}`
|
|
47
53
|
);
|
|
48
54
|
});
|
|
55
|
+
|
|
56
|
+
it("should re-throw ApacuanaAPIError if caught", async () => {
|
|
57
|
+
const params = { reasonCode: 1 };
|
|
58
|
+
const apiError = new ApacuanaAPIError("API Error");
|
|
59
|
+
httpRequest.mockRejectedValue(apiError);
|
|
60
|
+
|
|
61
|
+
await expect(requestRevocation(params)).rejects.toThrow(apiError);
|
|
62
|
+
});
|
|
49
63
|
});
|
|
50
64
|
|
|
51
65
|
describe("getRevocationReasons", () => {
|
|
52
66
|
it("should make a GET request and return the reasons for ONBOARDING", async () => {
|
|
53
|
-
|
|
54
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
55
|
-
});
|
|
56
|
-
const mockReasons = [
|
|
57
|
-
{ code: "0", description: "Unspecified" },
|
|
58
|
-
{ code: "1", description: "Key Compromise" },
|
|
59
|
-
];
|
|
67
|
+
const mockReasons = [{ code: 1, reason: "Test Reason" }];
|
|
60
68
|
httpRequest.mockResolvedValue({ records: mockReasons });
|
|
61
69
|
|
|
62
70
|
const result = await getRevocationReasons();
|
|
63
71
|
|
|
64
72
|
expect(httpRequest).toHaveBeenCalledWith(
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
"services/api/certificate/revocation-reasons",
|
|
74
|
+
{},
|
|
75
|
+
"GET"
|
|
68
76
|
);
|
|
69
|
-
expect(result).
|
|
77
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
78
|
+
expect(result.data).toEqual(mockReasons);
|
|
70
79
|
});
|
|
71
80
|
|
|
72
81
|
it("should throw an error if the API response does not contain 'records'", async () => {
|
|
73
|
-
|
|
74
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
75
|
-
});
|
|
76
|
-
httpRequest.mockResolvedValue({ data: [] }); // Respuesta inválida
|
|
82
|
+
httpRequest.mockResolvedValue({ data: [] }); // Invalid response
|
|
77
83
|
|
|
78
84
|
await expect(getRevocationReasons()).rejects.toThrow(
|
|
79
85
|
new ApacuanaAPIError("Failed to fetch revocation reasons.")
|
|
@@ -81,24 +87,18 @@ describe("Revocations API", () => {
|
|
|
81
87
|
});
|
|
82
88
|
|
|
83
89
|
it("should re-throw ApacuanaAPIError if caught", async () => {
|
|
84
|
-
|
|
85
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
86
|
-
});
|
|
87
|
-
const apiError = new ApacuanaAPIError("API is down", 500);
|
|
90
|
+
const apiError = new ApacuanaAPIError("API Error");
|
|
88
91
|
httpRequest.mockRejectedValue(apiError);
|
|
89
92
|
|
|
90
93
|
await expect(getRevocationReasons()).rejects.toThrow(apiError);
|
|
91
94
|
});
|
|
92
95
|
|
|
93
96
|
it("should throw a generic error for other types of errors", async () => {
|
|
94
|
-
getConfig.mockReturnValue({
|
|
95
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
96
|
-
});
|
|
97
97
|
const genericError = new Error("Something went wrong");
|
|
98
98
|
httpRequest.mockRejectedValue(genericError);
|
|
99
99
|
|
|
100
100
|
await expect(getRevocationReasons()).rejects.toThrow(
|
|
101
|
-
|
|
101
|
+
`Failed to get revocation reasons: ${genericError.message}`
|
|
102
102
|
);
|
|
103
103
|
});
|
|
104
104
|
|
|
@@ -109,7 +109,7 @@ describe("Revocations API", () => {
|
|
|
109
109
|
|
|
110
110
|
await expect(getRevocationReasons()).rejects.toThrow(
|
|
111
111
|
new ApacuanaAPIError(
|
|
112
|
-
"
|
|
112
|
+
"Getting revocation reasons is not supported for integration type: ONPREMISE",
|
|
113
113
|
501,
|
|
114
114
|
"NOT_IMPLEMENTED"
|
|
115
115
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getConfig } from "../../src/config";
|
|
2
2
|
import { httpRequest } from "../../src/utils/httpClient";
|
|
3
3
|
import { ApacuanaAPIError } from "../../src/errors";
|
|
4
|
+
import ApacuanaSuccess from "../../src/success";
|
|
4
5
|
import {
|
|
5
6
|
addSigner,
|
|
6
7
|
getDocs,
|
|
@@ -184,7 +185,8 @@ describe("API - Signatures", () => {
|
|
|
184
185
|
{ publickey: signData.cert },
|
|
185
186
|
"POST"
|
|
186
187
|
);
|
|
187
|
-
expect(result).
|
|
188
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
189
|
+
expect(result.data).toEqual({ digest: "test-digest" });
|
|
188
190
|
});
|
|
189
191
|
|
|
190
192
|
it("should throw an error if digest is not in response for ONBOARDING", async () => {
|
|
@@ -257,7 +259,8 @@ describe("API - Signatures", () => {
|
|
|
257
259
|
},
|
|
258
260
|
"PUT"
|
|
259
261
|
);
|
|
260
|
-
expect(result).
|
|
262
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
263
|
+
expect(result.data).toEqual(mockResponse);
|
|
261
264
|
});
|
|
262
265
|
|
|
263
266
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
|
@@ -346,7 +349,8 @@ describe("API - Signatures", () => {
|
|
|
346
349
|
{ file: validFile },
|
|
347
350
|
"POST"
|
|
348
351
|
);
|
|
349
|
-
expect(result).
|
|
352
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
353
|
+
expect(result.data).toEqual({ success: true, id: "123" });
|
|
350
354
|
});
|
|
351
355
|
|
|
352
356
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
|
@@ -392,7 +396,8 @@ describe("API - Signatures", () => {
|
|
|
392
396
|
{},
|
|
393
397
|
"GET"
|
|
394
398
|
);
|
|
395
|
-
expect(result).
|
|
399
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
400
|
+
expect(result.data).toEqual(mockResponse);
|
|
396
401
|
});
|
|
397
402
|
|
|
398
403
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
|
@@ -436,7 +441,8 @@ describe("API - Signatures", () => {
|
|
|
436
441
|
{},
|
|
437
442
|
"DELETE"
|
|
438
443
|
);
|
|
439
|
-
expect(result).
|
|
444
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
445
|
+
expect(result.data).toEqual(mockResponse);
|
|
440
446
|
});
|
|
441
447
|
|
|
442
448
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
package/tests/api/users.test.js
CHANGED
|
@@ -3,6 +3,7 @@ import { httpRequest } from "../../src/utils/httpClient.js";
|
|
|
3
3
|
import { getConfig } from "../../src/config/index.js";
|
|
4
4
|
import { ApacuanaAPIError } from "../../src/errors/index.js";
|
|
5
5
|
import getCustomer from "../../src/api/users.js";
|
|
6
|
+
import ApacuanaSuccess from "../../src/success/index.js";
|
|
6
7
|
|
|
7
8
|
// Mockear las dependencias:
|
|
8
9
|
jest.mock("../../src/utils/httpClient.js", () => ({
|
|
@@ -56,8 +57,8 @@ describe("getCustomer", () => {
|
|
|
56
57
|
"POST"
|
|
57
58
|
);
|
|
58
59
|
|
|
59
|
-
expect(result).
|
|
60
|
-
|
|
60
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
61
|
+
expect(result.data).toEqual({
|
|
61
62
|
token: "mock-session-id-12345",
|
|
62
63
|
userData: {
|
|
63
64
|
userId: "mock-user",
|