apacuana-sdk-core 0.9.0 → 0.10.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 +65 -0
- package/coverage/clover.xml +59 -24
- package/coverage/coverage-final.json +3 -3
- package/coverage/lcov-report/index.html +18 -18
- package/coverage/lcov-report/src/api/certs.js.html +390 -9
- package/coverage/lcov-report/src/api/index.html +16 -16
- package/coverage/lcov-report/src/api/revocations.js.html +1 -1
- package/coverage/lcov-report/src/api/signatures.js.html +1 -1
- package/coverage/lcov-report/src/api/users.js.html +1 -1
- 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 +24 -3
- package/coverage/lcov-report/src/utils/constant.js.html +1 -1
- 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 +94 -31
- package/dist/api/certs.d.ts +44 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +206 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +206 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/certs.js +127 -0
- package/src/index.js +8 -1
- package/tests/api/certs.test.js +113 -1
package/package.json
CHANGED
package/src/api/certs.js
CHANGED
|
@@ -99,3 +99,130 @@ export const getCertStatus = (isCertificateInDevice = false) => {
|
|
|
99
99
|
success: true,
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @typedef {object} CertType
|
|
105
|
+
* @property {string} id - The ID of the certificate type.
|
|
106
|
+
* @property {string} name - The name of the certificate type.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @typedef {object} GetCertTypesResponse
|
|
111
|
+
* @property {Array<CertType>} types - A list of available certificate types.
|
|
112
|
+
* @property {boolean} success - Indicates if the operation was successful.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
const getCertTypesOnBoarding = async () => {
|
|
116
|
+
try {
|
|
117
|
+
const response = await httpRequest(
|
|
118
|
+
"services/api/customer/typeusers",
|
|
119
|
+
{},
|
|
120
|
+
"GET"
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
return { ...response, success: true };
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error instanceof ApacuanaAPIError) {
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
throw new Error(`Failed to get certificate types: ${error.message}`);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const getCertTypesOnPremise = async () => {
|
|
133
|
+
throw new ApacuanaAPIError(
|
|
134
|
+
"Getting certificate types is not supported for integration type: ONPREMISE",
|
|
135
|
+
501,
|
|
136
|
+
"NOT_IMPLEMENTED"
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Gets the available certificate types.
|
|
142
|
+
* @returns {Promise<GetCertTypesResponse>} Object with the list of certificate types and a success indicator.
|
|
143
|
+
* @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
|
|
144
|
+
* @throws {Error} If the request fails for another reason.
|
|
145
|
+
*/
|
|
146
|
+
export const getCertTypes = async () => {
|
|
147
|
+
const { integrationType } = getConfig();
|
|
148
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
149
|
+
return getCertTypesOnBoarding();
|
|
150
|
+
}
|
|
151
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
152
|
+
return getCertTypesOnPremise();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
throw new ApacuanaAPIError(
|
|
156
|
+
`Unsupported integration type: ${integrationType}`,
|
|
157
|
+
400,
|
|
158
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @typedef {object} Requirement
|
|
164
|
+
* @property {string} id - The ID of the requirement.
|
|
165
|
+
* @property {string} description - The description of the requirement.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @typedef {object} GetRequirementsResponse
|
|
170
|
+
* @property {Array<Requirement>} requirements - A list of requirements for the user type.
|
|
171
|
+
* @property {boolean} success - Indicates if the operation was successful.
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
const getRequerimentsByTypeUserOnBoarding = async (type) => {
|
|
175
|
+
try {
|
|
176
|
+
const response = await httpRequest(
|
|
177
|
+
`services/api/customer/documentspref?typeuser=${type}`,
|
|
178
|
+
{},
|
|
179
|
+
"GET"
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return { ...response, success: true };
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (error instanceof ApacuanaAPIError) {
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
throw new Error(`Failed to get requirements: ${error.message}`);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const getRequerimentsByTypeUserOnPremise = async () => {
|
|
192
|
+
throw new ApacuanaAPIError(
|
|
193
|
+
"Getting requirements by user type is not supported for integration type: ONPREMISE",
|
|
194
|
+
501,
|
|
195
|
+
"NOT_IMPLEMENTED"
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Gets the requirements for a given user type.
|
|
201
|
+
* @param {object} params - The parameters.
|
|
202
|
+
* @param {number} params.type - The user type to get requirements for.
|
|
203
|
+
* @returns {Promise<GetRequirementsResponse>} Object with the list of requirements and a success indicator.
|
|
204
|
+
* @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
|
|
205
|
+
* @throws {Error} If the request fails for another reason or the type is invalid.
|
|
206
|
+
*/
|
|
207
|
+
export const getRequerimentsByTypeUser = async (params) => {
|
|
208
|
+
if (!params || typeof params.type !== "number") {
|
|
209
|
+
throw new Error(
|
|
210
|
+
'The "params" object with a numeric "type" property is required.'
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
const { type } = params;
|
|
214
|
+
|
|
215
|
+
const { integrationType } = getConfig();
|
|
216
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
217
|
+
return getRequerimentsByTypeUserOnBoarding(type);
|
|
218
|
+
}
|
|
219
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
220
|
+
return getRequerimentsByTypeUserOnPremise();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
throw new ApacuanaAPIError(
|
|
224
|
+
`Unsupported integration type: ${integrationType}`,
|
|
225
|
+
400,
|
|
226
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
227
|
+
);
|
|
228
|
+
};
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,12 @@ import { setConfig, getConfig, close } from "./config/index";
|
|
|
2
2
|
import { initHttpClient, setAuthToken } from "./utils/httpClient";
|
|
3
3
|
import getCustomer from "./api/users";
|
|
4
4
|
import { requestRevocation, getRevocationReasons } from "./api/revocations";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
generateCert,
|
|
7
|
+
getCertStatus,
|
|
8
|
+
getCertTypes,
|
|
9
|
+
getRequerimentsByTypeUser,
|
|
10
|
+
} from "./api/certs";
|
|
6
11
|
import {
|
|
7
12
|
addSigner,
|
|
8
13
|
deleteSignatureVariant,
|
|
@@ -61,6 +66,8 @@ const apacuana = {
|
|
|
61
66
|
uploadSignatureVariant,
|
|
62
67
|
getSignatureVariant,
|
|
63
68
|
deleteSignatureVariant,
|
|
69
|
+
getCertTypes,
|
|
70
|
+
getRequerimentsByTypeUser,
|
|
64
71
|
};
|
|
65
72
|
|
|
66
73
|
export default apacuana;
|
package/tests/api/certs.test.js
CHANGED
|
@@ -2,7 +2,12 @@ import { getConfig } from "../../src/config/index";
|
|
|
2
2
|
import { httpRequest } from "../../src/utils/httpClient";
|
|
3
3
|
import helpers from "../../src/utils/helpers";
|
|
4
4
|
import { ApacuanaAPIError } from "../../src/errors";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
generateCert,
|
|
7
|
+
getCertStatus,
|
|
8
|
+
getCertTypes,
|
|
9
|
+
getRequerimentsByTypeUser,
|
|
10
|
+
} from "../../src/api/certs";
|
|
6
11
|
import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
7
12
|
|
|
8
13
|
jest.mock("../../src/config/index");
|
|
@@ -91,4 +96,111 @@ describe("Certificate API - certs.js", () => {
|
|
|
91
96
|
expect(result).toEqual({ status: "VALID", success: true });
|
|
92
97
|
});
|
|
93
98
|
});
|
|
99
|
+
|
|
100
|
+
describe("getCertTypes", () => {
|
|
101
|
+
it("should call getCertTypesOnBoarding for ONBOARDING integration", async () => {
|
|
102
|
+
getConfig.mockReturnValue({
|
|
103
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
104
|
+
});
|
|
105
|
+
const mockApiResponse = { types: [{ id: "1", name: "Type 1" }] };
|
|
106
|
+
httpRequest.mockResolvedValue(mockApiResponse);
|
|
107
|
+
|
|
108
|
+
const result = await getCertTypes();
|
|
109
|
+
|
|
110
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
111
|
+
"services/api/customer/typeusers",
|
|
112
|
+
{},
|
|
113
|
+
"GET"
|
|
114
|
+
);
|
|
115
|
+
expect(result).toEqual({ types: mockApiResponse.types, success: true });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("should throw an error for ONPREMISE integration", async () => {
|
|
119
|
+
getConfig.mockReturnValue({
|
|
120
|
+
integrationType: INTEGRATION_TYPE.ONPREMISE,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
await expect(getCertTypes()).rejects.toThrow(
|
|
124
|
+
new ApacuanaAPIError(
|
|
125
|
+
"Getting certificate types is not supported for integration type: ONPREMISE",
|
|
126
|
+
501,
|
|
127
|
+
"NOT_IMPLEMENTED"
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should throw an error for an unsupported integration type", async () => {
|
|
133
|
+
getConfig.mockReturnValue({ integrationType: "INVALID_TYPE" });
|
|
134
|
+
|
|
135
|
+
await expect(getCertTypes()).rejects.toThrow(
|
|
136
|
+
new ApacuanaAPIError(
|
|
137
|
+
"Unsupported integration type: INVALID_TYPE",
|
|
138
|
+
400,
|
|
139
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
140
|
+
)
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("getRequerimentsByTypeUser", () => {
|
|
146
|
+
it("should call getRequerimentsByTypeUserOnBoarding for ONBOARDING integration", async () => {
|
|
147
|
+
getConfig.mockReturnValue({
|
|
148
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
149
|
+
});
|
|
150
|
+
const mockApiResponse = {
|
|
151
|
+
requirements: [{ id: "1", description: "Requirement 1" }],
|
|
152
|
+
};
|
|
153
|
+
httpRequest.mockResolvedValue(mockApiResponse);
|
|
154
|
+
|
|
155
|
+
const result = await getRequerimentsByTypeUser({ type: 1 });
|
|
156
|
+
|
|
157
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
158
|
+
"services/api/customer/documentspref?typeuser=1",
|
|
159
|
+
{},
|
|
160
|
+
"GET"
|
|
161
|
+
);
|
|
162
|
+
expect(result).toEqual({
|
|
163
|
+
requirements: mockApiResponse.requirements,
|
|
164
|
+
success: true,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("should throw an error for ONPREMISE integration", async () => {
|
|
169
|
+
getConfig.mockReturnValue({
|
|
170
|
+
integrationType: INTEGRATION_TYPE.ONPREMISE,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
await expect(getRequerimentsByTypeUser({ type: 1 })).rejects.toThrow(
|
|
174
|
+
new ApacuanaAPIError(
|
|
175
|
+
"Getting requirements by user type is not supported for integration type: ONPREMISE",
|
|
176
|
+
501,
|
|
177
|
+
"NOT_IMPLEMENTED"
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("should throw an error for an unsupported integration type", async () => {
|
|
183
|
+
getConfig.mockReturnValue({ integrationType: "INVALID_TYPE" });
|
|
184
|
+
|
|
185
|
+
await expect(getRequerimentsByTypeUser({ type: 1 })).rejects.toThrow(
|
|
186
|
+
new ApacuanaAPIError(
|
|
187
|
+
"Unsupported integration type: INVALID_TYPE",
|
|
188
|
+
400,
|
|
189
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
190
|
+
)
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should throw an error if params are invalid", async () => {
|
|
195
|
+
await expect(getRequerimentsByTypeUser()).rejects.toThrow(
|
|
196
|
+
'The "params" object with a numeric "type" property is required.'
|
|
197
|
+
);
|
|
198
|
+
await expect(getRequerimentsByTypeUser({})).rejects.toThrow(
|
|
199
|
+
'The "params" object with a numeric "type" property is required.'
|
|
200
|
+
);
|
|
201
|
+
await expect(getRequerimentsByTypeUser({ type: "1" })).rejects.toThrow(
|
|
202
|
+
'The "params" object with a numeric "type" property is required.'
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
94
206
|
});
|