apacuana-sdk-core 0.3.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.
Files changed (40) hide show
  1. package/coverage/clover.xml +12 -12
  2. package/coverage/coverage-final.json +2 -2
  3. package/coverage/lcov-report/block-navigation.js +1 -1
  4. package/coverage/lcov-report/index.html +1 -1
  5. package/coverage/lcov-report/sorter.js +21 -7
  6. package/coverage/lcov-report/src/api/certs.js.html +2 -2
  7. package/coverage/lcov-report/src/api/index.html +1 -1
  8. package/coverage/lcov-report/src/api/revocations.js.html +12 -15
  9. package/coverage/lcov-report/src/api/signatures.js.html +1 -1
  10. package/coverage/lcov-report/src/api/users.js.html +1 -1
  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 +1 -1
  15. package/coverage/lcov-report/src/index.html +1 -1
  16. package/coverage/lcov-report/src/index.js.html +6 -3
  17. package/coverage/lcov-report/src/utils/constant.js.html +1 -1
  18. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  19. package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
  20. package/coverage/lcov-report/src/utils/index.html +1 -1
  21. package/coverage/lcov.info +16 -16
  22. package/dist/api/certs.d.ts +8 -0
  23. package/dist/api/revocations.d.ts +7 -0
  24. package/dist/api/signatures.d.ts +16 -0
  25. package/dist/api/users.d.ts +15 -0
  26. package/dist/config/index.d.ts +11 -0
  27. package/dist/errors/index.d.ts +10 -0
  28. package/dist/index.d.ts +25 -0
  29. package/dist/index.js +116 -9
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +116 -9
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/utils/constant.d.ts +18 -0
  34. package/dist/utils/helpers.d.ts +21 -0
  35. package/dist/utils/httpClient.d.ts +3 -0
  36. package/package.json +9 -4
  37. package/src/api/certs.js +1 -1
  38. package/src/api/revocations.js +10 -11
  39. package/src/index.js +2 -1
  40. 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;
@@ -0,0 +1,3 @@
1
+ export function initHttpClient(): void;
2
+ export function setAuthToken(token: string): void;
3
+ export function httpRequest(path: string, data?: object, method?: string): Promise<object>;
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "apacuana-sdk-core",
3
- "version": "0.3.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 test && npm run build",
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
@@ -42,7 +42,7 @@ const generateCertOnPremise = async () => {
42
42
 
43
43
  /**
44
44
  * Generates a digital certificate.
45
- * @param {string} [csr] - Optional Certificate Signing Request (CSR).
45
+ * @param {string} [csr] - Certificate Signing Request (CSR).
46
46
  * @returns {Promise<{cert: string, success: boolean}>} Object with the generated certificate and a success indicator.
47
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
48
  * @throws {Error} If certificate generation fails for another reason.
@@ -1,6 +1,5 @@
1
- // src/api/revocations.js
2
- import { httpRequest } from '../utils/httpClient';
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('-> Función \'requestRevocation\' ejecutada.');
12
- console.log('Parámetros recibidos para solicitud de revocación:', {
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
- 'ID de certificado y motivo son requeridos para requestRevocation.',
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
- 'users/api/customers/requestcert',
23
+ "users/api/customers/requestcert",
25
24
  { reason: reasonCode },
26
- 'POST',
25
+ "POST"
27
26
  );
28
- console.log('Respuesta del servidor', response);
27
+ console.log("Respuesta del servidor", response);
29
28
  if (!response.success) {
30
29
  throw new ApacuanaAPIError(
31
- response.message || 'Error desconocido al solicitar revocación.',
30
+ response.message || "Error desconocido al solicitar revocación."
32
31
  );
33
32
  }
34
33
  return {
35
- revocationStatus: response.status || 'pending',
34
+ revocationStatus: response.status || "pending",
36
35
  requestId: response.id,
37
36
  };
38
37
  } catch (error) {
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/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2020",
4
+ "module": "esnext",
5
+ "allowJs": true,
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true,
8
+ "outDir": "./dist",
9
+ "strict": true,
10
+ "moduleResolution": "node",
11
+ "esModuleInterop": true
12
+ },
13
+ "include": ["src"],
14
+ "exclude": ["node_modules", "dist", "tests"]
15
+ }