@trayio/axios 5.16.0 → 5.17.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.
@@ -1 +1 @@
1
- {"version":3,"file":"AxiosHttpClient.d.ts","sourceRoot":"","sources":["../../src/http/AxiosHttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAEN,UAAU,EACV,WAAW,EAEX,YAAY,EAEZ,MAAM,2BAA2B,CAAC;AAWnC,OAAO,QAAQ,GAAG,QAAQ,WAAW,CAAC,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAMxD,KAAK,YAAY,GAAG;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAWF,qBAAa,eAAgB,YAAW,UAAU;IAMhD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAL7B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IAC1C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA8B;IAC5D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuB;gBAGrC,WAAW,GAAE,WAAqC,EACnE,YAAY,GAAE,YAAiB;IAgDhC,OAAO,CACN,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,GAClB,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC;IAgHrC,OAAO,CAAC,wBAAwB;IAmBhC,OAAO,CAAC,2BAA2B;IAUnC,YAAY,aAAc,QAAQ,cA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ttpClient {
129
129
  httpsAgent: axiosHttpsAgent,
130
130
  params: request.queryString,
131
131
  ...(this.resolvedOptions.followRedirects ? {} : { maxRedirects: 0 }),
132
- timeout: this.resolvedOptions.timeout,
132
+ timeout: (0, function_1.pipe)(request.timeout ?? O.none, O.getOrElse(() => this.resolvedOptions.timeout)),
133
133
  };
134
134
  return (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => this.axiosInstance(axiosConfig)
135
135
  .then(this.axiosResponseToHttpResponse)
@@ -144,7 +144,7 @@ class AxiosHttpClient {
144
144
  httpsAgent: axiosHttpsAgent,
145
145
  params: request.queryString,
146
146
  ...(this.resolvedOptions.followRedirects ? {} : { maxRedirects: 0 }),
147
- timeout: this.resolvedOptions.timeout,
147
+ timeout: (0, function_1.pipe)(request.timeout ?? O.none, O.getOrElse(() => this.resolvedOptions.timeout)),
148
148
  };
149
149
  return (0, Task_1.createTaskEitherFromPromiseWithSimpleError)(() => this.axiosInstance(axiosConfig)
150
150
  .then(this.axiosResponseToHttpResponse)
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const HttpClient_abstract_test_1 = require("@trayio/commons/http/HttpClient.abstract.test");
30
30
  const NodeFsFileStorage_1 = require("@trayio/commons/file/NodeFsFileStorage");
31
+ const O = __importStar(require("fp-ts/Option"));
31
32
  const E = __importStar(require("fp-ts/Either"));
32
33
  const Http_1 = require("@trayio/commons/http/Http");
33
34
  const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
@@ -271,5 +272,88 @@ describe('AxiosHttpClient Tests', () => {
271
272
  expect(response.right.statusCode).toBe(200);
272
273
  }
273
274
  });
275
+ test('should use per-request timeout when provided, overriding constructor timeout', async () => {
276
+ const axiosHttpClient = new AxiosHttpClient_1.AxiosHttpClient(new NodeFsFileStorage_1.NodeFsFileStorage(), {
277
+ rejectUnauthorized: false,
278
+ followRedirects: true,
279
+ timeout: 5000, // 5 second constructor-level timeout (long)
280
+ });
281
+ const testUrl = 'http://test-per-request-timeout.example.com';
282
+ // Mock a slow response (500ms delay)
283
+ (0, nock_1.default)(testUrl)
284
+ .get('/')
285
+ .delay(500) // 500ms delay
286
+ .reply(200, { success: true });
287
+ const response = await axiosHttpClient.execute(Http_1.HttpMethod.Get, testUrl, Http_1.HttpRequest.create({
288
+ headers: {},
289
+ pathParams: {},
290
+ queryString: {},
291
+ body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
292
+ timeout: O.some(50), // 50ms per-request timeout (short) - should override constructor timeout
293
+ }))();
294
+ // Should timeout because per-request timeout (50ms) is used instead of constructor timeout (5000ms)
295
+ expect(E.isRight(response)).toBe(true);
296
+ if (E.isRight(response)) {
297
+ // AxiosHttpClient converts timeout errors to 500 responses
298
+ expect(response.right.statusCode).toBe(500);
299
+ }
300
+ });
301
+ test('should use constructor timeout when per-request timeout is O.none', async () => {
302
+ const axiosHttpClient = new AxiosHttpClient_1.AxiosHttpClient(new NodeFsFileStorage_1.NodeFsFileStorage(), {
303
+ rejectUnauthorized: false,
304
+ followRedirects: true,
305
+ timeout: 50, // 50ms constructor-level timeout (short)
306
+ });
307
+ const testUrl = 'http://test-none-timeout.example.com';
308
+ // Mock a slow response (500ms delay)
309
+ (0, nock_1.default)(testUrl)
310
+ .get('/')
311
+ .delay(500) // 500ms delay
312
+ .reply(200, { success: true });
313
+ const response = await axiosHttpClient.execute(Http_1.HttpMethod.Get, testUrl, Http_1.HttpRequest.create({
314
+ headers: {},
315
+ pathParams: {},
316
+ queryString: {},
317
+ body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
318
+ timeout: O.none, // No per-request timeout - should use constructor timeout (50ms)
319
+ }))();
320
+ // Should timeout because constructor timeout (50ms) is used
321
+ expect(E.isRight(response)).toBe(true);
322
+ if (E.isRight(response)) {
323
+ // AxiosHttpClient converts timeout errors to 500 responses
324
+ expect(response.right.statusCode).toBe(500);
325
+ }
326
+ });
327
+ test('should use constructor timeout when timeout field is omitted (backward compatibility)', async () => {
328
+ const axiosHttpClient = new AxiosHttpClient_1.AxiosHttpClient(new NodeFsFileStorage_1.NodeFsFileStorage(), {
329
+ rejectUnauthorized: false,
330
+ followRedirects: true,
331
+ timeout: 50, // 50ms constructor-level timeout (short)
332
+ });
333
+ const testUrl = 'http://test-omitted-timeout.example.com';
334
+ // Mock a slow response (500ms delay)
335
+ (0, nock_1.default)(testUrl)
336
+ .get('/')
337
+ .delay(500) // 500ms delay
338
+ .reply(200, { success: true });
339
+ // Create request without timeout field (backward compatible with old code)
340
+ const request = {
341
+ headers: {},
342
+ pathParams: {},
343
+ queryString: {},
344
+ body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
345
+ headerOptions: O.none,
346
+ agent: O.none,
347
+ clientIp: O.none,
348
+ // timeout field omitted - should use constructor timeout (50ms)
349
+ };
350
+ const response = await axiosHttpClient.execute(Http_1.HttpMethod.Get, testUrl, request)();
351
+ // Should timeout because constructor timeout (50ms) is used
352
+ expect(E.isRight(response)).toBe(true);
353
+ if (E.isRight(response)) {
354
+ // AxiosHttpClient converts timeout errors to 500 responses
355
+ expect(response.right.statusCode).toBe(500);
356
+ }
357
+ });
274
358
  });
275
359
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/axios",
3
- "version": "5.16.0",
3
+ "version": "5.17.0",
4
4
  "description": "Axios extensions and implementations",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -14,7 +14,7 @@
14
14
  "access": "public"
15
15
  },
16
16
  "dependencies": {
17
- "@trayio/commons": "5.16.0",
17
+ "@trayio/commons": "5.17.0",
18
18
  "axios": "1.13.5",
19
19
  "axios-retry": "4.5.0",
20
20
  "form-data": "4.0.4"