apacuana-sdk-core 1.26.2 → 1.26.4

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 (32) hide show
  1. package/coverage/clover.xml +125 -123
  2. package/coverage/coverage-final.json +2 -2
  3. package/coverage/lcov-report/index.html +13 -13
  4. package/coverage/lcov-report/src/api/certs.js.html +1 -1
  5. package/coverage/lcov-report/src/api/faceLiveness.js.html +1 -1
  6. package/coverage/lcov-report/src/api/index.html +1 -1
  7. package/coverage/lcov-report/src/api/revocations.js.html +1 -1
  8. package/coverage/lcov-report/src/api/signatures.js.html +10 -4
  9. package/coverage/lcov-report/src/api/users.js.html +1 -1
  10. package/coverage/lcov-report/src/config/index.html +1 -1
  11. package/coverage/lcov-report/src/config/index.js.html +1 -1
  12. package/coverage/lcov-report/src/errors/index.html +1 -1
  13. package/coverage/lcov-report/src/errors/index.js.html +1 -1
  14. package/coverage/lcov-report/src/index.html +1 -1
  15. package/coverage/lcov-report/src/index.js.html +1 -1
  16. package/coverage/lcov-report/src/success/index.html +1 -1
  17. package/coverage/lcov-report/src/success/index.js.html +1 -1
  18. package/coverage/lcov-report/src/utils/constant.js.html +1 -1
  19. package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
  20. package/coverage/lcov-report/src/utils/httpClient.js.html +51 -9
  21. package/coverage/lcov-report/src/utils/index.html +12 -12
  22. package/coverage/lcov.info +218 -213
  23. package/dist/index.js +17 -4
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +17 -4
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/utils/httpClient.d.ts +3 -1
  28. package/package.json +1 -1
  29. package/src/api/signatures.js +4 -2
  30. package/src/utils/httpClient.js +16 -2
  31. package/tests/api/signatures.test.js +4 -2
  32. package/tests/integration/createAndLockDocument.test.js +3 -2
@@ -1,3 +1,5 @@
1
1
  export function initHttpClient(): void;
2
2
  export function setAuthToken(token: string): void;
3
- export function httpRequest(path: string, data?: object, method?: string): Promise<object>;
3
+ export function httpRequest(path: string, data?: object, method?: string, options?: {
4
+ skipAuth?: boolean | undefined;
5
+ }): Promise<object>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apacuana-sdk-core",
3
- "version": "1.26.2",
3
+ "version": "1.26.4",
4
4
  "description": "Core SDK para interacciones con las APIs de Apacuana.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -278,7 +278,8 @@ const createDocumentOnBoarding = async (documentData) => {
278
278
  const response = await httpRequest(
279
279
  "services/api/documents",
280
280
  formData,
281
- "POST"
281
+ "POST",
282
+ { skipAuth: true }
282
283
  );
283
284
  return new ApacuanaSuccess({
284
285
  msg: response.msg,
@@ -307,7 +308,8 @@ const lockDocumentOnBoarding = async (documentId) => {
307
308
  const response = await httpRequest(
308
309
  `services/api/documents/lock/${documentId}`,
309
310
  {},
310
- "PUT"
311
+ "PUT",
312
+ { skipAuth: true }
311
313
  );
312
314
  return new ApacuanaSuccess(response);
313
315
  } catch (error) {
@@ -114,10 +114,17 @@ export const setAuthToken = (token) => {
114
114
  * @param {string} path - La ruta del endpoint de la API.
115
115
  * @param {object} [data={}] - Los datos para enviar en la petición.
116
116
  * @param {string} [method='POST'] - El método HTTP.
117
+ * @param {object} [options={}] - Opciones adicionales.
118
+ * @param {boolean} [options.skipAuth=false] - Si es true, no envía el header Authorization aunque haya un Bearer configurado. Usar para endpoints públicos que solo requieren API keys.
117
119
  * @returns {Promise<object>} Los datos de la respuesta del backend.
118
120
  * @throws {ApacuanaAPIError} Si la petición falla.
119
121
  */
120
- export const httpRequest = async (path, data = {}, method = "POST") => {
122
+ export const httpRequest = async (
123
+ path,
124
+ data = {},
125
+ method = "POST",
126
+ options = {}
127
+ ) => {
121
128
  if (!axiosInstance) {
122
129
  throw new Error(
123
130
  "Apacuana SDK: Cliente HTTP no inicializado. " +
@@ -128,6 +135,10 @@ export const httpRequest = async (path, data = {}, method = "POST") => {
128
135
  let dataToSend;
129
136
  const requestConfig = {};
130
137
 
138
+ if (options.skipAuth) {
139
+ requestConfig.headers = { Authorization: undefined };
140
+ }
141
+
131
142
  if (typeof FormData !== "undefined" && data instanceof FormData) {
132
143
  dataToSend = data;
133
144
  } else {
@@ -149,7 +160,10 @@ export const httpRequest = async (path, data = {}, method = "POST") => {
149
160
  let response;
150
161
  switch (method.toUpperCase()) {
151
162
  case "GET":
152
- response = await axiosInstance.get(path, { params: dataToSend });
163
+ response = await axiosInstance.get(path, {
164
+ params: dataToSend,
165
+ ...requestConfig,
166
+ });
153
167
  break;
154
168
  case "POST":
155
169
  response = await axiosInstance.post(path, dataToSend, requestConfig);
@@ -642,7 +642,8 @@ describe("API - Signatures", () => {
642
642
  expect(httpRequest).toHaveBeenCalledWith(
643
643
  "services/api/documents",
644
644
  expect.any(FormData),
645
- "POST"
645
+ "POST",
646
+ { skipAuth: true }
646
647
  );
647
648
  expect(result).toBeInstanceOf(ApacuanaSuccess);
648
649
  expect(result.data).toEqual(mockResponse);
@@ -725,7 +726,8 @@ describe("API - Signatures", () => {
725
726
  expect(httpRequest).toHaveBeenCalledWith(
726
727
  `services/api/documents/lock/${documentId}`,
727
728
  {},
728
- "PUT"
729
+ "PUT",
730
+ { skipAuth: true }
729
731
  );
730
732
  expect(result).toBeInstanceOf(ApacuanaSuccess);
731
733
  expect(result.data).toEqual(mockResponse);
@@ -7,6 +7,7 @@
7
7
  * APACUANA_API_KEY=your-api-key
8
8
  * APACUANA_VERIFICATION_ID=your-verification-id
9
9
  * APACUANA_INTEGRATION_TYPE=ONBOARDING
10
+ * APACUANA_CUSTOMER_ID=your-customer-id
10
11
  *
11
12
  * Note: APACUANA_DOCUMENT_REFERENCE is provided by the backend team for this
12
13
  * sandbox environment; it's a reference id the document will be linked to.
@@ -38,6 +39,7 @@ const requiredEnvVars = [
38
39
  "APACUANA_API_KEY",
39
40
  "APACUANA_VERIFICATION_ID",
40
41
  "APACUANA_INTEGRATION_TYPE",
42
+ "APACUANA_CUSTOMER_ID",
41
43
  "APACUANA_DOCUMENT_REFERENCE",
42
44
  ];
43
45
 
@@ -58,8 +60,7 @@ describe("createDocument → lockDocument - Integration", () => {
58
60
  apiKey: process.env.APACUANA_API_KEY,
59
61
  verificationId: process.env.APACUANA_VERIFICATION_ID,
60
62
  integrationType: process.env.APACUANA_INTEGRATION_TYPE,
61
- // customerId omitted: init() would set Authorization: Bearer which the
62
- // backend rejects on this endpoint with 404 "Cliente no encontrado".
63
+ customerId: process.env.APACUANA_CUSTOMER_ID,
63
64
  });
64
65
  });
65
66