apacuana-sdk-core 0.2.0 → 0.4.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 +64 -15
- package/coverage/clover.xml +155 -121
- package/coverage/coverage-final.json +8 -8
- package/coverage/lcov-report/block-navigation.js +1 -1
- package/coverage/lcov-report/index.html +30 -30
- package/coverage/lcov-report/sorter.js +21 -7
- package/coverage/lcov-report/src/api/certs.js.html +73 -28
- package/coverage/lcov-report/src/api/index.html +31 -31
- package/coverage/lcov-report/src/api/revocations.js.html +12 -15
- package/coverage/lcov-report/src/api/signatures.js.html +186 -159
- package/coverage/lcov-report/src/api/users.js.html +24 -63
- 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 +6 -3
- package/coverage/lcov-report/src/utils/constant.js.html +4 -4
- package/coverage/lcov-report/src/utils/helpers.js.html +101 -50
- package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +19 -19
- package/coverage/lcov.info +293 -221
- package/dist/api/certs.d.ts +8 -0
- package/dist/api/revocations.d.ts +7 -0
- package/dist/api/signatures.d.ts +16 -0
- package/dist/api/users.d.ts +15 -0
- package/dist/config/index.d.ts +11 -0
- package/dist/errors/index.d.ts +10 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +252 -251
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +252 -251
- package/dist/index.mjs.map +1 -1
- package/dist/utils/constant.d.ts +18 -0
- package/dist/utils/helpers.d.ts +21 -0
- package/dist/utils/httpClient.d.ts +3 -0
- package/package.json +9 -4
- package/src/api/certs.js +25 -10
- package/src/api/revocations.js +10 -11
- package/src/api/signatures.js +106 -97
- package/src/api/users.js +16 -29
- package/src/index.js +2 -1
- package/src/utils/helpers.js +17 -0
- package/tests/api/certs.test.js +58 -74
- package/tests/api/signatures.test.js +18 -73
- package/tests/api/users.test.js +10 -10
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export namespace STATUS_CERTIFICATE {
|
|
2
|
+
let request: string;
|
|
3
|
+
let generate: string;
|
|
4
|
+
let current: string;
|
|
5
|
+
let revoque: string;
|
|
6
|
+
let expire: string;
|
|
7
|
+
let request_revoque: string;
|
|
8
|
+
let certificate_another_device: string;
|
|
9
|
+
let sign_pending: string;
|
|
10
|
+
}
|
|
11
|
+
export namespace VERIFICATION_STATUS {
|
|
12
|
+
let IN_REGISTER: number;
|
|
13
|
+
let APPROVED: number;
|
|
14
|
+
}
|
|
15
|
+
export namespace INTEGRATION_TYPE {
|
|
16
|
+
let ONBOARDING: string;
|
|
17
|
+
let ONPREMISE: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { getCertificateStatus };
|
|
3
|
+
export { exportPrivateKey };
|
|
4
|
+
export { arrayBufferToBase64 };
|
|
5
|
+
export { encryptedCsr };
|
|
6
|
+
export { validateOnBoardingSignerData };
|
|
7
|
+
export { validateCsr };
|
|
8
|
+
export { validateGetDocsData };
|
|
9
|
+
export { validateGetDigestData };
|
|
10
|
+
}
|
|
11
|
+
export default _default;
|
|
12
|
+
declare function getCertificateStatus(userData: any, certificateInDevice: any): string;
|
|
13
|
+
declare function exportPrivateKey(key: any): Promise<string>;
|
|
14
|
+
declare function arrayBufferToBase64(buffer: any): string;
|
|
15
|
+
declare function encryptedCsr(csr: any, encryptKey?: string): {
|
|
16
|
+
csr: any;
|
|
17
|
+
};
|
|
18
|
+
declare function validateOnBoardingSignerData(signerData: any): void;
|
|
19
|
+
declare function validateCsr(csr: any): void;
|
|
20
|
+
declare function validateGetDocsData(data: any): void;
|
|
21
|
+
declare function validateGetDigestData(signData: any): void;
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apacuana-sdk-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Core SDK para interacciones con las APIs de Apacuana.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"scripts": {
|
|
10
|
+
"clean": "rimraf dist",
|
|
11
|
+
"clean-modules": "rimraf node_modules",
|
|
9
12
|
"test": "jest",
|
|
10
13
|
"lint": "eslint src/",
|
|
11
|
-
"build": "rollup -c",
|
|
12
|
-
"prepublishOnly": "npm
|
|
14
|
+
"build": "npm run clean && tsc && rollup -c",
|
|
15
|
+
"prepublishOnly": "npm run validate",
|
|
13
16
|
"validate": "npm run lint && npm test && npm run build"
|
|
14
17
|
},
|
|
15
18
|
"keywords": [
|
|
@@ -33,7 +36,9 @@
|
|
|
33
36
|
"eslint-config-prettier": "^10.1.8",
|
|
34
37
|
"eslint-plugin-import": "^2.29.1",
|
|
35
38
|
"jest": "^29.7.0",
|
|
36
|
-
"rollup": "^4.18.0"
|
|
39
|
+
"rollup": "^4.18.0",
|
|
40
|
+
"rimraf": "^5.0.7",
|
|
41
|
+
"typescript": "^5.4.5"
|
|
37
42
|
},
|
|
38
43
|
"engines": {
|
|
39
44
|
"node": ">=14.0.0"
|
package/src/api/certs.js
CHANGED
|
@@ -16,7 +16,7 @@ const generateCertOnBoarding = async (csr = undefined) => {
|
|
|
16
16
|
const { cert } = response;
|
|
17
17
|
if (!cert) {
|
|
18
18
|
throw new ApacuanaAPIError(
|
|
19
|
-
"
|
|
19
|
+
"The API response does not contain the certificate.",
|
|
20
20
|
response.status,
|
|
21
21
|
"INVALID_API_RESPONSE"
|
|
22
22
|
);
|
|
@@ -24,14 +24,29 @@ const generateCertOnBoarding = async (csr = undefined) => {
|
|
|
24
24
|
|
|
25
25
|
return { cert, success: true };
|
|
26
26
|
} catch (error) {
|
|
27
|
-
//
|
|
27
|
+
// The captured error is re-thrown, which will already be of type ApacuanaAPIError or a native Error.
|
|
28
28
|
if (error instanceof ApacuanaAPIError) {
|
|
29
29
|
throw error;
|
|
30
30
|
}
|
|
31
|
-
throw new Error(`
|
|
31
|
+
throw new Error(`Certificate generation failed: ${error.message}`);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
const generateCertOnPremise = async () => {
|
|
36
|
+
throw new ApacuanaAPIError(
|
|
37
|
+
"Certificate generation is not supported for integration type: ONPREMISE",
|
|
38
|
+
501,
|
|
39
|
+
"NOT_IMPLEMENTED"
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generates a digital certificate.
|
|
45
|
+
* @param {string} [csr] - Certificate Signing Request (CSR).
|
|
46
|
+
* @returns {Promise<{cert: string, success: boolean}>} Object with the generated certificate and a success indicator.
|
|
47
|
+
* @throws {ApacuanaAPIError} If the CSR is invalid, if the API response does not contain the certificate, or if the integration type is not supported.
|
|
48
|
+
* @throws {Error} If certificate generation fails for another reason.
|
|
49
|
+
*/
|
|
35
50
|
export const generateCert = async (csr = undefined) => {
|
|
36
51
|
const { integrationType } = getConfig();
|
|
37
52
|
helpers.validateCsr(csr);
|
|
@@ -39,21 +54,21 @@ export const generateCert = async (csr = undefined) => {
|
|
|
39
54
|
return generateCertOnBoarding(csr);
|
|
40
55
|
}
|
|
41
56
|
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
42
|
-
|
|
43
|
-
console.log("-> Lógica para On-premise");
|
|
44
|
-
// Aquí iría la llamada a httpRequest para el endpoint de on-premise
|
|
45
|
-
// return httpRequest('/certs/generate-onpremise', data);
|
|
46
|
-
return Promise.resolve(); // Retornar una promesa resuelta para consistencia
|
|
57
|
+
return generateCertOnPremise();
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
// Lanzar un error si el tipo de integración no es soportado
|
|
50
60
|
throw new ApacuanaAPIError(
|
|
51
|
-
`
|
|
61
|
+
`Unsupported integration type: ${integrationType}`,
|
|
52
62
|
400,
|
|
53
63
|
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
54
64
|
);
|
|
55
65
|
};
|
|
56
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Gets the user's certificate status.
|
|
69
|
+
* @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
|
|
70
|
+
* @returns {{status: string, success: boolean}} Object with the certificate status and a success indicator.
|
|
71
|
+
*/
|
|
57
72
|
export const getCertStatus = (isCertificateInDevice = false) => {
|
|
58
73
|
const config = getConfig();
|
|
59
74
|
const status = helpers.getCertificateStatus(
|
package/src/api/revocations.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { ApacuanaAPIError } from '../errors/index';
|
|
1
|
+
import { httpRequest } from "../utils/httpClient";
|
|
2
|
+
import { ApacuanaAPIError } from "../errors/index";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Simula la solicitud de revocación de un certificado.
|
|
@@ -8,31 +7,31 @@ import { ApacuanaAPIError } from '../errors/index';
|
|
|
8
7
|
* @returns {Promise<object>} Objeto con el estado de la solicitud de revocación.
|
|
9
8
|
*/
|
|
10
9
|
const requestRevocation = async (reasonCode) => {
|
|
11
|
-
console.log(
|
|
12
|
-
console.log(
|
|
10
|
+
console.log("-> Función 'requestRevocation' ejecutada.");
|
|
11
|
+
console.log("Parámetros recibidos para solicitud de revocación:", {
|
|
13
12
|
reasonCode,
|
|
14
13
|
});
|
|
15
14
|
|
|
16
15
|
if (!reasonCode) {
|
|
17
16
|
throw new Error(
|
|
18
|
-
|
|
17
|
+
"ID de certificado y motivo son requeridos para requestRevocation."
|
|
19
18
|
);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
try {
|
|
23
22
|
const response = await httpRequest(
|
|
24
|
-
|
|
23
|
+
"users/api/customers/requestcert",
|
|
25
24
|
{ reason: reasonCode },
|
|
26
|
-
|
|
25
|
+
"POST"
|
|
27
26
|
);
|
|
28
|
-
console.log(
|
|
27
|
+
console.log("Respuesta del servidor", response);
|
|
29
28
|
if (!response.success) {
|
|
30
29
|
throw new ApacuanaAPIError(
|
|
31
|
-
response.message ||
|
|
30
|
+
response.message || "Error desconocido al solicitar revocación."
|
|
32
31
|
);
|
|
33
32
|
}
|
|
34
33
|
return {
|
|
35
|
-
revocationStatus: response.status ||
|
|
34
|
+
revocationStatus: response.status || "pending",
|
|
36
35
|
requestId: response.id,
|
|
37
36
|
};
|
|
38
37
|
} catch (error) {
|
package/src/api/signatures.js
CHANGED
|
@@ -5,124 +5,113 @@ import { ApacuanaAPIError } from "../errors";
|
|
|
5
5
|
import helpers from "../utils/helpers";
|
|
6
6
|
import { INTEGRATION_TYPE } from "../utils/constant";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
8
|
+
const signDocumentOnBoarding = async () => {
|
|
9
|
+
throw new ApacuanaAPIError(
|
|
10
|
+
"Document signing is not supported for integration type: ONBOARDING",
|
|
11
|
+
501,
|
|
12
|
+
"NOT_IMPLEMENTED"
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const signDocumentOnPremise = async () => {
|
|
17
|
+
throw new ApacuanaAPIError(
|
|
18
|
+
"Document signing is not supported for integration type: ONPREMISE",
|
|
19
|
+
501,
|
|
20
|
+
"NOT_IMPLEMENTED"
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
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();
|
|
29
39
|
}
|
|
40
|
+
|
|
41
|
+
throw new ApacuanaAPIError(
|
|
42
|
+
`Unsupported integration type: ${integrationType}`,
|
|
43
|
+
400,
|
|
44
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
45
|
+
);
|
|
30
46
|
};
|
|
31
47
|
|
|
32
|
-
const
|
|
33
|
-
helpers.validateSignOnPremiseData({ signature, cert, privateKey });
|
|
48
|
+
const getDigestToSignOnBoarding = async (signData) => {
|
|
34
49
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
`services/api/documents/getdigest/${signature.id}`,
|
|
41
|
-
digestBody,
|
|
50
|
+
const response = await httpRequest(
|
|
51
|
+
`services/api/documents/getdigest/${signData.signatureId}`,
|
|
52
|
+
{
|
|
53
|
+
publickey: signData.cert,
|
|
54
|
+
},
|
|
42
55
|
"POST"
|
|
43
56
|
);
|
|
44
|
-
|
|
45
|
-
const digest = digestResponse.data?.digest || digestResponse.digest;
|
|
57
|
+
const digest = response.data?.digest || response.digest;
|
|
46
58
|
if (!digest) {
|
|
47
59
|
throw new ApacuanaAPIError(
|
|
48
|
-
"
|
|
60
|
+
"Signature generation failed: digest not found in the response.",
|
|
61
|
+
500,
|
|
62
|
+
"API_RESPONSE_ERROR"
|
|
49
63
|
);
|
|
50
64
|
}
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const signBody = {
|
|
55
|
-
positions: JSON.stringify(
|
|
56
|
-
signature.positions.map((p) => ({
|
|
57
|
-
x: p.x,
|
|
58
|
-
y: p.y,
|
|
59
|
-
page: p.page,
|
|
60
|
-
status: 1,
|
|
61
|
-
}))
|
|
62
|
-
),
|
|
63
|
-
publickey: cert,
|
|
64
|
-
signeddigest: signedDigest,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const signResponse = await httpRequest(
|
|
68
|
-
`services/api/documents/sign/${signature.id}`,
|
|
69
|
-
signBody,
|
|
70
|
-
"PUT"
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
return signResponse;
|
|
66
|
+
return { digest, success: true };
|
|
74
67
|
} catch (error) {
|
|
75
68
|
if (error.name === "ApacuanaAPIError") {
|
|
76
69
|
throw error;
|
|
77
70
|
}
|
|
78
71
|
throw new ApacuanaAPIError(
|
|
79
|
-
`
|
|
72
|
+
`Failed to sign document (on-boarding): ${error.message}`
|
|
80
73
|
);
|
|
81
74
|
}
|
|
82
75
|
};
|
|
83
|
-
|
|
76
|
+
|
|
77
|
+
const getDigestToSignOnPremise = async () => {
|
|
78
|
+
throw new ApacuanaAPIError(
|
|
79
|
+
"Digest retrieval is not supported for integration type: ONPREMISE",
|
|
80
|
+
501,
|
|
81
|
+
"NOT_IMPLEMENTED"
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
* @param {object}
|
|
88
|
-
* @returns {Promise<
|
|
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.
|
|
89
90
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
!signData ||
|
|
94
|
-
typeof signData !== "object" ||
|
|
95
|
-
Object.keys(signData).length === 0
|
|
96
|
-
) {
|
|
97
|
-
throw new ApacuanaAPIError(
|
|
98
|
-
"El parámetro 'data' es requerido y debe ser un objeto no vacío.",
|
|
99
|
-
400,
|
|
100
|
-
"INVALID_PARAMETER"
|
|
101
|
-
);
|
|
102
|
-
}
|
|
91
|
+
export const getDigest = async (signData) => {
|
|
92
|
+
helpers.validateGetDigestData(signData);
|
|
103
93
|
|
|
104
94
|
const { integrationType } = getConfig();
|
|
105
95
|
|
|
106
96
|
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
107
|
-
return
|
|
97
|
+
return getDigestToSignOnBoarding(signData);
|
|
108
98
|
}
|
|
109
99
|
|
|
110
100
|
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
111
|
-
return
|
|
101
|
+
return getDigestToSignOnPremise();
|
|
112
102
|
}
|
|
113
103
|
|
|
114
104
|
throw new ApacuanaAPIError(
|
|
115
|
-
`
|
|
116
|
-
|
|
117
|
-
"
|
|
105
|
+
`Document retrieval is not supported for an unknown integration type: ${integrationType}`,
|
|
106
|
+
501,
|
|
107
|
+
"NOT_IMPLEMENTED"
|
|
118
108
|
);
|
|
119
109
|
};
|
|
120
|
-
*/
|
|
121
110
|
|
|
122
111
|
const addSignerOnBoarding = async (signerData) => {
|
|
123
112
|
helpers.validateOnBoardingSignerData(signerData);
|
|
124
113
|
try {
|
|
125
|
-
//
|
|
114
|
+
// Current httpRequest logic is moved here
|
|
126
115
|
await httpRequest("services/api/documents/signing", signerData, "POST");
|
|
127
116
|
return { signer: signerData.typedoc + signerData.doc, success: true };
|
|
128
117
|
} catch (error) {
|
|
@@ -130,18 +119,24 @@ const addSignerOnBoarding = async (signerData) => {
|
|
|
130
119
|
throw error;
|
|
131
120
|
}
|
|
132
121
|
throw new Error(
|
|
133
|
-
`
|
|
122
|
+
`Failed to add signer in On-Boarding: ${error.message}`
|
|
134
123
|
);
|
|
135
124
|
}
|
|
136
125
|
};
|
|
137
126
|
|
|
138
|
-
const addSignerOnPremise = async () =>
|
|
139
|
-
|
|
127
|
+
const addSignerOnPremise = async () => {
|
|
128
|
+
throw new ApacuanaAPIError(
|
|
129
|
+
"Adding signers is not supported for integration type: ONPREMISE",
|
|
130
|
+
501,
|
|
131
|
+
"NOT_IMPLEMENTED"
|
|
132
|
+
);
|
|
133
|
+
};
|
|
140
134
|
|
|
141
135
|
/**
|
|
142
|
-
*
|
|
143
|
-
* @param {object} signerData -
|
|
144
|
-
* @returns {Promise<
|
|
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.
|
|
145
140
|
*/
|
|
146
141
|
export const addSigner = async (signerData) => {
|
|
147
142
|
if (
|
|
@@ -150,7 +145,7 @@ export const addSigner = async (signerData) => {
|
|
|
150
145
|
Object.keys(signerData).length === 0
|
|
151
146
|
) {
|
|
152
147
|
throw new ApacuanaAPIError(
|
|
153
|
-
"
|
|
148
|
+
"Signer data (signerData) is required and must be a non-empty object.",
|
|
154
149
|
400,
|
|
155
150
|
"INVALID_PARAMETER"
|
|
156
151
|
);
|
|
@@ -167,7 +162,7 @@ export const addSigner = async (signerData) => {
|
|
|
167
162
|
}
|
|
168
163
|
|
|
169
164
|
throw new ApacuanaAPIError(
|
|
170
|
-
`
|
|
165
|
+
`Unsupported integration type: ${integrationType}`,
|
|
171
166
|
400,
|
|
172
167
|
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
173
168
|
);
|
|
@@ -175,7 +170,7 @@ export const addSigner = async (signerData) => {
|
|
|
175
170
|
|
|
176
171
|
const getDocsOnPremise = async () => {
|
|
177
172
|
throw new ApacuanaAPIError(
|
|
178
|
-
"
|
|
173
|
+
"Document retrieval is not supported for integration type: ONBOARDING",
|
|
179
174
|
501,
|
|
180
175
|
"NOT_IMPLEMENTED"
|
|
181
176
|
);
|
|
@@ -185,31 +180,45 @@ const getDocsOnBoarding = async (data) => {
|
|
|
185
180
|
const { customerId } = getConfig();
|
|
186
181
|
if (!customerId) {
|
|
187
182
|
throw new ApacuanaAPIError(
|
|
188
|
-
"
|
|
183
|
+
"'customerId' is not configured. Please configure the SDK.",
|
|
189
184
|
400,
|
|
190
185
|
"CONFIGURATION_ERROR"
|
|
191
186
|
);
|
|
192
187
|
}
|
|
193
188
|
|
|
194
189
|
try {
|
|
195
|
-
const
|
|
190
|
+
const params = new URLSearchParams({
|
|
191
|
+
page: data.page,
|
|
192
|
+
customerid: customerId,
|
|
193
|
+
size: data.size,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
if (typeof data.status !== "undefined") {
|
|
197
|
+
params.append("status", data.status);
|
|
198
|
+
}
|
|
196
199
|
|
|
200
|
+
const apiUrl = `services/api/documents/listcustomer?${params.toString()}`;
|
|
197
201
|
const response = await httpRequest(apiUrl, {}, "GET");
|
|
198
|
-
return
|
|
202
|
+
return {
|
|
203
|
+
totalRecords: response.numofrecords,
|
|
204
|
+
records: response.records,
|
|
205
|
+
success: true,
|
|
206
|
+
};
|
|
199
207
|
} catch (error) {
|
|
200
208
|
if (error.name === "ApacuanaAPIError") {
|
|
201
209
|
throw error;
|
|
202
210
|
}
|
|
203
211
|
throw new ApacuanaAPIError(
|
|
204
|
-
`
|
|
212
|
+
`Failed to get document list (on-premise): ${error.message}`
|
|
205
213
|
);
|
|
206
214
|
}
|
|
207
215
|
};
|
|
208
216
|
|
|
209
217
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @param {object} data -
|
|
212
|
-
* @returns {Promise<
|
|
218
|
+
* Gets a list of documents.
|
|
219
|
+
* @param {object} data - Object with pagination parameters. Must contain {page, size}.
|
|
220
|
+
* @returns {Promise<{totalRecords: number, records:any[], success: boolean}>} Object with the list of documents.
|
|
221
|
+
* @throws {ApacuanaAPIError} If pagination parameters are invalid, if 'customerId' is not configured, if the API call fails, or if the integration type is not supported.
|
|
213
222
|
*/
|
|
214
223
|
export const getDocs = async (data) => {
|
|
215
224
|
helpers.validateGetDocsData(data);
|
|
@@ -225,7 +234,7 @@ export const getDocs = async (data) => {
|
|
|
225
234
|
}
|
|
226
235
|
|
|
227
236
|
throw new ApacuanaAPIError(
|
|
228
|
-
`
|
|
237
|
+
`Document retrieval is not supported for an unknown integration type: ${integrationType}`,
|
|
229
238
|
501,
|
|
230
239
|
"NOT_IMPLEMENTED"
|
|
231
240
|
);
|
package/src/api/users.js
CHANGED
|
@@ -7,46 +7,36 @@ import { getConfig } from "../config/index";
|
|
|
7
7
|
* Este método es útil para endpoints que requieren datos en el cuerpo de la petición
|
|
8
8
|
* para buscar un usuario, como un ID de sesión o un token de acceso.
|
|
9
9
|
*
|
|
10
|
-
* @returns {Promise<object>} Objeto con los
|
|
10
|
+
* @returns {Promise<{token: string, userData: object, success: boolean}>} Objeto con el token de sesión, los datos del usuario y un indicador de éxito.
|
|
11
11
|
* @throws {Error} Si los parámetros de entrada son inválidos.
|
|
12
12
|
* @throws {ApacuanaAPIError} Si ocurre un error en la API de Apacuana.
|
|
13
13
|
*/
|
|
14
14
|
const getCustomer = async () => {
|
|
15
15
|
const { verificationId, customerId } = getConfig();
|
|
16
|
+
|
|
17
|
+
if (!verificationId || !customerId) {
|
|
18
|
+
throw new ApacuanaAPIError(
|
|
19
|
+
"Both 'verificationId' and 'customerId' must be configured.",
|
|
20
|
+
400,
|
|
21
|
+
"CONFIGURATION_ERROR"
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
16
25
|
const body = {
|
|
17
26
|
verificationid: verificationId,
|
|
18
27
|
customerid: customerId,
|
|
19
28
|
};
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
21
|
-
console.log("-> Función 'getCustomer' ejecutada.");
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
console.log("Parámetros recibidos para buscar usuario:", body);
|
|
24
|
-
|
|
25
|
-
// 1. Validación de Parámetros de Entrada (Lado del SDK)
|
|
26
|
-
if (!body || !body.verificationid || !body.customerid) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
"El 'body' con 'userId' es un parámetro requerido para getCustomer."
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
29
|
|
|
32
30
|
try {
|
|
33
|
-
// 2. Realizar la Llamada al Backend a través del HttpClient
|
|
34
|
-
// Usamos POST ya que la búsqueda podría requerir datos sensibles o complejos en el cuerpo.
|
|
35
31
|
const response = await httpRequest(
|
|
36
|
-
"services/api/register/init",
|
|
37
|
-
body,
|
|
32
|
+
"services/api/register/init",
|
|
33
|
+
body,
|
|
38
34
|
"POST"
|
|
39
35
|
);
|
|
40
36
|
|
|
41
|
-
// 3. Procesar la Respuesta del Backend
|
|
42
|
-
// Asumiendo que la respuesta exitosa del backend incluye un objeto 'user'
|
|
43
|
-
// eslint-disable-next-line no-console
|
|
44
|
-
console.log("Respuesta del servidor para el token:", response);
|
|
45
|
-
|
|
46
37
|
if (!response.sessionid || !response.entry) {
|
|
47
|
-
// Si el backend no devuelve el objeto 'user' esperado
|
|
48
38
|
throw new ApacuanaAPIError(
|
|
49
|
-
"
|
|
39
|
+
"The API response does not contain the user.",
|
|
50
40
|
200,
|
|
51
41
|
"INVALID_API_RESPONSE"
|
|
52
42
|
);
|
|
@@ -56,17 +46,14 @@ const getCustomer = async () => {
|
|
|
56
46
|
token: response.sessionid,
|
|
57
47
|
userData: response.entry,
|
|
58
48
|
success: true,
|
|
59
|
-
};
|
|
49
|
+
};
|
|
60
50
|
} catch (error) {
|
|
61
|
-
// 4. Manejo de Errores
|
|
62
|
-
// eslint-disable-next-line no-console
|
|
63
|
-
console.error("Error en getCustomer:", error);
|
|
64
51
|
if (error instanceof ApacuanaAPIError) {
|
|
65
52
|
throw error;
|
|
66
53
|
}
|
|
67
54
|
throw new ApacuanaAPIError(
|
|
68
|
-
`
|
|
69
|
-
error.message || "
|
|
55
|
+
`Unexpected failure getting token: ${
|
|
56
|
+
error.message || "Unknown error"
|
|
70
57
|
}`
|
|
71
58
|
);
|
|
72
59
|
}
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { setConfig, getConfig } from "./config/index";
|
|
|
2
2
|
import { initHttpClient, setAuthToken } from "./utils/httpClient";
|
|
3
3
|
import getCustomer from "./api/users";
|
|
4
4
|
import requestRevocation from "./api/revocations";
|
|
5
|
-
import { getCertStatus } from "./api/certs";
|
|
5
|
+
import { generateCert, getCertStatus } from "./api/certs";
|
|
6
6
|
import { addSigner, getDocs } from "./api/signatures";
|
|
7
7
|
|
|
8
8
|
const apacuana = {
|
|
@@ -65,6 +65,7 @@ const apacuana = {
|
|
|
65
65
|
getCustomer,
|
|
66
66
|
addSigner,
|
|
67
67
|
getDocs,
|
|
68
|
+
generateCert,
|
|
68
69
|
};
|
|
69
70
|
|
|
70
71
|
export default apacuana;
|
package/src/utils/helpers.js
CHANGED
|
@@ -196,6 +196,22 @@ const validateGetDocsData = (data) => {
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
const validateGetDigestData = (signData) => {
|
|
200
|
+
if (
|
|
201
|
+
!signData ||
|
|
202
|
+
!signData.cert ||
|
|
203
|
+
typeof signData.cert !== "string" ||
|
|
204
|
+
!signData.signatureId ||
|
|
205
|
+
typeof signData.signatureId !== "string"
|
|
206
|
+
) {
|
|
207
|
+
throw new ApacuanaAPIError(
|
|
208
|
+
"Los parámetros 'cert' y 'signatureId' son requeridos y deben ser cadenas de texto.",
|
|
209
|
+
400,
|
|
210
|
+
"INVALID_PARAMETER"
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
199
215
|
export default {
|
|
200
216
|
getCertificateStatus,
|
|
201
217
|
exportPrivateKey,
|
|
@@ -204,4 +220,5 @@ export default {
|
|
|
204
220
|
validateOnBoardingSignerData,
|
|
205
221
|
validateCsr,
|
|
206
222
|
validateGetDocsData,
|
|
223
|
+
validateGetDigestData,
|
|
207
224
|
};
|