arca-sdk 0.1.2 → 0.1.3

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/dist/index.cjs CHANGED
@@ -79,6 +79,12 @@ var ArcaValidationError = class extends ArcaError {
79
79
  this.name = "ArcaValidationError";
80
80
  }
81
81
  };
82
+ var ArcaNetworkError = class extends ArcaError {
83
+ constructor(message, details) {
84
+ super(message, "NETWORK_ERROR", details);
85
+ this.name = "ArcaNetworkError";
86
+ }
87
+ };
82
88
 
83
89
  // src/utils/xml.ts
84
90
  var import_fast_xml_parser = require("fast-xml-parser");
@@ -245,21 +251,47 @@ var TicketManager = class {
245
251
  // src/utils/network.ts
246
252
  var import_https = __toESM(require("https"), 1);
247
253
  async function callArcaApi(url, options) {
254
+ const timeout = options.timeout || 15e3;
248
255
  const isNode = typeof process !== "undefined" && process.versions && process.versions.node;
249
- if (isNode) {
250
- const agent = new import_https.default.Agent({
251
- // Permitir llaves DH de 1024 bits (AFIP) bajando a Security Level 1
252
- // solo para esta conexión específica.
253
- ciphers: "DEFAULT@SECLEVEL=1",
254
- rejectUnauthorized: true
255
- // Seguimos validando el certificado
256
+ const controller = new AbortController();
257
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
258
+ try {
259
+ if (isNode) {
260
+ const agent = new import_https.default.Agent({
261
+ // Permitir llaves DH de 1024 bits (AFIP) bajando a Security Level 1
262
+ // solo para esta conexión específica.
263
+ ciphers: "DEFAULT@SECLEVEL=1",
264
+ rejectUnauthorized: true
265
+ });
266
+ return await fetch(url, {
267
+ method: options.method,
268
+ headers: options.headers,
269
+ body: options.body,
270
+ agent,
271
+ signal: controller.signal
272
+ });
273
+ }
274
+ return await fetch(url, {
275
+ method: options.method,
276
+ headers: options.headers,
277
+ body: options.body,
278
+ signal: controller.signal
256
279
  });
257
- return fetch(url, {
258
- ...options,
259
- agent
280
+ } catch (error) {
281
+ if (error.name === "AbortError") {
282
+ throw new ArcaNetworkError(`Tiempo de espera agotado (${timeout}ms) al conectar con ARCA: ${url}`);
283
+ }
284
+ let message = error.message;
285
+ if (message.includes("dh key too small")) {
286
+ message = "Error SSL de ARCA (DH Key too small). El SDK intent\xF3 mitigarlo pero fall\xF3. Verifique su versi\xF3n de Node.js.";
287
+ }
288
+ throw new ArcaNetworkError(`Error de red al comunicarse con ARCA: ${message}`, {
289
+ url,
290
+ originalError: error
260
291
  });
292
+ } finally {
293
+ clearTimeout(timeoutId);
261
294
  }
262
- return fetch(url, options);
263
295
  }
264
296
 
265
297
  // src/auth/wsaa.ts
@@ -336,7 +368,8 @@ var WsaaService = class {
336
368
  "Content-Type": "text/xml; charset=utf-8",
337
369
  "SOAPAction": ""
338
370
  },
339
- body: this.buildSoapRequest(cms)
371
+ body: this.buildSoapRequest(cms),
372
+ timeout: this.config.timeout
340
373
  });
341
374
  if (!response.ok) {
342
375
  throw new ArcaAuthError(
@@ -625,7 +658,8 @@ var WsfeService = class {
625
658
  "Content-Type": "text/xml; charset=utf-8",
626
659
  "SOAPAction": "http://ar.gov.afip.dif.FEV1/FECAESolicitar"
627
660
  },
628
- body: soapRequest
661
+ body: soapRequest,
662
+ timeout: this.config.timeout
629
663
  });
630
664
  if (!response.ok) {
631
665
  throw new ArcaError(
package/dist/index.d.cts CHANGED
@@ -13,6 +13,8 @@ interface ArcaConfig {
13
13
  environment: Environment;
14
14
  /** CUIT del contribuyente (11 dígitos sin guiones) */
15
15
  cuit: string;
16
+ /** Tiempo de espera para peticiones (ms). Defecto: 15000 */
17
+ timeout?: number;
16
18
  }
17
19
  /**
18
20
  * Error personalizado de ARCA SDK
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ interface ArcaConfig {
13
13
  environment: Environment;
14
14
  /** CUIT del contribuyente (11 dígitos sin guiones) */
15
15
  cuit: string;
16
+ /** Tiempo de espera para peticiones (ms). Defecto: 15000 */
17
+ timeout?: number;
16
18
  }
17
19
  /**
18
20
  * Error personalizado de ARCA SDK
package/dist/index.js CHANGED
@@ -35,6 +35,12 @@ var ArcaValidationError = class extends ArcaError {
35
35
  this.name = "ArcaValidationError";
36
36
  }
37
37
  };
38
+ var ArcaNetworkError = class extends ArcaError {
39
+ constructor(message, details) {
40
+ super(message, "NETWORK_ERROR", details);
41
+ this.name = "ArcaNetworkError";
42
+ }
43
+ };
38
44
 
39
45
  // src/utils/xml.ts
40
46
  import { XMLBuilder, XMLParser } from "fast-xml-parser";
@@ -201,21 +207,47 @@ var TicketManager = class {
201
207
  // src/utils/network.ts
202
208
  import https from "https";
203
209
  async function callArcaApi(url, options) {
210
+ const timeout = options.timeout || 15e3;
204
211
  const isNode = typeof process !== "undefined" && process.versions && process.versions.node;
205
- if (isNode) {
206
- const agent = new https.Agent({
207
- // Permitir llaves DH de 1024 bits (AFIP) bajando a Security Level 1
208
- // solo para esta conexión específica.
209
- ciphers: "DEFAULT@SECLEVEL=1",
210
- rejectUnauthorized: true
211
- // Seguimos validando el certificado
212
+ const controller = new AbortController();
213
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
214
+ try {
215
+ if (isNode) {
216
+ const agent = new https.Agent({
217
+ // Permitir llaves DH de 1024 bits (AFIP) bajando a Security Level 1
218
+ // solo para esta conexión específica.
219
+ ciphers: "DEFAULT@SECLEVEL=1",
220
+ rejectUnauthorized: true
221
+ });
222
+ return await fetch(url, {
223
+ method: options.method,
224
+ headers: options.headers,
225
+ body: options.body,
226
+ agent,
227
+ signal: controller.signal
228
+ });
229
+ }
230
+ return await fetch(url, {
231
+ method: options.method,
232
+ headers: options.headers,
233
+ body: options.body,
234
+ signal: controller.signal
212
235
  });
213
- return fetch(url, {
214
- ...options,
215
- agent
236
+ } catch (error) {
237
+ if (error.name === "AbortError") {
238
+ throw new ArcaNetworkError(`Tiempo de espera agotado (${timeout}ms) al conectar con ARCA: ${url}`);
239
+ }
240
+ let message = error.message;
241
+ if (message.includes("dh key too small")) {
242
+ message = "Error SSL de ARCA (DH Key too small). El SDK intent\xF3 mitigarlo pero fall\xF3. Verifique su versi\xF3n de Node.js.";
243
+ }
244
+ throw new ArcaNetworkError(`Error de red al comunicarse con ARCA: ${message}`, {
245
+ url,
246
+ originalError: error
216
247
  });
248
+ } finally {
249
+ clearTimeout(timeoutId);
217
250
  }
218
- return fetch(url, options);
219
251
  }
220
252
 
221
253
  // src/auth/wsaa.ts
@@ -292,7 +324,8 @@ var WsaaService = class {
292
324
  "Content-Type": "text/xml; charset=utf-8",
293
325
  "SOAPAction": ""
294
326
  },
295
- body: this.buildSoapRequest(cms)
327
+ body: this.buildSoapRequest(cms),
328
+ timeout: this.config.timeout
296
329
  });
297
330
  if (!response.ok) {
298
331
  throw new ArcaAuthError(
@@ -581,7 +614,8 @@ var WsfeService = class {
581
614
  "Content-Type": "text/xml; charset=utf-8",
582
615
  "SOAPAction": "http://ar.gov.afip.dif.FEV1/FECAESolicitar"
583
616
  },
584
- body: soapRequest
617
+ body: soapRequest,
618
+ timeout: this.config.timeout
585
619
  });
586
620
  if (!response.ok) {
587
621
  throw new ArcaError(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arca-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "SDK moderna en TypeScript para ARCA (ex-AFIP)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",