undici-types 5.27.2 → 5.28.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Matteo Collina and Undici contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/client.d.ts CHANGED
@@ -77,7 +77,7 @@ export declare namespace Client {
77
77
  */
78
78
  allowH2?: boolean;
79
79
  /**
80
- * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overriden by a SETTINGS remote frame.
80
+ * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
81
81
  * @default 100
82
82
  */
83
83
  maxConcurrentStreams?: number
package/dispatcher.d.ts CHANGED
@@ -211,7 +211,7 @@ declare namespace Dispatcher {
211
211
  /** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */
212
212
  onUpgrade?(statusCode: number, headers: Buffer[] | string[] | null, socket: Duplex): void;
213
213
  /** Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. */
214
- onHeaders?(statusCode: number, headers: Buffer[] | string[] | null, resume: () => void): boolean;
214
+ onHeaders?(statusCode: number, headers: Buffer[] | string[] | null, resume: () => void, statusText: string): boolean;
215
215
  /** Invoked when response payload data is received. */
216
216
  onData?(chunk: Buffer): boolean;
217
217
  /** Invoked when response payload and trailers have been received and the request has completed. */
package/index.d.ts CHANGED
@@ -14,6 +14,7 @@ import MockPool from'./mock-pool'
14
14
  import MockAgent from'./mock-agent'
15
15
  import mockErrors from'./mock-errors'
16
16
  import ProxyAgent from'./proxy-agent'
17
+ import RetryHandler from'./retry-handler'
17
18
  import { request, pipeline, stream, connect, upgrade } from './api'
18
19
 
19
20
  export * from './cookies'
@@ -27,7 +28,7 @@ export * from './content-type'
27
28
  export * from './cache'
28
29
  export { Interceptable } from './mock-interceptor'
29
30
 
30
- export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler }
31
+ export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler, RetryHandler }
31
32
  export default Undici
32
33
 
33
34
  declare namespace Undici {
@@ -35,6 +36,7 @@ declare namespace Undici {
35
36
  var Pool: typeof import('./pool').default;
36
37
  var RedirectHandler: typeof import ('./handlers').RedirectHandler
37
38
  var DecoratorHandler: typeof import ('./handlers').DecoratorHandler
39
+ var RetryHandler: typeof import ('./retry-handler').default
38
40
  var createRedirectInterceptor: typeof import ('./interceptors').createRedirectInterceptor
39
41
  var BalancedPool: typeof import('./balanced-pool').default;
40
42
  var Client: typeof import('./client').default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici-types",
3
- "version": "5.27.2",
3
+ "version": "5.28.1",
4
4
  "description": "A stand-alone types package for Undici",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {
@@ -0,0 +1,116 @@
1
+ import Dispatcher from "./dispatcher";
2
+
3
+ export default RetryHandler;
4
+
5
+ declare class RetryHandler implements Dispatcher.DispatchHandlers {
6
+ constructor(
7
+ options: Dispatcher.DispatchOptions & {
8
+ retryOptions?: RetryHandler.RetryOptions;
9
+ },
10
+ retryHandlers: RetryHandler.RetryHandlers
11
+ );
12
+ }
13
+
14
+ declare namespace RetryHandler {
15
+ export type RetryState = { counter: number; currentTimeout: number };
16
+
17
+ export type RetryContext = {
18
+ state: RetryState;
19
+ opts: Dispatcher.DispatchOptions & {
20
+ retryOptions?: RetryHandler.RetryOptions;
21
+ };
22
+ }
23
+
24
+ export type OnRetryCallback = (result?: Error | null) => void;
25
+
26
+ export type RetryCallback = (
27
+ err: Error,
28
+ context: {
29
+ state: RetryState;
30
+ opts: Dispatcher.DispatchOptions & {
31
+ retryOptions?: RetryHandler.RetryOptions;
32
+ };
33
+ },
34
+ callback: OnRetryCallback
35
+ ) => number | null;
36
+
37
+ export interface RetryOptions {
38
+ /**
39
+ * Callback to be invoked on every retry iteration.
40
+ * It receives the error, current state of the retry object and the options object
41
+ * passed when instantiating the retry handler.
42
+ *
43
+ * @type {RetryCallback}
44
+ * @memberof RetryOptions
45
+ */
46
+ retry?: RetryCallback;
47
+ /**
48
+ * Maximum number of retries to allow.
49
+ *
50
+ * @type {number}
51
+ * @memberof RetryOptions
52
+ * @default 5
53
+ */
54
+ maxRetries?: number;
55
+ /**
56
+ * Max number of milliseconds allow between retries
57
+ *
58
+ * @type {number}
59
+ * @memberof RetryOptions
60
+ * @default 30000
61
+ */
62
+ maxTimeout?: number;
63
+ /**
64
+ * Initial number of milliseconds to wait before retrying for the first time.
65
+ *
66
+ * @type {number}
67
+ * @memberof RetryOptions
68
+ * @default 500
69
+ */
70
+ minTimeout?: number;
71
+ /**
72
+ * Factior to multiply the timeout factor between retries.
73
+ *
74
+ * @type {number}
75
+ * @memberof RetryOptions
76
+ * @default 2
77
+ */
78
+ timeoutFactor?: number;
79
+ /**
80
+ * It enables to automatically infer timeout between retries based on the `Retry-After` header.
81
+ *
82
+ * @type {boolean}
83
+ * @memberof RetryOptions
84
+ * @default true
85
+ */
86
+ retryAfter?: boolean;
87
+ /**
88
+ * HTTP methods to retry.
89
+ *
90
+ * @type {Dispatcher.HttpMethod[]}
91
+ * @memberof RetryOptions
92
+ * @default ['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE'],
93
+ */
94
+ methods?: Dispatcher.HttpMethod[];
95
+ /**
96
+ * Error codes to be retried. e.g. `ECONNRESET`, `ENOTFOUND`, `ETIMEDOUT`, `ECONNREFUSED`, etc.
97
+ *
98
+ * @type {string[]}
99
+ * @default ['ECONNRESET','ECONNREFUSED','ENOTFOUND','ENETDOWN','ENETUNREACH','EHOSTDOWN','EHOSTUNREACH','EPIPE']
100
+ */
101
+ errorCodes?: string[];
102
+ /**
103
+ * HTTP status codes to be retried.
104
+ *
105
+ * @type {number[]}
106
+ * @memberof RetryOptions
107
+ * @default [500, 502, 503, 504, 429],
108
+ */
109
+ statusCodes?: number[];
110
+ }
111
+
112
+ export interface RetryHandlers {
113
+ dispatch: Dispatcher["dispatch"];
114
+ handler: Dispatcher.DispatchHandlers;
115
+ }
116
+ }