apacuana-sdk-core 0.13.0 → 0.15.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 +606 -179
- package/coverage/clover.xml +263 -206
- package/coverage/coverage-final.json +6 -6
- package/coverage/lcov-report/index.html +36 -36
- package/coverage/lcov-report/src/api/certs.js.html +14 -8
- package/coverage/lcov-report/src/api/faceLiveness.js.html +1 -1
- package/coverage/lcov-report/src/api/index.html +25 -25
- package/coverage/lcov-report/src/api/revocations.js.html +2 -2
- package/coverage/lcov-report/src/api/signatures.js.html +1 -1
- package/coverage/lcov-report/src/api/users.js.html +160 -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 +1 -1
- package/coverage/lcov-report/src/index.html +21 -21
- package/coverage/lcov-report/src/index.js.html +278 -59
- package/coverage/lcov-report/src/success/index.html +1 -1
- package/coverage/lcov-report/src/success/index.js.html +1 -1
- package/coverage/lcov-report/src/utils/constant.js.html +115 -4
- package/coverage/lcov-report/src/utils/helpers.js.html +16 -13
- package/coverage/lcov-report/src/utils/httpClient.js.html +4 -7
- package/coverage/lcov-report/src/utils/index.html +12 -12
- package/coverage/lcov.info +504 -387
- package/dist/api/users.d.ts +27 -21
- package/dist/index.d.ts +19 -40
- package/dist/index.js +265 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +265 -118
- package/dist/index.mjs.map +1 -1
- package/dist/types/certs.d.ts +20 -34
- package/dist/utils/constant.d.ts +31 -0
- package/dist/utils/helpers.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/certs.js +4 -2
- package/src/api/revocations.js +1 -1
- package/src/api/users.js +51 -2
- package/src/index.js +114 -41
- package/src/types/certs.js +36 -25
- package/src/utils/constant.js +37 -0
- package/src/utils/helpers.js +5 -4
- package/src/utils/httpClient.js +1 -2
- package/tests/api/certs.test.js +11 -3
- package/tests/api/revocations.test.js +1 -1
- package/tests/api/users.test.js +1 -1
- package/tests/index.test.js +3 -2
package/dist/types/certs.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ApacuanaSuccess = import("../success").ApacuanaSuccess;
|
|
2
|
+
export type GenerateCertResponseData = {
|
|
2
3
|
/**
|
|
3
4
|
* - El certificado generado en formato string.
|
|
4
5
|
*/
|
|
@@ -7,26 +8,12 @@ export type GenerateCertResponse = {
|
|
|
7
8
|
* - El ID del certificado generado.
|
|
8
9
|
*/
|
|
9
10
|
certifiedid: string;
|
|
10
|
-
/**
|
|
11
|
-
* - Indica si la operación fue exitosa.
|
|
12
|
-
*/
|
|
13
|
-
success: boolean;
|
|
14
11
|
};
|
|
15
|
-
export type
|
|
12
|
+
export type GetCertStatusResponseData = {
|
|
16
13
|
/**
|
|
17
14
|
* - El estado actual del certificado del usuario.
|
|
18
15
|
*/
|
|
19
16
|
status: string;
|
|
20
|
-
/**
|
|
21
|
-
* - Indica si la operación fue exitosa.
|
|
22
|
-
*/
|
|
23
|
-
success: boolean;
|
|
24
|
-
};
|
|
25
|
-
export type EncryptedCSRObject = {
|
|
26
|
-
/**
|
|
27
|
-
* - The encrypted Certificate Signing Request.
|
|
28
|
-
*/
|
|
29
|
-
csr: string;
|
|
30
17
|
};
|
|
31
18
|
export type CertType = {
|
|
32
19
|
/**
|
|
@@ -38,15 +25,11 @@ export type CertType = {
|
|
|
38
25
|
*/
|
|
39
26
|
name: string;
|
|
40
27
|
};
|
|
41
|
-
export type
|
|
28
|
+
export type GetCertTypesResponseData = {
|
|
42
29
|
/**
|
|
43
30
|
* - A list of available certificate types.
|
|
44
31
|
*/
|
|
45
32
|
types: Array<CertType>;
|
|
46
|
-
/**
|
|
47
|
-
* - Indicates if the operation was successful.
|
|
48
|
-
*/
|
|
49
|
-
success: boolean;
|
|
50
33
|
};
|
|
51
34
|
export type Requirement = {
|
|
52
35
|
/**
|
|
@@ -58,15 +41,28 @@ export type Requirement = {
|
|
|
58
41
|
*/
|
|
59
42
|
description: string;
|
|
60
43
|
};
|
|
61
|
-
export type
|
|
44
|
+
export type GetRequirementsResponseData = {
|
|
62
45
|
/**
|
|
63
46
|
* - A list of requirements for the user type.
|
|
64
47
|
*/
|
|
65
48
|
requirements: Array<Requirement>;
|
|
49
|
+
};
|
|
50
|
+
export type RequestCertificateResponseData = {
|
|
51
|
+
/**
|
|
52
|
+
* - A message confirming the request.
|
|
53
|
+
*/
|
|
54
|
+
message: string;
|
|
55
|
+
};
|
|
56
|
+
export type GenerateCertResponse = GenerateCertResponseData & ApacuanaSuccess;
|
|
57
|
+
export type GetCertStatusResponse = GetCertStatusResponseData & ApacuanaSuccess;
|
|
58
|
+
export type GetCertTypesResponse = GetCertTypesResponseData & ApacuanaSuccess;
|
|
59
|
+
export type GetRequirementsResponse = GetRequirementsResponseData & ApacuanaSuccess;
|
|
60
|
+
export type RequestCertificateResponse = RequestCertificateResponseData & ApacuanaSuccess;
|
|
61
|
+
export type EncryptedCSRObject = {
|
|
66
62
|
/**
|
|
67
|
-
* -
|
|
63
|
+
* - The encrypted Certificate Signing Request.
|
|
68
64
|
*/
|
|
69
|
-
|
|
65
|
+
csr: string;
|
|
70
66
|
};
|
|
71
67
|
export type CertificateRequestParams = {
|
|
72
68
|
/**
|
|
@@ -85,13 +81,3 @@ export type CertificateRequestParams = {
|
|
|
85
81
|
file: string;
|
|
86
82
|
}>;
|
|
87
83
|
};
|
|
88
|
-
export type RequestCertificateResponse = {
|
|
89
|
-
/**
|
|
90
|
-
* - A message confirming the request.
|
|
91
|
-
*/
|
|
92
|
-
message: string;
|
|
93
|
-
/**
|
|
94
|
-
* - Indicates if the operation was successful.
|
|
95
|
-
*/
|
|
96
|
-
success: boolean;
|
|
97
|
-
};
|
package/dist/utils/constant.d.ts
CHANGED
|
@@ -8,6 +8,37 @@ export namespace STATUS_CERTIFICATE {
|
|
|
8
8
|
let certificate_another_device: string;
|
|
9
9
|
let sign_pending: string;
|
|
10
10
|
}
|
|
11
|
+
export const PARSE_STATUS: {
|
|
12
|
+
[STATUS_CERTIFICATE.certificate_another_device]: {
|
|
13
|
+
text: string;
|
|
14
|
+
descriptionText: undefined;
|
|
15
|
+
};
|
|
16
|
+
[STATUS_CERTIFICATE.request]: {
|
|
17
|
+
text: string;
|
|
18
|
+
descriptionText: string;
|
|
19
|
+
};
|
|
20
|
+
[STATUS_CERTIFICATE.generate]: {
|
|
21
|
+
text: string;
|
|
22
|
+
descriptionText: string;
|
|
23
|
+
};
|
|
24
|
+
[STATUS_CERTIFICATE.current]: {
|
|
25
|
+
text: string;
|
|
26
|
+
descriptionText: undefined;
|
|
27
|
+
};
|
|
28
|
+
[STATUS_CERTIFICATE.expire]: string;
|
|
29
|
+
[STATUS_CERTIFICATE.request_revoque]: {
|
|
30
|
+
text: string;
|
|
31
|
+
descriptionText: string;
|
|
32
|
+
};
|
|
33
|
+
[STATUS_CERTIFICATE.revoque]: {
|
|
34
|
+
text: string;
|
|
35
|
+
descriptionText: string;
|
|
36
|
+
};
|
|
37
|
+
[STATUS_CERTIFICATE.request_cert]: {
|
|
38
|
+
text: string;
|
|
39
|
+
descriptionText: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
11
42
|
export namespace VERIFICATION_STATUS {
|
|
12
43
|
let IN_REGISTER: number;
|
|
13
44
|
let APPROVED: number;
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -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):
|
|
14
|
+
declare function getCertificateStatus(userData: any, certificateInDevice: any): any;
|
|
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
package/src/api/certs.js
CHANGED
|
@@ -14,7 +14,7 @@ import { httpRequest } from "../utils/httpClient";
|
|
|
14
14
|
import helpers from "../utils/helpers";
|
|
15
15
|
import { ApacuanaAPIError } from "../errors";
|
|
16
16
|
import ApacuanaSuccess from "../success";
|
|
17
|
-
import { INTEGRATION_TYPE } from "../utils/constant";
|
|
17
|
+
import { INTEGRATION_TYPE, PARSE_STATUS } from "../utils/constant";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @param {EncryptedCSRObject} encryptedCSR
|
|
@@ -88,7 +88,9 @@ export const getCertStatus = (isCertificateInDevice = false) => {
|
|
|
88
88
|
config.userData,
|
|
89
89
|
isCertificateInDevice
|
|
90
90
|
);
|
|
91
|
-
|
|
91
|
+
const parseStatus = PARSE_STATUS[status];
|
|
92
|
+
|
|
93
|
+
return new ApacuanaSuccess({ status: parseStatus });
|
|
92
94
|
};
|
|
93
95
|
|
|
94
96
|
const getCertTypesOnBoarding = async () => {
|
package/src/api/revocations.js
CHANGED
package/src/api/users.js
CHANGED
|
@@ -24,7 +24,7 @@ import ApacuanaSuccess from "../success";
|
|
|
24
24
|
* @throws {Error} Si los parámetros de entrada son inválidos.
|
|
25
25
|
* @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
|
|
26
26
|
*/
|
|
27
|
-
const getCustomer = async () => {
|
|
27
|
+
export const getCustomer = async () => {
|
|
28
28
|
const { verificationId, customerId } = getConfig();
|
|
29
29
|
|
|
30
30
|
if (!verificationId || !customerId) {
|
|
@@ -69,4 +69,53 @@ const getCustomer = async () => {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {object} CreateUserPayload
|
|
74
|
+
* @property {string} usr - Correo electrónico del usuario.
|
|
75
|
+
* @property {string} pwd - Contraseña del usuario.
|
|
76
|
+
* @property {string} kinddoc - Tipo de documento de identidad (ej. 'V', 'P', 'E').
|
|
77
|
+
* @property {string} doc - Número de documento de identidad.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @typedef {object} CreateUserResponse
|
|
82
|
+
* @property {string} message - Mensaje de confirmación de la creación del usuario.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Crea un nuevo usuario en la plataforma de Apacuana.
|
|
87
|
+
* @param {CreateUserPayload} userData - Objeto con los datos del usuario a crear.
|
|
88
|
+
* @returns {Promise<ApacuanaSuccess>} Una promesa que resuelve a un objeto con la respuesta exitosa.
|
|
89
|
+
* @throws {ApacuanaAPIError} Si los datos de entrada son inválidos o si ocurre un error en la API.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export const createApacuanaUser = async (userData) => {
|
|
93
|
+
try {
|
|
94
|
+
const formData = new FormData();
|
|
95
|
+
Object.keys(userData).forEach((key) => {
|
|
96
|
+
const value = userData[key];
|
|
97
|
+
if (value instanceof File) {
|
|
98
|
+
formData.append(key, value);
|
|
99
|
+
} else if (value !== null && value !== undefined) {
|
|
100
|
+
formData.append(key, String(value));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const response = await httpRequest(
|
|
105
|
+
"services/api/register/initial",
|
|
106
|
+
formData,
|
|
107
|
+
"POST"
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return new ApacuanaSuccess({
|
|
111
|
+
...response,
|
|
112
|
+
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (error instanceof ApacuanaAPIError) {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
throw new ApacuanaAPIError(
|
|
118
|
+
`Unexpected failure creating user: ${error.message || "Unknown error"}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { setConfig, getConfig, close } from "./config/index";
|
|
2
2
|
import { initHttpClient, setAuthToken } from "./utils/httpClient";
|
|
3
|
-
import getCustomer from "./api/users";
|
|
4
3
|
import { requestRevocation, getRevocationReasons } from "./api/revocations";
|
|
5
4
|
import {
|
|
6
5
|
generateCert,
|
|
@@ -23,44 +22,59 @@ import {
|
|
|
23
22
|
} from "./api/faceLiveness";
|
|
24
23
|
import ApacuanaSuccess from "./success/index";
|
|
25
24
|
import { ApacuanaAPIError } from "./errors/index";
|
|
25
|
+
import { createApacuanaUser, getCustomer } from "./api/users";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Valida si el SDK está inicializado y si se dispone de un customerId.
|
|
29
|
+
* @param {boolean} requiresCustomerId - Indica si la operación necesita un customerId.
|
|
30
|
+
* @throws {ApacuanaAPIError} Si el SDK no está inicializado o el customerId es requerido y no está presente.
|
|
31
|
+
*/
|
|
32
|
+
const checkSdk = (requiresCustomerId = true) => {
|
|
33
|
+
const config = getConfig();
|
|
34
|
+
|
|
35
|
+
if (!config || !config.apiUrl) {
|
|
36
|
+
throw new ApacuanaAPIError(
|
|
37
|
+
"El SDK no está inicializado. Llama a apacuana.init() primero.",
|
|
38
|
+
400,
|
|
39
|
+
"NOT_INITIALIZED_ERROR"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (requiresCustomerId && !config.customerId) {
|
|
44
|
+
throw new ApacuanaAPIError(
|
|
45
|
+
"Se requiere un CustomerId para esta operación. Por favor, inicia sesión.",
|
|
46
|
+
403,
|
|
47
|
+
"CUSTOMER_ID_REQUIRED"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
26
51
|
|
|
27
52
|
const apacuana = {
|
|
28
53
|
/**
|
|
29
|
-
* Inicializa el Apacuana SDK con la configuración necesaria
|
|
30
|
-
* los detalles del usuario.
|
|
31
|
-
* @param {object} config - Objeto de configuración.
|
|
32
|
-
* @param {string} config.apiUrl - La URL base de la API de Apacuana.
|
|
33
|
-
* @param {string} config.secretKey - La clave secreta para la autenticación.
|
|
34
|
-
* @param {string} config.apiKey - La clave de API para la autenticación.
|
|
35
|
-
* @param {string} config.verificationId - El ID de verificación del usuario.
|
|
36
|
-
* @param {string} config.customerId - El ID del cliente.
|
|
37
|
-
* @param {string} config.integrationType - El tipo de integración ('onpremise' o 'onboarding').
|
|
38
|
-
* @returns {Promise<object>} retorna los detalles del usuario si la inicialización es exitosa.
|
|
54
|
+
* Inicializa el Apacuana SDK con la configuración necesaria.
|
|
39
55
|
*/
|
|
40
56
|
init: async (config) => {
|
|
41
57
|
try {
|
|
42
58
|
setConfig(config);
|
|
43
59
|
initHttpClient();
|
|
44
60
|
const currentConfig = getConfig();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
|
|
62
|
+
if (currentConfig.customerId) {
|
|
63
|
+
const customer = await getCustomer();
|
|
64
|
+
const { token, userData } = customer.data;
|
|
65
|
+
setConfig({ ...currentConfig, token, userData });
|
|
66
|
+
setAuthToken(token);
|
|
67
|
+
return new ApacuanaSuccess({
|
|
68
|
+
initialized: true,
|
|
69
|
+
message: "SDK inicializado con sesión de usuario.",
|
|
70
|
+
});
|
|
52
71
|
}
|
|
53
72
|
|
|
54
|
-
const customer = await getCustomer();
|
|
55
|
-
const { token, userData } = customer.data;
|
|
56
|
-
setConfig({ ...currentConfig, token, userData });
|
|
57
|
-
setAuthToken(token);
|
|
58
73
|
return new ApacuanaSuccess({
|
|
59
74
|
initialized: true,
|
|
60
|
-
message: "SDK inicializado
|
|
75
|
+
message: "SDK inicializado para operaciones públicas (sin customerId).",
|
|
61
76
|
});
|
|
62
77
|
} catch (error) {
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
78
|
console.error("Error durante la inicialización del SDK:", error);
|
|
65
79
|
if (error instanceof ApacuanaAPIError) {
|
|
66
80
|
throw error;
|
|
@@ -72,25 +86,84 @@ const apacuana = {
|
|
|
72
86
|
);
|
|
73
87
|
}
|
|
74
88
|
},
|
|
89
|
+
|
|
90
|
+
// --- Métodos de Revocación ---
|
|
91
|
+
requestRevocation: (data) => {
|
|
92
|
+
checkSdk(true);
|
|
93
|
+
return requestRevocation(data);
|
|
94
|
+
},
|
|
95
|
+
getRevocationReasons: () => {
|
|
96
|
+
checkSdk(true);
|
|
97
|
+
return getRevocationReasons();
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// --- Métodos de Certificados ---
|
|
101
|
+
generateCert: (data) => {
|
|
102
|
+
checkSdk(true);
|
|
103
|
+
return generateCert(data);
|
|
104
|
+
},
|
|
105
|
+
getCertStatus: (isCertificateInDevice) => {
|
|
106
|
+
checkSdk(true);
|
|
107
|
+
return getCertStatus(isCertificateInDevice);
|
|
108
|
+
},
|
|
109
|
+
getCertTypes: () => {
|
|
110
|
+
checkSdk(false);
|
|
111
|
+
return getCertTypes();
|
|
112
|
+
},
|
|
113
|
+
getRequerimentsByTypeUser: (data) => {
|
|
114
|
+
checkSdk(false);
|
|
115
|
+
return getRequerimentsByTypeUser(data);
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
// --- Métodos de Firmas y Documentos ---
|
|
119
|
+
addSigner: (data) => {
|
|
120
|
+
checkSdk(true);
|
|
121
|
+
return addSigner(data);
|
|
122
|
+
},
|
|
123
|
+
deleteSignatureVariant: () => {
|
|
124
|
+
checkSdk(true);
|
|
125
|
+
return deleteSignatureVariant();
|
|
126
|
+
},
|
|
127
|
+
getDigest: (data) => {
|
|
128
|
+
checkSdk(true);
|
|
129
|
+
return getDigest(data);
|
|
130
|
+
},
|
|
131
|
+
getDocs: (data) => {
|
|
132
|
+
checkSdk(true);
|
|
133
|
+
return getDocs(data);
|
|
134
|
+
},
|
|
135
|
+
getSignatureVariant: () => {
|
|
136
|
+
checkSdk(true);
|
|
137
|
+
return getSignatureVariant();
|
|
138
|
+
},
|
|
139
|
+
signDocument: (data) => {
|
|
140
|
+
checkSdk(true);
|
|
141
|
+
return signDocument(data);
|
|
142
|
+
},
|
|
143
|
+
uploadSignatureVariant: (data) => {
|
|
144
|
+
checkSdk(true);
|
|
145
|
+
return uploadSignatureVariant(data);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
getCustomer: () => {
|
|
149
|
+
checkSdk(true);
|
|
150
|
+
return getCustomer();
|
|
151
|
+
},
|
|
152
|
+
createFaceLivenessSession: () => {
|
|
153
|
+
checkSdk(true);
|
|
154
|
+
return createFaceLivenessSession();
|
|
155
|
+
},
|
|
156
|
+
createApacuanaUser: (data) => {
|
|
157
|
+
checkSdk(false);
|
|
158
|
+
return createApacuanaUser(data);
|
|
159
|
+
},
|
|
160
|
+
validateFaceLiveness: (data) => {
|
|
161
|
+
checkSdk(true);
|
|
162
|
+
return validateFaceLiveness(data);
|
|
163
|
+
},
|
|
164
|
+
|
|
75
165
|
close: () => close(),
|
|
76
166
|
getConfig,
|
|
77
|
-
requestRevocation,
|
|
78
|
-
getCertStatus,
|
|
79
|
-
getCustomer,
|
|
80
|
-
addSigner,
|
|
81
|
-
getDocs,
|
|
82
|
-
generateCert,
|
|
83
|
-
signDocument,
|
|
84
|
-
getDigest,
|
|
85
|
-
getRevocationReasons,
|
|
86
|
-
uploadSignatureVariant,
|
|
87
|
-
getSignatureVariant,
|
|
88
|
-
deleteSignatureVariant,
|
|
89
|
-
getCertTypes,
|
|
90
|
-
getRequerimentsByTypeUser,
|
|
91
|
-
createFaceLivenessSession,
|
|
92
|
-
validateFaceLiveness,
|
|
93
|
-
// requestCertificate,
|
|
94
167
|
};
|
|
95
168
|
|
|
96
169
|
export default apacuana;
|
package/src/types/certs.js
CHANGED
|
@@ -1,45 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {
|
|
3
|
-
* @property {string} cert - El certificado generado en formato string.
|
|
4
|
-
* @property {string} certifiedid - El ID del certificado generado.
|
|
5
|
-
* @property {boolean} success - Indica si la operación fue exitosa.
|
|
2
|
+
* @typedef {import('../success').ApacuanaSuccess} ApacuanaSuccess
|
|
6
3
|
*/
|
|
7
4
|
|
|
5
|
+
// Tipos de datos para las respuestas
|
|
8
6
|
/**
|
|
9
|
-
* @typedef {object}
|
|
10
|
-
* @property {string}
|
|
11
|
-
* @property {
|
|
7
|
+
* @typedef {object} GenerateCertResponseData
|
|
8
|
+
* @property {string} cert - El certificado generado en formato string.
|
|
9
|
+
* @property {string} certifiedid - El ID del certificado generado.
|
|
12
10
|
*/
|
|
13
|
-
|
|
14
11
|
/**
|
|
15
|
-
* @typedef {object}
|
|
16
|
-
* @property {string}
|
|
12
|
+
* @typedef {object} GetCertStatusResponseData
|
|
13
|
+
* @property {string} status - El estado actual del certificado del usuario.
|
|
17
14
|
*/
|
|
18
|
-
|
|
19
15
|
/**
|
|
20
16
|
* @typedef {object} CertType
|
|
21
17
|
* @property {string} id - The ID of the certificate type.
|
|
22
18
|
* @property {string} name - The name of the certificate type.
|
|
23
19
|
*/
|
|
24
|
-
|
|
25
20
|
/**
|
|
26
|
-
* @typedef {object}
|
|
21
|
+
* @typedef {object} GetCertTypesResponseData
|
|
27
22
|
* @property {Array<CertType>} types - A list of available certificate types.
|
|
28
|
-
* @property {boolean} success - Indicates if the operation was successful.
|
|
29
23
|
*/
|
|
30
|
-
|
|
31
24
|
/**
|
|
32
25
|
* @typedef {object} Requirement
|
|
33
26
|
* @property {string} id - The ID of the requirement.
|
|
34
27
|
* @property {string} description - The description of the requirement.
|
|
35
28
|
*/
|
|
36
|
-
|
|
37
29
|
/**
|
|
38
|
-
* @typedef {object}
|
|
30
|
+
* @typedef {object} GetRequirementsResponseData
|
|
39
31
|
* @property {Array<Requirement>} requirements - A list of requirements for the user type.
|
|
40
|
-
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {object} RequestCertificateResponseData
|
|
35
|
+
* @property {string} message - A message confirming the request.
|
|
41
36
|
*/
|
|
42
37
|
|
|
38
|
+
// Tipos de respuesta combinados con ApacuanaSuccess
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {GenerateCertResponseData & ApacuanaSuccess} GenerateCertResponse
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {GetCertStatusResponseData & ApacuanaSuccess} GetCertStatusResponse
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {GetCertTypesResponseData & ApacuanaSuccess} GetCertTypesResponse
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {GetRequirementsResponseData & ApacuanaSuccess} GetRequirementsResponse
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {RequestCertificateResponseData & ApacuanaSuccess} RequestCertificateResponse
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
// Otros tipos de datos
|
|
56
|
+
/**
|
|
57
|
+
* @typedef {object} EncryptedCSRObject
|
|
58
|
+
* @property {string} csr - The encrypted Certificate Signing Request.
|
|
59
|
+
*/
|
|
43
60
|
/**
|
|
44
61
|
* @typedef {object} CertificateRequestParams
|
|
45
62
|
* @property {number} type - The user type to get requirements for.
|
|
@@ -47,10 +64,4 @@
|
|
|
47
64
|
* @property {Array<{id: string, file: string}>} documents - The documents required for the certificate.
|
|
48
65
|
*/
|
|
49
66
|
|
|
50
|
-
|
|
51
|
-
* @typedef {object} RequestCertificateResponse
|
|
52
|
-
* @property {string} message - A message confirming the request.
|
|
53
|
-
* @property {boolean} success - Indicates if the operation was successful.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
export {};
|
|
67
|
+
export {};
|
package/src/utils/constant.js
CHANGED
|
@@ -9,6 +9,43 @@ export const STATUS_CERTIFICATE = {
|
|
|
9
9
|
sign_pending: "PENDIENTE_POR_FIRMAR",
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
export const PARSE_STATUS = {
|
|
13
|
+
[STATUS_CERTIFICATE.certificate_another_device]: {
|
|
14
|
+
text: "Verificado",
|
|
15
|
+
descriptionText: undefined,
|
|
16
|
+
},
|
|
17
|
+
[STATUS_CERTIFICATE.request_cert]: {
|
|
18
|
+
text: "En revisión",
|
|
19
|
+
descriptionText:
|
|
20
|
+
"La información y documentos enviados están siendo certificados por la Autoridad de Certificación para confirmar su validez.",
|
|
21
|
+
},
|
|
22
|
+
[STATUS_CERTIFICATE.request]: {
|
|
23
|
+
text: "Por verificar",
|
|
24
|
+
descriptionText:
|
|
25
|
+
"La información y documentos enviados están siendo revisados por la Autoridad de Registro.",
|
|
26
|
+
},
|
|
27
|
+
[STATUS_CERTIFICATE.generate]: {
|
|
28
|
+
text: "Por generar",
|
|
29
|
+
descriptionText:
|
|
30
|
+
"Tu solicitud fue aprobada. Solo falta que generes tu certificado para comenzar a usarlo.",
|
|
31
|
+
},
|
|
32
|
+
[STATUS_CERTIFICATE.current]: {
|
|
33
|
+
text: " ",
|
|
34
|
+
descriptionText: undefined,
|
|
35
|
+
},
|
|
36
|
+
[STATUS_CERTIFICATE.expire]: "Certificado expirado.",
|
|
37
|
+
[STATUS_CERTIFICATE.request_revoque]: {
|
|
38
|
+
text: "Por revocar",
|
|
39
|
+
descriptionText:
|
|
40
|
+
"Recibimos tu solicitud de revocación y estamos procesándola. El certificado dejará de ser válido una vez finalice el trámite.",
|
|
41
|
+
},
|
|
42
|
+
[STATUS_CERTIFICATE.revoque]: {
|
|
43
|
+
text: "Revocado",
|
|
44
|
+
descriptionText:
|
|
45
|
+
"Este certificado ha sido revocado. Debes solicitar uno nuevo.",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
12
49
|
export const VERIFICATION_STATUS = {
|
|
13
50
|
IN_REGISTER: 0,
|
|
14
51
|
APPROVED: 1,
|
package/src/utils/helpers.js
CHANGED
|
@@ -17,6 +17,11 @@ const getCertificateStatus = (userData, certificateInDevice) => {
|
|
|
17
17
|
|
|
18
18
|
if (userData?.verificationstatus?.id !== VERIFICATION_STATUS.APPROVED)
|
|
19
19
|
return STATUS_CERTIFICATE.request;
|
|
20
|
+
if (
|
|
21
|
+
!userData?.certificationId &&
|
|
22
|
+
userData?.requestscert?.requests.length === 0
|
|
23
|
+
)
|
|
24
|
+
return STATUS_CERTIFICATE.request_cert;
|
|
20
25
|
if (
|
|
21
26
|
userData?.certificationId &&
|
|
22
27
|
!userData?.cangenerate &&
|
|
@@ -25,7 +30,6 @@ const getCertificateStatus = (userData, certificateInDevice) => {
|
|
|
25
30
|
userData?.certificatestatus !== STATUS_CERTIFICATE.revoque
|
|
26
31
|
)
|
|
27
32
|
return STATUS_CERTIFICATE.certificate_another_device;
|
|
28
|
-
|
|
29
33
|
if (userData?.requestscert?.pending && userData?.certificationId)
|
|
30
34
|
return STATUS_CERTIFICATE.request_revoque;
|
|
31
35
|
if (
|
|
@@ -33,10 +37,7 @@ const getCertificateStatus = (userData, certificateInDevice) => {
|
|
|
33
37
|
userData?.certificatestatus === STATUS_CERTIFICATE.revoque
|
|
34
38
|
)
|
|
35
39
|
return STATUS_CERTIFICATE.revoque;
|
|
36
|
-
|
|
37
|
-
if (!userData?.approvedUser) return STATUS_CERTIFICATE.request;
|
|
38
40
|
if (userData?.cangenerate) return STATUS_CERTIFICATE.generate;
|
|
39
|
-
|
|
40
41
|
if (userData?.certificationId) return STATUS_CERTIFICATE.current;
|
|
41
42
|
|
|
42
43
|
return STATUS_CERTIFICATE.revoque;
|
package/src/utils/httpClient.js
CHANGED
|
@@ -16,8 +16,7 @@ export const initHttpClient = () => {
|
|
|
16
16
|
!config.apiUrl ||
|
|
17
17
|
!config.secretKey ||
|
|
18
18
|
!config.apiKey ||
|
|
19
|
-
!config.verificationId
|
|
20
|
-
!config.customerId
|
|
19
|
+
!config.verificationId
|
|
21
20
|
) {
|
|
22
21
|
throw new Error(
|
|
23
22
|
"HttpClient: Configuración de inicialización incompleta. Llama a apacuana.init() primero."
|
package/tests/api/certs.test.js
CHANGED
|
@@ -85,9 +85,9 @@ describe("Certificate API - certs.js", () => {
|
|
|
85
85
|
|
|
86
86
|
describe("getCertStatus", () => {
|
|
87
87
|
it("should return the certificate status from helpers", () => {
|
|
88
|
-
const mockUserData = { certStatus: "
|
|
88
|
+
const mockUserData = { certStatus: "SOLICITUD" };
|
|
89
89
|
getConfig.mockReturnValue({ userData: mockUserData });
|
|
90
|
-
helpers.getCertificateStatus.mockReturnValue("
|
|
90
|
+
helpers.getCertificateStatus.mockReturnValue("SOLICITUD");
|
|
91
91
|
|
|
92
92
|
const result = getCertStatus(true);
|
|
93
93
|
|
|
@@ -96,7 +96,15 @@ describe("Certificate API - certs.js", () => {
|
|
|
96
96
|
true
|
|
97
97
|
);
|
|
98
98
|
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
99
|
-
|
|
99
|
+
|
|
100
|
+
// --- CORRECCIÓN AQUÍ: El objeto esperado debe estar anidado en la clave 'status' ---
|
|
101
|
+
expect(result.data).toEqual({
|
|
102
|
+
status: {
|
|
103
|
+
text: "Por verificar",
|
|
104
|
+
descriptionText:
|
|
105
|
+
"La información y documentos enviados están siendo revisados por la Autoridad de Registro.",
|
|
106
|
+
},
|
|
107
|
+
});
|
|
100
108
|
});
|
|
101
109
|
});
|
|
102
110
|
|
package/tests/api/users.test.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
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
|
-
import getCustomer from "../../src/api/users.js";
|
|
6
5
|
import ApacuanaSuccess from "../../src/success/index.js";
|
|
6
|
+
import { getCustomer } from "../../src/api/users.js";
|
|
7
7
|
|
|
8
8
|
// Mockear las dependencias:
|
|
9
9
|
jest.mock("../../src/utils/httpClient.js", () => ({
|