apacuana-sdk-core 0.4.0 → 0.5.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/coverage/clover.xml +72 -72
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/src/api/certs.js.html +1 -1
- package/coverage/lcov-report/src/api/index.html +1 -1
- package/coverage/lcov-report/src/api/revocations.js.html +1 -1
- package/coverage/lcov-report/src/api/signatures.js.html +320 -140
- 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 +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.js.html +1 -1
- 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 +121 -121
- package/dist/api/signatures.d.ts +103 -12
- package/dist/index.js +88 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -88
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/signatures.js +156 -96
- package/tests/api/signatures.test.js +11 -4
package/package.json
CHANGED
package/src/api/signatures.js
CHANGED
|
@@ -5,6 +5,66 @@ import { ApacuanaAPIError } from "../errors";
|
|
|
5
5
|
import helpers from "../utils/helpers";
|
|
6
6
|
import { INTEGRATION_TYPE } from "../utils/constant";
|
|
7
7
|
|
|
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
|
+
* @property {Signer} signer - Objeto con la información del firmante.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Define la estructura de la respuesta al añadir un firmante.
|
|
29
|
+
* @typedef {object} AddSignerResponse
|
|
30
|
+
* @property {string} signer - Identificador de confirmación del firmante añadido.
|
|
31
|
+
* @property {boolean} success - Indica si la operación fue exitosa.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Define la estructura de datos para obtener el digest de un documento.
|
|
36
|
+
* @typedef {object} GetDigestData
|
|
37
|
+
* @property {string} cert - Certificado del firmante en formato base64.
|
|
38
|
+
* @property {string} signatureId - Identificador único del proceso de firma.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Define la estructura de la respuesta al obtener el digest.
|
|
43
|
+
* @typedef {object} GetDigestResponse
|
|
44
|
+
* @property {string} digest - El digest del documento que se va a firmar.
|
|
45
|
+
* @property {boolean} success - Indica si la operación fue exitosa.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Define la estructura de los parámetros para obtener documentos.
|
|
50
|
+
* @typedef {object} GetDocsParams
|
|
51
|
+
* @property {number} page - Número de página para la paginación.
|
|
52
|
+
* @property {number} size - Cantidad de registros por página.
|
|
53
|
+
* @property {string} [status] - (Opcional) Estado para filtrar los documentos.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Define la estructura de la respuesta al obtener documentos.
|
|
58
|
+
* @typedef {object} GetDocsResponse
|
|
59
|
+
* @property {number} totalRecords - El número total de registros encontrados.
|
|
60
|
+
* @property {Array<object>} records - Un arreglo con los registros de los documentos.
|
|
61
|
+
* @property {boolean} success - Indica si la operación fue exitosa.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
// =================================================================
|
|
65
|
+
// Internal Functions
|
|
66
|
+
// =================================================================
|
|
67
|
+
|
|
8
68
|
const signDocumentOnBoarding = async () => {
|
|
9
69
|
throw new ApacuanaAPIError(
|
|
10
70
|
"Document signing is not supported for integration type: ONBOARDING",
|
|
@@ -21,30 +81,6 @@ const signDocumentOnPremise = async () => {
|
|
|
21
81
|
);
|
|
22
82
|
};
|
|
23
83
|
|
|
24
|
-
/**
|
|
25
|
-
* Signs a PDF document with a digital certificate.
|
|
26
|
-
* @param {object} data - Data for the signature. For 'on-boarding', it must contain {documentData, signatureData}. For 'on-premise', it must contain {signature, cert, privateKey}.
|
|
27
|
-
* @returns {Promise<{digest: string}>} Object with the document's digest.
|
|
28
|
-
* @throws {ApacuanaAPIError} If the integration type is not supported or the function is not implemented for the integration type.
|
|
29
|
-
*/
|
|
30
|
-
export const signDocument = async () => {
|
|
31
|
-
const { integrationType } = getConfig();
|
|
32
|
-
|
|
33
|
-
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
34
|
-
return signDocumentOnBoarding();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
38
|
-
return signDocumentOnPremise();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw new ApacuanaAPIError(
|
|
42
|
-
`Unsupported integration type: ${integrationType}`,
|
|
43
|
-
400,
|
|
44
|
-
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
84
|
const getDigestToSignOnBoarding = async (signData) => {
|
|
49
85
|
try {
|
|
50
86
|
const response = await httpRequest(
|
|
@@ -82,45 +118,16 @@ const getDigestToSignOnPremise = async () => {
|
|
|
82
118
|
);
|
|
83
119
|
};
|
|
84
120
|
|
|
85
|
-
/**
|
|
86
|
-
* Gets the digest of a document to be signed.
|
|
87
|
-
* @param {object} signData - Data for the signature. Must contain { cert, signatureId }.
|
|
88
|
-
* @returns {Promise<{digest: string, success: boolean}>} Object with the document's digest.
|
|
89
|
-
* @throws {ApacuanaAPIError} If the input data is invalid, if the API call fails, or if the integration type is not supported.
|
|
90
|
-
*/
|
|
91
|
-
export const getDigest = async (signData) => {
|
|
92
|
-
helpers.validateGetDigestData(signData);
|
|
93
|
-
|
|
94
|
-
const { integrationType } = getConfig();
|
|
95
|
-
|
|
96
|
-
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
97
|
-
return getDigestToSignOnBoarding(signData);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
101
|
-
return getDigestToSignOnPremise();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
throw new ApacuanaAPIError(
|
|
105
|
-
`Document retrieval is not supported for an unknown integration type: ${integrationType}`,
|
|
106
|
-
501,
|
|
107
|
-
"NOT_IMPLEMENTED"
|
|
108
|
-
);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
121
|
const addSignerOnBoarding = async (signerData) => {
|
|
112
122
|
helpers.validateOnBoardingSignerData(signerData);
|
|
113
123
|
try {
|
|
114
|
-
// Current httpRequest logic is moved here
|
|
115
124
|
await httpRequest("services/api/documents/signing", signerData, "POST");
|
|
116
125
|
return { signer: signerData.typedoc + signerData.doc, success: true };
|
|
117
126
|
} catch (error) {
|
|
118
127
|
if (error instanceof ApacuanaAPIError) {
|
|
119
128
|
throw error;
|
|
120
129
|
}
|
|
121
|
-
throw new Error(
|
|
122
|
-
`Failed to add signer in On-Boarding: ${error.message}`
|
|
123
|
-
);
|
|
130
|
+
throw new Error(`Failed to add signer in On-Boarding: ${error.message}`);
|
|
124
131
|
}
|
|
125
132
|
};
|
|
126
133
|
|
|
@@ -132,45 +139,9 @@ const addSignerOnPremise = async () => {
|
|
|
132
139
|
);
|
|
133
140
|
};
|
|
134
141
|
|
|
135
|
-
/**
|
|
136
|
-
* Adds a signer to a document, handling different integration types.
|
|
137
|
-
* @param {object} signerData - Data of the signer to be added.
|
|
138
|
-
* @returns {Promise<{signer: string, success: boolean}>} Object with the result of adding the signer.
|
|
139
|
-
* @throws {ApacuanaAPIError} If the signer data is invalid, if the API call fails, or if the integration type is not supported.
|
|
140
|
-
*/
|
|
141
|
-
export const addSigner = async (signerData) => {
|
|
142
|
-
if (
|
|
143
|
-
!signerData ||
|
|
144
|
-
typeof signerData !== "object" ||
|
|
145
|
-
Object.keys(signerData).length === 0
|
|
146
|
-
) {
|
|
147
|
-
throw new ApacuanaAPIError(
|
|
148
|
-
"Signer data (signerData) is required and must be a non-empty object.",
|
|
149
|
-
400,
|
|
150
|
-
"INVALID_PARAMETER"
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const { integrationType } = getConfig();
|
|
155
|
-
|
|
156
|
-
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
157
|
-
return addSignerOnBoarding(signerData);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
161
|
-
return addSignerOnPremise(signerData);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
throw new ApacuanaAPIError(
|
|
165
|
-
`Unsupported integration type: ${integrationType}`,
|
|
166
|
-
400,
|
|
167
|
-
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
168
|
-
);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
142
|
const getDocsOnPremise = async () => {
|
|
172
143
|
throw new ApacuanaAPIError(
|
|
173
|
-
"Document retrieval is not supported for integration type:
|
|
144
|
+
"Document retrieval is not supported for integration type: ONPREMISE",
|
|
174
145
|
501,
|
|
175
146
|
"NOT_IMPLEMENTED"
|
|
176
147
|
);
|
|
@@ -209,16 +180,105 @@ const getDocsOnBoarding = async (data) => {
|
|
|
209
180
|
throw error;
|
|
210
181
|
}
|
|
211
182
|
throw new ApacuanaAPIError(
|
|
212
|
-
`Failed to get document list (on-
|
|
183
|
+
`Failed to get document list (on-boarding): ${error.message}`
|
|
213
184
|
);
|
|
214
185
|
}
|
|
215
186
|
};
|
|
216
187
|
|
|
188
|
+
// =================================================================
|
|
189
|
+
// Exported Functions
|
|
190
|
+
// =================================================================
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Firma un documento PDF con un certificado digital.
|
|
194
|
+
* NOTA: Esta función no está implementada actualmente para ningún tipo de integración.
|
|
195
|
+
* @returns {Promise<object>}
|
|
196
|
+
* @throws {ApacuanaAPIError} Arroja un error 'NOT_IMPLEMENTED' para cualquier tipo de integración.
|
|
197
|
+
*/
|
|
198
|
+
export const signDocument = async () => {
|
|
199
|
+
const { integrationType } = getConfig();
|
|
200
|
+
|
|
201
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
202
|
+
return signDocumentOnBoarding();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
206
|
+
return signDocumentOnPremise();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
throw new ApacuanaAPIError(
|
|
210
|
+
`Unsupported integration type: ${integrationType}`,
|
|
211
|
+
400,
|
|
212
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Obtiene el digest de un documento para ser firmado.
|
|
218
|
+
* @param {GetDigestData} signData - Datos requeridos para obtener el digest.
|
|
219
|
+
* @returns {Promise<GetDigestResponse>} Una promesa que resuelve a un objeto con el digest del documento.
|
|
220
|
+
* @throws {ApacuanaAPIError} Si los datos de entrada son inválidos, la llamada a la API falla, o el tipo de integración no es soportado.
|
|
221
|
+
*/
|
|
222
|
+
export const getDigest = async (signData) => {
|
|
223
|
+
helpers.validateGetDigestData(signData);
|
|
224
|
+
|
|
225
|
+
const { integrationType } = getConfig();
|
|
226
|
+
|
|
227
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
228
|
+
return getDigestToSignOnBoarding(signData);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
232
|
+
return getDigestToSignOnPremise();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
throw new ApacuanaAPIError(
|
|
236
|
+
`Document retrieval is not supported for an unknown integration type: ${integrationType}`,
|
|
237
|
+
501,
|
|
238
|
+
"NOT_IMPLEMENTED"
|
|
239
|
+
);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Añade un firmante a un documento.
|
|
244
|
+
* @param {SignerData} signerData - Los datos del firmante que se va a añadir.
|
|
245
|
+
* @returns {Promise<AddSignerResponse>} Una promesa que resuelve a un objeto con el resultado de la operación.
|
|
246
|
+
* @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.
|
|
247
|
+
*/
|
|
248
|
+
export const addSigner = async (signerData) => {
|
|
249
|
+
if (
|
|
250
|
+
!signerData ||
|
|
251
|
+
typeof signerData !== "object" ||
|
|
252
|
+
Object.keys(signerData).length === 0
|
|
253
|
+
) {
|
|
254
|
+
throw new ApacuanaAPIError(
|
|
255
|
+
"Signer data (signerData) is required and must be a non-empty object.",
|
|
256
|
+
400,
|
|
257
|
+
"INVALID_PARAMETER"
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
const { integrationType } = getConfig();
|
|
261
|
+
|
|
262
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
263
|
+
return addSignerOnBoarding(signerData);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
267
|
+
return addSignerOnPremise();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
throw new ApacuanaAPIError(
|
|
271
|
+
`Unsupported integration type: ${integrationType}`,
|
|
272
|
+
400,
|
|
273
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
217
277
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @param {
|
|
220
|
-
* @returns {Promise<
|
|
221
|
-
* @throws {ApacuanaAPIError}
|
|
278
|
+
* Obtiene una lista de documentos basada en los filtros especificados.
|
|
279
|
+
* @param {GetDocsParams} data - Objeto con parámetros de paginación y filtros.
|
|
280
|
+
* @returns {Promise<GetDocsResponse>} Una promesa que resuelve a un objeto con la lista de documentos.
|
|
281
|
+
* @throws {ApacuanaAPIError} Si los parámetros de paginación son inválidos, 'customerId' no está configurado, la llamada a la API falla, o el tipo de integración no es soportado.
|
|
222
282
|
*/
|
|
223
283
|
export const getDocs = async (data) => {
|
|
224
284
|
helpers.validateGetDocsData(data);
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { getConfig } from "../../src/config";
|
|
2
2
|
import { httpRequest } from "../../src/utils/httpClient";
|
|
3
3
|
import { ApacuanaAPIError } from "../../src/errors";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
addSigner,
|
|
6
|
+
getDocs,
|
|
7
|
+
getDigest,
|
|
8
|
+
signDocument,
|
|
9
|
+
} from "../../src/api/signatures";
|
|
5
10
|
import helpers from "../../src/utils/helpers";
|
|
6
11
|
import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
7
12
|
|
|
@@ -23,7 +28,9 @@ describe("API - Signatures", () => {
|
|
|
23
28
|
|
|
24
29
|
describe("addSigner", () => {
|
|
25
30
|
it("should call addSignerOnBoarding for ONBOARDING integration", async () => {
|
|
26
|
-
getConfig.mockReturnValue({
|
|
31
|
+
getConfig.mockReturnValue({
|
|
32
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
33
|
+
});
|
|
27
34
|
const signerData = { typedoc: "V", doc: "12345678" };
|
|
28
35
|
httpRequest.mockResolvedValue({ success: true });
|
|
29
36
|
|
|
@@ -106,7 +113,7 @@ describe("API - Signatures", () => {
|
|
|
106
113
|
httpRequest.mockResolvedValue({ docs: [] });
|
|
107
114
|
|
|
108
115
|
await expect(getDocs(paginationData)).rejects.toThrow(
|
|
109
|
-
"Document retrieval is not supported for integration type:
|
|
116
|
+
"Document retrieval is not supported for integration type: ONPREMISE"
|
|
110
117
|
);
|
|
111
118
|
});
|
|
112
119
|
|
|
@@ -151,4 +158,4 @@ describe("API - Signatures", () => {
|
|
|
151
158
|
);
|
|
152
159
|
});
|
|
153
160
|
});
|
|
154
|
-
});
|
|
161
|
+
});
|