apacuana-sdk-core 0.10.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 (58) hide show
  1. package/README.md +305 -286
  2. package/coverage/clover.xml +345 -248
  3. package/coverage/coverage-final.json +9 -7
  4. package/coverage/lcov-report/index.html +41 -26
  5. package/coverage/lcov-report/src/api/certs.js.html +162 -87
  6. package/coverage/lcov-report/src/api/faceLiveness.js.html +523 -0
  7. package/coverage/lcov-report/src/api/index.html +43 -28
  8. package/coverage/lcov-report/src/api/revocations.js.html +132 -90
  9. package/coverage/lcov-report/src/api/signatures.js.html +25 -253
  10. package/coverage/lcov-report/src/api/users.js.html +23 -14
  11. package/coverage/lcov-report/src/config/index.html +1 -1
  12. package/coverage/lcov-report/src/config/index.js.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.html +1 -1
  14. package/coverage/lcov-report/src/errors/index.js.html +8 -8
  15. package/coverage/lcov-report/src/index.html +13 -13
  16. package/coverage/lcov-report/src/index.js.html +96 -12
  17. package/coverage/lcov-report/src/success/index.html +116 -0
  18. package/coverage/lcov-report/src/success/index.js.html +106 -0
  19. package/coverage/lcov-report/src/utils/constant.js.html +4 -4
  20. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  21. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  22. package/coverage/lcov-report/src/utils/index.html +1 -1
  23. package/coverage/lcov.info +597 -414
  24. package/dist/api/certs.d.ts +9 -70
  25. package/dist/api/faceLiveness.d.ts +6 -0
  26. package/dist/api/revocations.d.ts +6 -42
  27. package/dist/api/signatures.d.ts +11 -153
  28. package/dist/api/users.d.ts +16 -6
  29. package/dist/index.d.ts +6 -0
  30. package/dist/index.js +513 -259
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +513 -259
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/success/index.d.ts +7 -0
  35. package/dist/types/certs.d.ts +97 -0
  36. package/dist/types/faceLiveness.d.ts +11 -0
  37. package/dist/types/revocations.d.ts +51 -0
  38. package/dist/types/signatures.d.ts +147 -0
  39. package/dist/types/users.d.ts +260 -0
  40. package/package.json +1 -1
  41. package/src/api/certs.js +74 -49
  42. package/src/api/faceLiveness.js +146 -0
  43. package/src/api/revocations.js +76 -62
  44. package/src/api/signatures.js +21 -97
  45. package/src/api/users.js +12 -9
  46. package/src/index.js +33 -5
  47. package/src/success/index.js +8 -0
  48. package/src/types/certs.js +56 -0
  49. package/src/types/faceLiveness.js +16 -0
  50. package/src/types/revocations.js +45 -0
  51. package/src/types/signatures.js +91 -0
  52. package/src/types/users.js +73 -0
  53. package/tests/api/certs.test.js +99 -6
  54. package/tests/api/faceLiveness.test.js +170 -0
  55. package/tests/api/revocations.test.js +35 -35
  56. package/tests/api/signatures.test.js +11 -5
  57. package/tests/api/users.test.js +3 -2
  58. package/tests/index.test.js +16 -8
package/src/api/certs.js CHANGED
@@ -1,27 +1,21 @@
1
+ /**
2
+ * @typedef {import('../types/users').UserData} UserData
3
+ * @typedef {import('../types/certs').GenerateCertResponse} GenerateCertResponse
4
+ * @typedef {import('../types/certs').GetCertStatusResponse} GetCertStatusResponse
5
+ * @typedef {import('../types/certs').EncryptedCSRObject} EncryptedCSRObject
6
+ * @typedef {import('../types/certs').GetCertTypesResponse} GetCertTypesResponse
7
+ * @typedef {import('../types/certs').GetRequirementsResponse} GetRequirementsResponse
8
+ * @typedef {import('../types/certs').CertificateRequestParams} CertificateRequestParams
9
+ * @typedef {import('../types/certs').RequestCertificateResponse} RequestCertificateResponse
10
+ */
11
+
1
12
  import { getConfig } from "../config/index";
2
13
  import { httpRequest } from "../utils/httpClient";
3
14
  import helpers from "../utils/helpers";
4
15
  import { ApacuanaAPIError } from "../errors";
16
+ import ApacuanaSuccess from "../success";
5
17
  import { INTEGRATION_TYPE } from "../utils/constant";
6
18
 
7
- /**
8
- * @typedef {object} GenerateCertResponse
9
- * @property {string} cert - El certificado generado en formato string.
10
- * @property {string} certifiedid - El ID del certificado generado.
11
- * @property {boolean} success - Indica si la operación fue exitosa.
12
- */
13
-
14
- /**
15
- * @typedef {object} GetCertStatusResponse
16
- * @property {string} status - El estado actual del certificado del usuario.
17
- * @property {boolean} success - Indica si la operación fue exitosa.
18
- */
19
-
20
- /**
21
- * @typedef {object} EncryptedCSRObject
22
- * @property {string} csr - The encrypted Certificate Signing Request.
23
- */
24
-
25
19
  /**
26
20
  * @param {EncryptedCSRObject} encryptedCSR
27
21
  */
@@ -41,7 +35,7 @@ const generateCertOnBoarding = async (encryptedCSR) => {
41
35
  );
42
36
  }
43
37
 
44
- return { cert, certifiedid, success: true };
38
+ return new ApacuanaSuccess({ cert, certifiedid });
45
39
  } catch (error) {
46
40
  // The captured error is re-thrown, which will already be of type ApacuanaAPIError or a native Error.
47
41
  if (error instanceof ApacuanaAPIError) {
@@ -94,24 +88,9 @@ export const getCertStatus = (isCertificateInDevice = false) => {
94
88
  config.userData,
95
89
  isCertificateInDevice
96
90
  );
97
- return {
98
- status,
99
- success: true,
100
- };
91
+ return new ApacuanaSuccess({ status });
101
92
  };
102
93
 
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
94
  const getCertTypesOnBoarding = async () => {
116
95
  try {
117
96
  const response = await httpRequest(
@@ -120,7 +99,7 @@ const getCertTypesOnBoarding = async () => {
120
99
  "GET"
121
100
  );
122
101
 
123
- return { ...response, success: true };
102
+ return new ApacuanaSuccess(response);
124
103
  } catch (error) {
125
104
  if (error instanceof ApacuanaAPIError) {
126
105
  throw error;
@@ -159,18 +138,6 @@ export const getCertTypes = async () => {
159
138
  );
160
139
  };
161
140
 
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
141
  const getRequerimentsByTypeUserOnBoarding = async (type) => {
175
142
  try {
176
143
  const response = await httpRequest(
@@ -179,7 +146,7 @@ const getRequerimentsByTypeUserOnBoarding = async (type) => {
179
146
  "GET"
180
147
  );
181
148
 
182
- return { ...response, success: true };
149
+ return new ApacuanaSuccess(response);
183
150
  } catch (error) {
184
151
  if (error instanceof ApacuanaAPIError) {
185
152
  throw error;
@@ -226,3 +193,61 @@ export const getRequerimentsByTypeUser = async (params) => {
226
193
  "UNSUPPORTED_INTEGRATION_TYPE"
227
194
  );
228
195
  };
196
+
197
+ const requestCertificateOnBoarding = async (params) => {
198
+ try {
199
+ const response = await httpRequest(
200
+ "services/api/customer/request-certificate",
201
+ params,
202
+ "POST"
203
+ );
204
+
205
+ return new ApacuanaSuccess(response);
206
+ } catch (error) {
207
+ if (error instanceof ApacuanaAPIError) {
208
+ throw error;
209
+ }
210
+ throw new Error(`Failed to request certificate: ${error.message}`);
211
+ }
212
+ };
213
+
214
+ const requestCertificateOnPremise = async () => {
215
+ throw new ApacuanaAPIError(
216
+ "Requesting a certificate is not supported for integration type: ONPREMISE",
217
+ 501,
218
+ "NOT_IMPLEMENTED"
219
+ );
220
+ };
221
+
222
+ /**
223
+ * Requests a certificate for the user.
224
+ * @param {CertificateRequestParams} params - The parameters for the certificate request.
225
+ * @returns {Promise<RequestCertificateResponse>} Object with a confirmation message and a success indicator.
226
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
227
+ * @throws {Error} If the request fails for another reason or the params are invalid.
228
+ */
229
+ export const requestCertificate = async (params) => {
230
+ if (
231
+ !params ||
232
+ typeof params.type !== "number" ||
233
+ !Array.isArray(params.documents)
234
+ ) {
235
+ throw new Error(
236
+ 'The "params" object with a numeric "type" property and a "documents" array is required.'
237
+ );
238
+ }
239
+
240
+ const { integrationType } = getConfig();
241
+ if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
242
+ return requestCertificateOnBoarding(params);
243
+ }
244
+ if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
245
+ return requestCertificateOnPremise();
246
+ }
247
+
248
+ throw new ApacuanaAPIError(
249
+ `Unsupported integration type: ${integrationType}`,
250
+ 400,
251
+ "UNSUPPORTED_INTEGRATION_TYPE"
252
+ );
253
+ };
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @typedef {import('../types/faceLiveness').CreateFaceLivenessSessionResponse} CreateFaceLivenessSessionResponse
3
+ */
4
+
5
+ import { getConfig } from "../config/index";
6
+ import { httpRequest } from "../utils/httpClient";
7
+ import { ApacuanaAPIError } from "../errors";
8
+ import ApacuanaSuccess from "../success";
9
+ import { INTEGRATION_TYPE } from "../utils/constant";
10
+
11
+ /**
12
+ * Creates a new Face Liveness session.
13
+ * @returns {Promise<CreateFaceLivenessSessionResponse>} Object with the session ID and a success indicator.
14
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
15
+ * @throws {Error} If the request fails for another reason.
16
+ */
17
+ const createFaceLivenessSessionOnBoarding = async () => {
18
+ try {
19
+ const response = await httpRequest(
20
+ "services/api/faceliveness/create",
21
+ {},
22
+ "POST"
23
+ );
24
+ if (!response.sessionid) {
25
+ throw new ApacuanaAPIError(
26
+ "The API response does not contain the session ID.",
27
+ response.status,
28
+ "INVALID_API_RESPONSE"
29
+ );
30
+ }
31
+
32
+ return new ApacuanaSuccess({
33
+ sessionId: response.sessionid,
34
+ });
35
+ } catch (error) {
36
+ if (error instanceof ApacuanaAPIError) {
37
+ throw error;
38
+ }
39
+ throw new ApacuanaAPIError(
40
+ `Failed to create Face Liveness session: ${error.message}`
41
+ );
42
+ }
43
+ };
44
+
45
+ const createFaceLivenessSessionOnPremise = async () => {
46
+ throw new ApacuanaAPIError(
47
+ "Creating a Face Liveness session is not supported for integration type: ONPREMISE",
48
+ 501,
49
+ "NOT_IMPLEMENTED"
50
+ );
51
+ };
52
+
53
+ const validateFaceLivenessOnBoarding = async (sessionId) => {
54
+ try {
55
+ const response = await httpRequest(
56
+ "services/api/faceliveness/validate",
57
+ { sessionid: sessionId },
58
+ "POST"
59
+ );
60
+ return new ApacuanaSuccess({ status: "verified", ...response });
61
+ } catch (error) {
62
+ if (error instanceof ApacuanaAPIError) {
63
+ let status;
64
+ switch (error.statusCode) {
65
+ case 402:
66
+ status = "waitingForScan";
67
+ break;
68
+ case 403:
69
+ status = "rejected";
70
+ break;
71
+ case 406:
72
+ status = "processing";
73
+ break;
74
+ case 408:
75
+ status = "expired";
76
+ break;
77
+ default:
78
+ throw error;
79
+ }
80
+ return new ApacuanaSuccess({ status });
81
+ }
82
+ throw error;
83
+ }
84
+ };
85
+
86
+ const validateFaceLivenessOnPremise = async () => {
87
+ throw new ApacuanaAPIError(
88
+ "Validating a Face Liveness session is not supported for integration type: ONPREMISE",
89
+ 501,
90
+ "NOT_IMPLEMENTED"
91
+ );
92
+ };
93
+
94
+ /**
95
+ * Creates a new Face Liveness session.
96
+ * @returns {Promise<CreateFaceLivenessSessionResponse>} Object with the session ID and a success indicator.
97
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
98
+ * @throws {Error} If the request fails for another reason.
99
+ */
100
+ export const createFaceLivenessSession = async () => {
101
+ const { integrationType } = getConfig();
102
+
103
+ if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
104
+ return createFaceLivenessSessionOnBoarding();
105
+ }
106
+ if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
107
+ return createFaceLivenessSessionOnPremise();
108
+ }
109
+
110
+ throw new ApacuanaAPIError(
111
+ `Unsupported integration type: ${integrationType}`,
112
+ 400,
113
+ "UNSUPPORTED_INTEGRATION_TYPE"
114
+ );
115
+ };
116
+
117
+ /**
118
+ * Validates a Face Liveness session and returns its status.
119
+ * @param {{sessionId: string}} params - Object containing the session ID.
120
+ * @returns {Promise<ApacuanaSuccess>} Object with the validation status.
121
+ * @throws {ApacuanaAPIError} If the API response is invalid or the integration type is not supported.
122
+ */
123
+ export const validateFaceLiveness = async ({ sessionId }) => {
124
+ if (!sessionId) {
125
+ throw new ApacuanaAPIError(
126
+ "sessionId is a required parameter.",
127
+ 400,
128
+ "INVALID_PARAMETER"
129
+ );
130
+ }
131
+
132
+ const { integrationType } = getConfig();
133
+
134
+ if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
135
+ return validateFaceLivenessOnBoarding(sessionId);
136
+ }
137
+ if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
138
+ return validateFaceLivenessOnPremise();
139
+ }
140
+
141
+ throw new ApacuanaAPIError(
142
+ `Unsupported integration type: ${integrationType}`,
143
+ 400,
144
+ "UNSUPPORTED_INTEGRATION_TYPE"
145
+ );
146
+ };
@@ -1,95 +1,109 @@
1
1
  import { httpRequest } from "../utils/httpClient";
2
- import { ApacuanaAPIError } from "../errors/index";
3
2
  import { getConfig } from "../config";
4
3
  import { INTEGRATION_TYPE } from "../utils/constant";
4
+ import { ApacuanaAPIError } from "../errors";
5
+ import ApacuanaSuccess from "../success";
5
6
 
6
- /**
7
- * @typedef {object} RequestRevocationResponse
8
- * @property {string} revocationStatus - El estado de la solicitud de revocación (e.g., "pending").
9
- * @property {string|number} requestId - El ID de la solicitud de revocación.
10
- */
11
-
12
- /**
13
- * Simula la solicitud de revocación de un certificado.
14
- * @param {string} reasonCode - Código o descripción del motivo de la revocación.
15
- * @returns {Promise<RequestRevocationResponse>} Objeto con el estado de la solicitud de revocación.
16
- */
17
- /**
18
- * @typedef {object} RevocationResponse
19
- * @property {boolean} success - Indicates if the revocation request was successful.
20
- * @property {string} [message] - A message providing details about the outcome.
21
- */
22
-
23
- /**
24
- * @typedef {object} RevocationReason
25
- * @property {string} code - The code for the revocation reason.
26
- * @property {string} description - The description of the revocation reason.
27
- */
28
-
29
- /**
30
- * @typedef {object} RevocationReasonsResponse
31
- * @property {boolean} success - Indicates if the request was successful.
32
- * @property {RevocationReason[]} reasons - A list of revocation reasons.
33
- */
34
-
35
- /**
36
- * Requests the revocation of a certificate.
37
- * @param {number} reasonCode - Código o descripción del motivo de la revocación.
38
- * @returns {Promise<RevocationResponse>} An object indicating the success of the request.
39
- * @throws {ApacuanaAPIError} If the revocation request fails.
40
- */
41
- export const requestRevocation = async (reasonCode) => {
42
- if (!reasonCode) {
43
- throw new Error("Código de motivo es requerido para requestRevocation.");
44
- }
7
+ /** @typedef {import("../types/revocations").RequestRevocationResponse} RequestRevocationResponse */
8
+ /** @typedef {import("../types/revocations").GetRevocationReasonsResponse} GetRevocationReasonsResponse */
45
9
 
10
+ const requestRevocationOnBoarding = async (params) => {
46
11
  try {
47
12
  const response = await httpRequest(
48
13
  "services/api/onboardingclient/requestcert",
49
- { reason: reasonCode },
14
+ params,
50
15
  "POST"
51
16
  );
52
-
53
- return response;
17
+ return new ApacuanaSuccess(response);
54
18
  } catch (error) {
55
- throw new Error(`Fallo en la solicitud de revocación: ${error.message}`);
19
+ if (error instanceof ApacuanaAPIError) {
20
+ throw error;
21
+ }
22
+ throw new Error(`Failed to request revocation: ${error.message}`);
56
23
  }
57
24
  };
58
25
 
26
+ const requestRevocationOnPremise = async () => {
27
+ throw new ApacuanaAPIError(
28
+ "Requesting revocation is not supported for integration type: ONPREMISE",
29
+ 501,
30
+ "NOT_IMPLEMENTED"
31
+ );
32
+ };
33
+
59
34
  /**
60
- * Retrieves the available reasons for certificate revocation.
61
- * @returns {Promise<RevocationReasonsResponse>} An object containing the list of revocation reasons.
62
- * @throws {ApacuanaAPIError} If fetching the reasons fails.
35
+ * Solicita la revocación de un certificado.
36
+ * @param {object} params - Parámetros para la solicitud.
37
+ * @param {number} params.reasonCode - El código de la razón de la revocación.
38
+ * @returns {Promise<RequestRevocationResponse>} Una promesa que resuelve con la confirmación de la solicitud.
39
+ * @throws {Error} Si los parámetros son inválidos.
63
40
  */
64
- export const getRevocationReasons = async () => {
41
+ export const requestRevocation = async (params) => {
42
+ if (!params || typeof params.reasonCode !== "number") {
43
+ throw new Error(
44
+ 'The "params" object with a numeric "reasonCode" property is required.'
45
+ );
46
+ }
47
+
65
48
  const { integrationType } = getConfig();
66
49
 
50
+ if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
51
+ return requestRevocationOnBoarding(params);
52
+ }
67
53
  if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
68
- throw new ApacuanaAPIError(
69
- `Get revocation reasons is not supported for integration type: ${integrationType}`,
70
- 501,
71
- "NOT_IMPLEMENTED"
72
- );
54
+ return requestRevocationOnPremise(params);
73
55
  }
56
+ throw new ApacuanaAPIError(
57
+ `Unsupported integration type: ${integrationType}`,
58
+ 400,
59
+ "UNSUPPORTED_INTEGRATION_TYPE"
60
+ );
61
+ };
74
62
 
63
+ const getRevocationReasonsOnBoarding = async () => {
75
64
  try {
76
65
  const response = await httpRequest(
77
- "GET",
78
66
  "config/api/revocation/reasonsonboarding",
79
- {}
67
+ {},
68
+ "GET"
80
69
  );
81
-
82
- if (!response.records) {
70
+ if (!response || !response.records) {
83
71
  throw new ApacuanaAPIError("Failed to fetch revocation reasons.");
84
72
  }
85
-
86
- return response.records;
73
+ return new ApacuanaSuccess({ reasons: response.records });
87
74
  } catch (error) {
88
75
  if (error instanceof ApacuanaAPIError) {
89
76
  throw error;
90
77
  }
91
- throw new Error(
92
- "Failed to get revocation reasons. Please try again later."
93
- );
78
+ throw new Error(`Failed to get revocation reasons: ${error.message}`);
79
+ }
80
+ };
81
+
82
+ const getRevocationReasonsOnPremise = async () => {
83
+ throw new ApacuanaAPIError(
84
+ "Getting revocation reasons is not supported for integration type: ONPREMISE",
85
+ 501,
86
+ "NOT_IMPLEMENTED"
87
+ );
88
+ };
89
+
90
+ /**
91
+ * Obtiene la lista de razones de revocación de certificados.
92
+ * @returns {Promise<GetRevocationReasonsResponse>} Una promesa que resuelve con la lista de razones de revocación.
93
+ * @throws {ApacuanaAPIError} Si la llamada a la API falla o el tipo de integración no es soportado.
94
+ */
95
+ export const getRevocationReasons = async () => {
96
+ const { integrationType } = getConfig();
97
+
98
+ if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
99
+ return getRevocationReasonsOnBoarding();
100
+ }
101
+ if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
102
+ return getRevocationReasonsOnPremise();
94
103
  }
104
+ throw new ApacuanaAPIError(
105
+ `Unsupported integration type: ${integrationType}`,
106
+ 400,
107
+ "UNSUPPORTED_INTEGRATION_TYPE"
108
+ );
95
109
  };
@@ -2,72 +2,20 @@
2
2
  import { getConfig } from "../config/index";
3
3
  import { httpRequest } from "../utils/httpClient";
4
4
  import { ApacuanaAPIError } from "../errors";
5
+ import ApacuanaSuccess from "../success";
5
6
  import helpers from "../utils/helpers";
6
7
  import { INTEGRATION_TYPE } from "../utils/constant";
7
8
 
8
- // =================================================================
9
- // Type Definitions
10
- // =================================================================
11
-
12
- /**
13
- * Define la estructura de un objeto Firmante.
14
- * @typedef {object} Signer
15
- * @property {string} name - Nombre completo del firmante.
16
- * @property {string} email - Correo electrónico del firmante.
17
- * @property {string} document - Documento de identidad del firmante.
18
- */
19
-
20
- /**
21
- * Define la estructura de datos para añadir un firmante.
22
- * @typedef {object} SignerData
23
- * @property {string} docId - Identificador único del documento.
24
- */
25
-
26
- /**
27
- * Define la estructura de la respuesta al añadir un firmante.
28
- * @typedef {object} AddSignerResponse
29
- * @property {string} signer - Identificador de confirmación del firmante añadido.
30
- * @property {boolean} success - Indica si la operación fue exitosa.
31
- */
32
-
33
- /**
34
- * Define la estructura de datos para obtener el digest de un documento.
35
- * @typedef {object} GetDigestData
36
- * @property {string} cert - Certificado del firmante en formato base64.
37
- * @property {string} signatureId - Identificador único del proceso de firma.
38
- */
39
-
40
- /**
41
- * Define la estructura de la respuesta al obtener el digest.
42
- * @typedef {object} GetDigestResponse
43
- * @property {string} digest - El digest del documento que se va a firmar.
44
- * @property {boolean} success - Indica si la operación fue exitosa.
45
- */
46
-
47
- /**
48
- * Define la estructura de los parámetros para obtener documentos.
49
- * @typedef {object} GetDocsParams
50
- * @property {number} page - Número de página para la paginación.
51
- * @property {number} size - Cantidad de registros por página.
52
- * @property {string} [status] - (Opcional) Estado para filtrar los documentos.
53
- */
54
-
55
- /**
56
- * Define la estructura de la respuesta al obtener documentos.
57
- * @typedef {object} GetDocsResponse
58
- * @property {number} totalRecords - El número total de registros encontrados.
59
- * @property {Array<object>} records - Un arreglo con los registros de los documentos.
60
- * @property {boolean} success - Indica si la operación fue exitosa.
61
- */
62
-
63
- /**
64
- * @typedef {object} SignDocumentData
65
- * @property {object} signature - Objeto con información de la firma.
66
- * @property {string} signature.id - ID de la firma.
67
- * @property {Array<object>} signature.positions - Posiciones de la firma.
68
- * @property {string} cert - Certificado en base64.
69
- * @property {string} signedDigest - Digest firmado.
70
- */
9
+ /** @typedef {import("../types/signatures").Signer} Signer */
10
+ /** @typedef {import("../types/signatures").SignerData} SignerData */
11
+ /** @typedef {import("../types/signatures").AddSignerResponse} AddSignerResponse */
12
+ /** @typedef {import("../types/signatures").GetDigestData} GetDigestData */
13
+ /** @typedef {import("../types/signatures").GetDigestResponse} GetDigestResponse */
14
+ /** @typedef {import("../types/signatures").GetDocsParams} GetDocsParams */
15
+ /** @typedef {import("../types/signatures").GetDocsResponse} GetDocsResponse */
16
+ /** @typedef {import("../types/signatures").SignDocumentData} SignDocumentData */
17
+ /** @typedef {import("../types/signatures").SignaturePosition} SignaturePosition */
18
+ /** @typedef {import("../types/signatures").OnboardingSignerData} OnboardingSignerData */
71
19
 
72
20
  // =================================================================
73
21
  // Internal Functions
@@ -95,7 +43,7 @@ const signDocumentOnBoarding = async (signData) => {
95
43
  signBody,
96
44
  "PUT"
97
45
  );
98
- return response;
46
+ return new ApacuanaSuccess(response);
99
47
  } catch (error) {
100
48
  if (error instanceof ApacuanaAPIError) {
101
49
  throw error;
@@ -132,7 +80,7 @@ const getDigestToSignOnBoarding = async (signData) => {
132
80
  );
133
81
  }
134
82
 
135
- return { digest, success: true };
83
+ return new ApacuanaSuccess({ digest });
136
84
  } catch (error) {
137
85
  if (error.name === "ApacuanaAPIError") {
138
86
  throw error;
@@ -155,7 +103,9 @@ const addSignerOnBoarding = async (signerData) => {
155
103
  helpers.validateOnBoardingSignerData(signerData);
156
104
  try {
157
105
  await httpRequest("services/api/documents/signing", signerData, "POST");
158
- return { signer: signerData.typedoc + signerData.doc, success: true };
106
+ return new ApacuanaSuccess({
107
+ signer: signerData.typedoc + signerData.doc,
108
+ });
159
109
  } catch (error) {
160
110
  if (error instanceof ApacuanaAPIError) {
161
111
  throw error;
@@ -203,11 +153,10 @@ const getDocsOnBoarding = async (data) => {
203
153
 
204
154
  const apiUrl = `services/api/documents/listcustomer?${params.toString()}`;
205
155
  const response = await httpRequest(apiUrl, {}, "GET");
206
- return {
156
+ return new ApacuanaSuccess({
207
157
  totalRecords: response.numofrecords,
208
158
  records: response.records,
209
- success: true,
210
- };
159
+ });
211
160
  } catch (error) {
212
161
  if (error.name === "ApacuanaAPIError") {
213
162
  throw error;
@@ -225,7 +174,7 @@ const uploadSignatureVariantOnBoarding = async ({ file }) => {
225
174
  { file },
226
175
  "POST"
227
176
  );
228
- return { ...response, success: true };
177
+ return new ApacuanaSuccess(response);
229
178
  } catch (error) {
230
179
  if (error instanceof ApacuanaAPIError) {
231
180
  throw error;
@@ -252,7 +201,7 @@ const getSignatureVariantOnBoarding = async () => {
252
201
  {},
253
202
  "GET"
254
203
  );
255
- return { ...response, success: true };
204
+ return new ApacuanaSuccess(response);
256
205
  } catch (error) {
257
206
  if (error instanceof ApacuanaAPIError) {
258
207
  throw error;
@@ -278,7 +227,7 @@ const deleteSignatureVariantOnBoarding = async () => {
278
227
  {},
279
228
  "DELETE"
280
229
  );
281
- return { ...response, success: true };
230
+ return new ApacuanaSuccess(response);
282
231
  } catch (error) {
283
232
  if (error instanceof ApacuanaAPIError) {
284
233
  throw error;
@@ -358,31 +307,6 @@ export const getDigest = async (signData) => {
358
307
  * @returns {Promise<AddSignerResponse>} Una promesa que resuelve a un objeto con el resultado de la operación.
359
308
  * @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.
360
309
  */
361
- /**
362
- * @typedef {object} SignaturePosition
363
- * @property {number} page - The page number for the signature.
364
- * @property {number} x - The x-coordinate for the signature's position (from 0 to 1).
365
- * @property {number} y - The y-coordinate for the signature's position (from 0 to 1).
366
- */
367
-
368
- /**
369
- * @typedef {object} OnboardingSignerData
370
- * @property {string} name - The name of the document.
371
- * @property {string} reference - An external reference for the document.
372
- * @property {string} typedoc - The type of document of the signer (e.g., "V", "E", "J").
373
- * @property {string} doc - The document number of the signer.
374
- * @property {SignaturePosition[]} signature - An array of signature positions.
375
- */
376
-
377
- /**
378
- * Adds a new signer to the signature process.
379
- * This function acts as a dispatcher, delegating to the appropriate implementation
380
- * based on the configured integration type.
381
- *
382
- * @param {OnboardingSignerData | object} signerData - The signer's data. The structure depends on the integration type.
383
- * @returns {Promise<object>} The result from the API.
384
- * @throws {ApacuanaAPIError} If signerData is invalid or if the integration type is not supported.
385
- */
386
310
  export const addSigner = async (signerData) => {
387
311
  if (
388
312
  !signerData ||