@podium/client 5.1.9 → 5.1.10-next.1
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/CHANGELOG.md +7 -0
- package/lib/http.js +10 -4
- package/lib/resolver.content.js +2 -1
- package/package.json +1 -1
- package/types/http.d.ts +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [5.1.10-next.1](https://github.com/podium-lib/client/compare/v5.1.9...v5.1.10-next.1) (2024-08-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* use AbortSignal to ensure timeouts are respected ([08899d9](https://github.com/podium-lib/client/commit/08899d974246037cb1893a5b6d06bd6df58815e2))
|
|
7
|
+
|
|
1
8
|
## [5.1.9](https://github.com/podium-lib/client/compare/v5.1.8...v5.1.9) (2024-08-19)
|
|
2
9
|
|
|
3
10
|
|
package/lib/http.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { request } from 'undici';
|
|
1
|
+
import { request as undiciRequest } from 'undici';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {object} PodiumHttpClientRequestOptions
|
|
@@ -7,21 +7,27 @@ import { request } from 'undici';
|
|
|
7
7
|
* @property {boolean} [rejectUnauthorized]
|
|
8
8
|
* @property {boolean} [follow]
|
|
9
9
|
* @property {number} [timeout]
|
|
10
|
-
* @property {number} [bodyTimeout]
|
|
11
10
|
* @property {object} [query]
|
|
12
11
|
* @property {import('http').IncomingHttpHeaders} [headers]
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
14
|
export default class HTTP {
|
|
15
|
+
constructor(requestFn = undiciRequest) {
|
|
16
|
+
this.requestFn = requestFn;
|
|
17
|
+
}
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* @param {string} url
|
|
18
21
|
* @param {PodiumHttpClientRequestOptions} options
|
|
19
22
|
* @returns {Promise<Pick<import('undici').Dispatcher.ResponseData, 'statusCode' | 'headers' | 'body'>>}
|
|
20
23
|
*/
|
|
21
24
|
async request(url, options) {
|
|
22
|
-
const { statusCode, headers, body } = await
|
|
25
|
+
const { statusCode, headers, body } = await this.requestFn(
|
|
23
26
|
new URL(url),
|
|
24
|
-
|
|
27
|
+
{
|
|
28
|
+
...options,
|
|
29
|
+
signal: AbortSignal.timeout(options.timeout || 1000),
|
|
30
|
+
},
|
|
25
31
|
);
|
|
26
32
|
return { statusCode, headers, body };
|
|
27
33
|
}
|
package/lib/resolver.content.js
CHANGED
|
@@ -136,7 +136,7 @@ export default class PodletClientContentResolver {
|
|
|
136
136
|
/** @type {import('./http.js').PodiumHttpClientRequestOptions} */
|
|
137
137
|
const reqOptions = {
|
|
138
138
|
rejectUnauthorized: outgoing.rejectUnauthorized,
|
|
139
|
-
|
|
139
|
+
timeout: outgoing.timeout,
|
|
140
140
|
method: 'GET',
|
|
141
141
|
query: outgoing.reqOptions.query,
|
|
142
142
|
headers,
|
|
@@ -267,6 +267,7 @@ export default class PodletClientContentResolver {
|
|
|
267
267
|
}),
|
|
268
268
|
);
|
|
269
269
|
|
|
270
|
+
// @ts-ignore
|
|
270
271
|
pipeline([body, outgoing], (err) => {
|
|
271
272
|
if (err) {
|
|
272
273
|
this.#log.warn('error while piping content stream', err);
|
package/package.json
CHANGED
package/types/http.d.ts
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* @property {boolean} [rejectUnauthorized]
|
|
6
6
|
* @property {boolean} [follow]
|
|
7
7
|
* @property {number} [timeout]
|
|
8
|
-
* @property {number} [bodyTimeout]
|
|
9
8
|
* @property {object} [query]
|
|
10
9
|
* @property {import('http').IncomingHttpHeaders} [headers]
|
|
11
10
|
*/
|
|
12
11
|
export default class HTTP {
|
|
12
|
+
constructor(requestFn?: typeof undiciRequest);
|
|
13
|
+
requestFn: typeof undiciRequest;
|
|
13
14
|
/**
|
|
14
15
|
* @param {string} url
|
|
15
16
|
* @param {PodiumHttpClientRequestOptions} options
|
|
@@ -23,7 +24,7 @@ export type PodiumHttpClientRequestOptions = {
|
|
|
23
24
|
rejectUnauthorized?: boolean;
|
|
24
25
|
follow?: boolean;
|
|
25
26
|
timeout?: number;
|
|
26
|
-
bodyTimeout?: number;
|
|
27
27
|
query?: object;
|
|
28
28
|
headers?: import('http').IncomingHttpHeaders;
|
|
29
29
|
};
|
|
30
|
+
import { request as undiciRequest } from 'undici';
|