arca-sdk 0.1.1 → 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");
@@ -242,6 +248,52 @@ var TicketManager = class {
242
248
  }
243
249
  };
244
250
 
251
+ // src/utils/network.ts
252
+ var import_https = __toESM(require("https"), 1);
253
+ async function callArcaApi(url, options) {
254
+ const timeout = options.timeout || 15e3;
255
+ const isNode = typeof process !== "undefined" && process.versions && process.versions.node;
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
279
+ });
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
291
+ });
292
+ } finally {
293
+ clearTimeout(timeoutId);
294
+ }
295
+ }
296
+
245
297
  // src/auth/wsaa.ts
246
298
  var WsaaService = class {
247
299
  config;
@@ -310,13 +362,14 @@ var WsaaService = class {
310
362
  );
311
363
  }
312
364
  const endpoint = getWsaaEndpoint(this.config.environment);
313
- const response = await fetch(endpoint, {
365
+ const response = await callArcaApi(endpoint, {
314
366
  method: "POST",
315
367
  headers: {
316
368
  "Content-Type": "text/xml; charset=utf-8",
317
369
  "SOAPAction": ""
318
370
  },
319
- body: this.buildSoapRequest(cms)
371
+ body: this.buildSoapRequest(cms),
372
+ timeout: this.config.timeout
320
373
  });
321
374
  if (!response.ok) {
322
375
  throw new ArcaAuthError(
@@ -599,13 +652,14 @@ var WsfeService = class {
599
652
  ivaData: request.ivaData
600
653
  });
601
654
  const endpoint = getWsfeEndpoint(this.config.environment);
602
- const response = await fetch(endpoint, {
655
+ const response = await callArcaApi(endpoint, {
603
656
  method: "POST",
604
657
  headers: {
605
658
  "Content-Type": "text/xml; charset=utf-8",
606
659
  "SOAPAction": "http://ar.gov.afip.dif.FEV1/FECAESolicitar"
607
660
  },
608
- body: soapRequest
661
+ body: soapRequest,
662
+ timeout: this.config.timeout
609
663
  });
610
664
  if (!response.ok) {
611
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";
@@ -198,6 +204,52 @@ var TicketManager = class {
198
204
  }
199
205
  };
200
206
 
207
+ // src/utils/network.ts
208
+ import https from "https";
209
+ async function callArcaApi(url, options) {
210
+ const timeout = options.timeout || 15e3;
211
+ const isNode = typeof process !== "undefined" && process.versions && process.versions.node;
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
235
+ });
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
247
+ });
248
+ } finally {
249
+ clearTimeout(timeoutId);
250
+ }
251
+ }
252
+
201
253
  // src/auth/wsaa.ts
202
254
  var WsaaService = class {
203
255
  config;
@@ -266,13 +318,14 @@ var WsaaService = class {
266
318
  );
267
319
  }
268
320
  const endpoint = getWsaaEndpoint(this.config.environment);
269
- const response = await fetch(endpoint, {
321
+ const response = await callArcaApi(endpoint, {
270
322
  method: "POST",
271
323
  headers: {
272
324
  "Content-Type": "text/xml; charset=utf-8",
273
325
  "SOAPAction": ""
274
326
  },
275
- body: this.buildSoapRequest(cms)
327
+ body: this.buildSoapRequest(cms),
328
+ timeout: this.config.timeout
276
329
  });
277
330
  if (!response.ok) {
278
331
  throw new ArcaAuthError(
@@ -555,13 +608,14 @@ var WsfeService = class {
555
608
  ivaData: request.ivaData
556
609
  });
557
610
  const endpoint = getWsfeEndpoint(this.config.environment);
558
- const response = await fetch(endpoint, {
611
+ const response = await callArcaApi(endpoint, {
559
612
  method: "POST",
560
613
  headers: {
561
614
  "Content-Type": "text/xml; charset=utf-8",
562
615
  "SOAPAction": "http://ar.gov.afip.dif.FEV1/FECAESolicitar"
563
616
  },
564
- body: soapRequest
617
+ body: soapRequest,
618
+ timeout: this.config.timeout
565
619
  });
566
620
  if (!response.ok) {
567
621
  throw new ArcaError(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arca-sdk",
3
- "version": "0.1.1",
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",