apacuana-sdk-core 0.6.2 → 0.8.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 +105 -288
- package/coverage/clover.xml +141 -136
- package/coverage/coverage-final.json +5 -5
- package/coverage/lcov-report/index.html +34 -34
- package/coverage/lcov-report/src/api/certs.js.html +34 -7
- package/coverage/lcov-report/src/api/index.html +19 -19
- package/coverage/lcov-report/src/api/revocations.js.html +135 -30
- package/coverage/lcov-report/src/api/signatures.js.html +76 -4
- package/coverage/lcov-report/src/api/users.js.html +1 -1
- package/coverage/lcov-report/src/config/index.html +13 -13
- package/coverage/lcov-report/src/config/index.js.html +66 -18
- package/coverage/lcov-report/src/errors/index.html +1 -1
- package/coverage/lcov-report/src/errors/index.js.html +1 -1
- package/coverage/lcov-report/src/index.html +15 -15
- package/coverage/lcov-report/src/index.js.html +14 -68
- 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 +223 -216
- package/dist/api/certs.d.ts +11 -1
- package/dist/api/revocations.d.ts +32 -12
- package/dist/api/signatures.d.ts +37 -5
- package/dist/config/index.d.ts +13 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +159 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -75
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/certs.js +12 -3
- package/src/api/revocations.js +55 -20
- package/src/api/signatures.js +25 -1
- package/src/config/index.js +24 -8
- package/src/index.js +4 -22
package/package.json
CHANGED
package/src/api/certs.js
CHANGED
|
@@ -7,6 +7,7 @@ import { INTEGRATION_TYPE } from "../utils/constant";
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {object} GenerateCertResponse
|
|
9
9
|
* @property {string} cert - El certificado generado en formato string.
|
|
10
|
+
* @property {string} certifiedid - El ID del certificado generado.
|
|
10
11
|
* @property {boolean} success - Indica si la operación fue exitosa.
|
|
11
12
|
*/
|
|
12
13
|
|
|
@@ -16,7 +17,15 @@ import { INTEGRATION_TYPE } from "../utils/constant";
|
|
|
16
17
|
* @property {boolean} success - Indica si la operación fue exitosa.
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {object} EncryptedCSRObject
|
|
22
|
+
* @property {string} csr - The encrypted Certificate Signing Request.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {EncryptedCSRObject} encryptedCSR
|
|
27
|
+
*/
|
|
28
|
+
const generateCertOnBoarding = async (encryptedCSR) => {
|
|
20
29
|
try {
|
|
21
30
|
const response = await httpRequest(
|
|
22
31
|
"services/api/register/certificate",
|
|
@@ -52,12 +61,12 @@ const generateCertOnPremise = async () => {
|
|
|
52
61
|
|
|
53
62
|
/**
|
|
54
63
|
* Generates a digital certificate.
|
|
55
|
-
* @param {
|
|
64
|
+
* @param {EncryptedCSRObject} encryptedCSR - Certificate Signing Request (CSR) object.
|
|
56
65
|
* @returns {Promise<GenerateCertResponse>} Object with the generated certificate and a success indicator.
|
|
57
66
|
* @throws {ApacuanaAPIError} If the CSR is invalid, if the API response does not contain the certificate, or if the integration type is not supported.
|
|
58
67
|
* @throws {Error} If certificate generation fails for another reason.
|
|
59
68
|
*/
|
|
60
|
-
export const generateCert = async (encryptedCSR
|
|
69
|
+
export const generateCert = async (encryptedCSR) => {
|
|
61
70
|
const { integrationType } = getConfig();
|
|
62
71
|
helpers.validateCsr(encryptedCSR);
|
|
63
72
|
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
package/src/api/revocations.js
CHANGED
|
@@ -12,37 +12,72 @@ import { ApacuanaAPIError } from "../errors/index";
|
|
|
12
12
|
* @param {string} reasonCode - Código o descripción del motivo de la revocación.
|
|
13
13
|
* @returns {Promise<RequestRevocationResponse>} Objeto con el estado de la solicitud de revocación.
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object} RevocationResponse
|
|
17
|
+
* @property {boolean} success - Indicates if the revocation request was successful.
|
|
18
|
+
* @property {string} [message] - A message providing details about the outcome.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {object} RevocationReason
|
|
23
|
+
* @property {string} code - The code for the revocation reason.
|
|
24
|
+
* @property {string} description - The description of the revocation reason.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} RevocationReasonsResponse
|
|
29
|
+
* @property {boolean} success - Indicates if the request was successful.
|
|
30
|
+
* @property {RevocationReason[]} reasons - A list of revocation reasons.
|
|
31
|
+
*/
|
|
20
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Requests the revocation of a certificate.
|
|
35
|
+
* @param {number} reasonCode - Código o descripción del motivo de la revocación.
|
|
36
|
+
* @returns {Promise<RevocationResponse>} An object indicating the success of the request.
|
|
37
|
+
* @throws {ApacuanaAPIError} If the revocation request fails.
|
|
38
|
+
*/
|
|
39
|
+
export const requestRevocation = async (reasonCode) => {
|
|
21
40
|
if (!reasonCode) {
|
|
22
|
-
throw new Error(
|
|
23
|
-
"ID de certificado y motivo son requeridos para requestRevocation."
|
|
24
|
-
);
|
|
41
|
+
throw new Error("Código de motivo es requerido para requestRevocation.");
|
|
25
42
|
}
|
|
26
43
|
|
|
27
44
|
try {
|
|
28
45
|
const response = await httpRequest(
|
|
29
|
-
"
|
|
46
|
+
"services/api/onboardingclient/requestcert",
|
|
30
47
|
{ reason: reasonCode },
|
|
31
48
|
"POST"
|
|
32
49
|
);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
throw new ApacuanaAPIError(
|
|
36
|
-
response.message || "Error desconocido al solicitar revocación."
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
revocationStatus: response.status || "pending",
|
|
41
|
-
requestId: response.id,
|
|
42
|
-
};
|
|
50
|
+
|
|
51
|
+
return response;
|
|
43
52
|
} catch (error) {
|
|
44
53
|
throw new Error(`Fallo en la solicitud de revocación: ${error.message}`);
|
|
45
54
|
}
|
|
46
55
|
};
|
|
47
56
|
|
|
48
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves the available reasons for certificate revocation.
|
|
59
|
+
* @returns {Promise<RevocationReasonsResponse>} An object containing the list of revocation reasons.
|
|
60
|
+
* @throws {ApacuanaAPIError} If fetching the reasons fails.
|
|
61
|
+
*/
|
|
62
|
+
export const getRevocationReasons = async () => {
|
|
63
|
+
try {
|
|
64
|
+
const response = await httpRequest(
|
|
65
|
+
"config/api/revocation/reasonsonboarding",
|
|
66
|
+
{},
|
|
67
|
+
"GET"
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if (!response.records) {
|
|
71
|
+
throw new ApacuanaAPIError("Failed to fetch revocation reasons.");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return response.records;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error instanceof ApacuanaAPIError) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
throw new Error(
|
|
80
|
+
"Failed to get revocation reasons. Please try again later."
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
};
|
package/src/api/signatures.js
CHANGED
|
@@ -21,7 +21,6 @@ import { INTEGRATION_TYPE } from "../utils/constant";
|
|
|
21
21
|
* Define la estructura de datos para añadir un firmante.
|
|
22
22
|
* @typedef {object} SignerData
|
|
23
23
|
* @property {string} docId - Identificador único del documento.
|
|
24
|
-
* @property {Signer} signer - Objeto con la información del firmante.
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
26
|
/**
|
|
@@ -280,6 +279,31 @@ export const getDigest = async (signData) => {
|
|
|
280
279
|
* @returns {Promise<AddSignerResponse>} Una promesa que resuelve a un objeto con el resultado de la operación.
|
|
281
280
|
* @throws {ApacuanaAPIError} Si los datos del firmante son inválidos, la llamada a la API falla, o el tipo de integración no es soportado.
|
|
282
281
|
*/
|
|
282
|
+
/**
|
|
283
|
+
* @typedef {object} SignaturePosition
|
|
284
|
+
* @property {number} page - The page number for the signature.
|
|
285
|
+
* @property {number} x - The x-coordinate for the signature's position (from 0 to 1).
|
|
286
|
+
* @property {number} y - The y-coordinate for the signature's position (from 0 to 1).
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @typedef {object} OnboardingSignerData
|
|
291
|
+
* @property {string} name - The name of the document.
|
|
292
|
+
* @property {string} reference - An external reference for the document.
|
|
293
|
+
* @property {string} typedoc - The type of document of the signer (e.g., "V", "E", "J").
|
|
294
|
+
* @property {string} doc - The document number of the signer.
|
|
295
|
+
* @property {SignaturePosition[]} signature - An array of signature positions.
|
|
296
|
+
*/
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Adds a new signer to the signature process.
|
|
300
|
+
* This function acts as a dispatcher, delegating to the appropriate implementation
|
|
301
|
+
* based on the configured integration type.
|
|
302
|
+
*
|
|
303
|
+
* @param {OnboardingSignerData | object} signerData - The signer's data. The structure depends on the integration type.
|
|
304
|
+
* @returns {Promise<object>} The result from the API.
|
|
305
|
+
* @throws {ApacuanaAPIError} If signerData is invalid or if the integration type is not supported.
|
|
306
|
+
*/
|
|
283
307
|
export const addSigner = async (signerData) => {
|
|
284
308
|
if (
|
|
285
309
|
!signerData ||
|
package/src/config/index.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
// src/config/index.js
|
|
2
|
-
import { INTEGRATION_TYPE } from
|
|
2
|
+
import { INTEGRATION_TYPE } from "../utils/constant";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} SDKConfig
|
|
6
|
+
* @property {string} apiUrl
|
|
7
|
+
* @property {string} secretKey
|
|
8
|
+
* @property {string} apiKey
|
|
9
|
+
* @property {string} verificationId
|
|
10
|
+
* @property {string} customerId
|
|
11
|
+
* @property {string} integrationType
|
|
12
|
+
* @property {object} [userData]
|
|
13
|
+
* @property {string} [token]
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const defaultConfig = {
|
|
5
17
|
apiUrl: "",
|
|
6
18
|
secretKey: "",
|
|
7
19
|
apiKey: "",
|
|
@@ -12,8 +24,12 @@ let config = {
|
|
|
12
24
|
token: undefined,
|
|
13
25
|
};
|
|
14
26
|
|
|
27
|
+
/** @type {SDKConfig} */
|
|
28
|
+
let config = { ...defaultConfig };
|
|
29
|
+
|
|
15
30
|
export const setConfig = (newConfig) => {
|
|
16
|
-
const { apiUrl, secretKey, apiKey, verificationId, integrationType } =
|
|
31
|
+
const { apiUrl, secretKey, apiKey, verificationId, integrationType } =
|
|
32
|
+
newConfig;
|
|
17
33
|
|
|
18
34
|
if (!apiUrl || !secretKey || !apiKey || !verificationId || !integrationType) {
|
|
19
35
|
throw new Error(
|
|
@@ -26,16 +42,16 @@ export const setConfig = (newConfig) => {
|
|
|
26
42
|
if (!Object.values(INTEGRATION_TYPE).includes(integrationType)) {
|
|
27
43
|
throw new Error(
|
|
28
44
|
`Apacuana SDK: El valor de integrationType ('${integrationType}') no es válido. ` +
|
|
29
|
-
|
|
45
|
+
`Valores permitidos: ${Object.values(INTEGRATION_TYPE).join(", ")}`
|
|
30
46
|
);
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
config = { ...config, ...newConfig };
|
|
34
50
|
// eslint-disable-next-line no-console
|
|
35
|
-
console.log("[Config] SDK Configuración actualizada (desde config):", {
|
|
36
|
-
...config,
|
|
37
|
-
secretKey: "********",
|
|
38
|
-
});
|
|
39
51
|
};
|
|
40
52
|
|
|
41
53
|
export const getConfig = () => ({ ...config });
|
|
54
|
+
|
|
55
|
+
export const close = () => {
|
|
56
|
+
config = { ...defaultConfig };
|
|
57
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { setConfig, getConfig } from "./config/index";
|
|
1
|
+
import { setConfig, getConfig, close } from "./config/index";
|
|
2
2
|
import { initHttpClient, setAuthToken } from "./utils/httpClient";
|
|
3
3
|
import getCustomer from "./api/users";
|
|
4
|
-
import requestRevocation from "./api/revocations";
|
|
4
|
+
import { requestRevocation, getRevocationReasons } from "./api/revocations";
|
|
5
5
|
import { generateCert, getCertStatus } from "./api/certs";
|
|
6
6
|
import { addSigner, getDigest, getDocs, signDocument } from "./api/signatures";
|
|
7
7
|
|
|
@@ -19,19 +19,9 @@ const apacuana = {
|
|
|
19
19
|
* @returns {Promise<object>} retorna los detalles del usuario si la inicialización es exitosa.
|
|
20
20
|
*/
|
|
21
21
|
init: async (config) => {
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
console.log(
|
|
24
|
-
"-> apacuana-sdk: Iniciando configuración y validando usuario..."
|
|
25
|
-
);
|
|
26
|
-
|
|
27
22
|
try {
|
|
28
|
-
// 1. Guardar la configuración inicial
|
|
29
23
|
setConfig(config);
|
|
30
|
-
|
|
31
|
-
// 2. Inicializar el cliente HTTP con la configuración guardada
|
|
32
24
|
initHttpClient();
|
|
33
|
-
|
|
34
|
-
// 3. Opcional: Validar que la configuración se guardó correctamente
|
|
35
25
|
const currentConfig = getConfig();
|
|
36
26
|
if (!currentConfig.customerId) {
|
|
37
27
|
throw new Error(
|
|
@@ -39,19 +29,9 @@ const apacuana = {
|
|
|
39
29
|
" correctamente."
|
|
40
30
|
);
|
|
41
31
|
}
|
|
42
|
-
|
|
43
|
-
// 4. Obtener los detalles del usuario como parte de la inicialización
|
|
44
32
|
const { token, userData } = await getCustomer();
|
|
45
|
-
|
|
46
|
-
// Opcional: Guardar los detalles del usuario en la configuración
|
|
47
|
-
// para acceso futuro si fuera necesario
|
|
48
33
|
setConfig({ ...currentConfig, token, userData });
|
|
49
34
|
setAuthToken(token);
|
|
50
|
-
// eslint-disable-next-line no-console
|
|
51
|
-
console.log(
|
|
52
|
-
"-> apacuana-sdk: Inicialización completa. Usuario validado:",
|
|
53
|
-
token
|
|
54
|
-
);
|
|
55
35
|
return true;
|
|
56
36
|
} catch (error) {
|
|
57
37
|
// eslint-disable-next-line no-console
|
|
@@ -59,6 +39,7 @@ const apacuana = {
|
|
|
59
39
|
throw error;
|
|
60
40
|
}
|
|
61
41
|
},
|
|
42
|
+
close: () => close(),
|
|
62
43
|
getConfig,
|
|
63
44
|
requestRevocation,
|
|
64
45
|
getCertStatus,
|
|
@@ -68,6 +49,7 @@ const apacuana = {
|
|
|
68
49
|
generateCert,
|
|
69
50
|
signDocument,
|
|
70
51
|
getDigest,
|
|
52
|
+
getRevocationReasons,
|
|
71
53
|
};
|
|
72
54
|
|
|
73
55
|
export default apacuana;
|