@foundatiofx/fetchclient 1.1.1 → 1.2.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.
- package/esm/mod.js +83 -0
- package/esm/src/DefaultHelpers.js +5 -5
- package/esm/src/FetchClient.js +66 -41
- package/esm/src/FetchClientError.js +73 -0
- package/esm/src/FetchClientProvider.js +24 -0
- package/esm/src/RateLimitMiddleware.js +35 -1
- package/esm/src/ResponsePromise.js +163 -0
- package/esm/src/RetryMiddleware.js +179 -0
- package/esm/src/mocks/MockHistory.js +8 -0
- package/esm/src/mocks/MockRegistry.js +7 -0
- package/package.json +1 -1
- package/script/mod.js +94 -1
- package/script/src/DefaultHelpers.js +5 -5
- package/script/src/FetchClient.js +66 -41
- package/script/src/FetchClientError.js +77 -0
- package/script/src/FetchClientProvider.js +24 -0
- package/script/src/RateLimitMiddleware.js +36 -0
- package/script/src/ResponsePromise.js +167 -0
- package/script/src/RetryMiddleware.js +184 -0
- package/script/src/mocks/MockHistory.js +8 -0
- package/script/src/mocks/MockRegistry.js +7 -0
- package/types/mod.d.ts +96 -0
- package/types/mod.d.ts.map +1 -1
- package/types/src/DefaultHelpers.d.ts +5 -5
- package/types/src/FetchClient.d.ts +31 -15
- package/types/src/FetchClient.d.ts.map +1 -1
- package/types/src/FetchClientError.d.ts +29 -0
- package/types/src/FetchClientError.d.ts.map +1 -0
- package/types/src/FetchClientProvider.d.ts +11 -0
- package/types/src/FetchClientProvider.d.ts.map +1 -1
- package/types/src/RateLimitMiddleware.d.ts +27 -0
- package/types/src/RateLimitMiddleware.d.ts.map +1 -1
- package/types/src/ResponsePromise.d.ts +93 -0
- package/types/src/ResponsePromise.d.ts.map +1 -0
- package/types/src/RetryMiddleware.d.ts +88 -0
- package/types/src/RetryMiddleware.d.ts.map +1 -0
- package/types/src/mocks/MockHistory.d.ts +1 -0
- package/types/src/mocks/MockHistory.d.ts.map +1 -1
- package/types/src/mocks/MockRegistry.d.ts +5 -0
- package/types/src/mocks/MockRegistry.d.ts.map +1 -1
- package/types/src/mocks/types.d.ts +2 -0
- package/types/src/mocks/types.d.ts.map +1 -1
- package/types/src/tests/RetryMiddleware.test.d.ts.map +1 -0
|
@@ -17,7 +17,7 @@ export declare function useFetchClient(options?: FetchClientOptions): FetchClien
|
|
|
17
17
|
* Sends a GET request to the specified URL using the default client and provider and returns the response as JSON.
|
|
18
18
|
* @param url - The URL to send the GET request to.
|
|
19
19
|
* @param options - Optional request options.
|
|
20
|
-
* @returns A promise that resolves to the response
|
|
20
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
21
21
|
*/
|
|
22
22
|
export declare function getJSON<T>(url: string, options?: GetRequestOptions): Promise<FetchClientResponse<T>>;
|
|
23
23
|
/**
|
|
@@ -27,7 +27,7 @@ export declare function getJSON<T>(url: string, options?: GetRequestOptions): Pr
|
|
|
27
27
|
* @param {string} url - The URL to send the request to.
|
|
28
28
|
* @param {object | string | FormData} [body] - The JSON payload or form data to send with the request.
|
|
29
29
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
30
|
-
* @returns
|
|
30
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
31
31
|
*/
|
|
32
32
|
export declare function postJSON<T>(url: string, body?: object | string | FormData, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
33
33
|
/**
|
|
@@ -37,7 +37,7 @@ export declare function postJSON<T>(url: string, body?: object | string | FormDa
|
|
|
37
37
|
* @param {string} url - The URL to send the request to.
|
|
38
38
|
* @param {object | string} [body] - The JSON payload to send with the request.
|
|
39
39
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
40
|
-
* @returns
|
|
40
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
41
41
|
*/
|
|
42
42
|
export declare function putJSON<T>(url: string, body?: object | string, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
43
43
|
/**
|
|
@@ -47,7 +47,7 @@ export declare function putJSON<T>(url: string, body?: object | string, options?
|
|
|
47
47
|
* @param {string} url - The URL to send the request to.
|
|
48
48
|
* @param {object | string} [body] - The JSON payload to send with the request.
|
|
49
49
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
50
|
-
* @returns
|
|
50
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
51
51
|
*/
|
|
52
52
|
export declare function patchJSON<T>(url: string, body?: object | string, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
53
53
|
/**
|
|
@@ -56,7 +56,7 @@ export declare function patchJSON<T>(url: string, body?: object | string, option
|
|
|
56
56
|
* @template T - The type of the response data.
|
|
57
57
|
* @param {string} url - The URL to send the request to.
|
|
58
58
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
59
|
-
* @returns
|
|
59
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
60
60
|
*/
|
|
61
61
|
export declare function deleteJSON<T>(url: string, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
62
62
|
/**
|
|
@@ -5,6 +5,7 @@ import type { FetchClientCache } from "./FetchClientCache.js";
|
|
|
5
5
|
import { FetchClientProvider } from "./FetchClientProvider.js";
|
|
6
6
|
import type { FetchClientOptions } from "./FetchClientOptions.js";
|
|
7
7
|
import { type IObjectEvent } from "./ObjectEvent.js";
|
|
8
|
+
import { ResponsePromise } from "./ResponsePromise.js";
|
|
8
9
|
type Fetch = typeof globalThis.fetch;
|
|
9
10
|
/**
|
|
10
11
|
* Represents a client for making HTTP requests using the Fetch API.
|
|
@@ -57,14 +58,16 @@ export declare class FetchClient {
|
|
|
57
58
|
*
|
|
58
59
|
* @param url - The URL to send the GET request to.
|
|
59
60
|
* @param options - The optional request options.
|
|
60
|
-
* @returns A
|
|
61
|
+
* @returns A ResponsePromise that resolves to the response. Can use `.json<T>()` for typed JSON.
|
|
61
62
|
*/
|
|
62
|
-
get(url: string, options?: GetRequestOptions):
|
|
63
|
+
get(url: string, options?: GetRequestOptions): ResponsePromise<unknown>;
|
|
63
64
|
/**
|
|
64
65
|
* Sends a GET request to the specified URL and returns the response as JSON.
|
|
66
|
+
* The response will have the parsed JSON in `response.data`.
|
|
67
|
+
*
|
|
65
68
|
* @param url - The URL to send the GET request to.
|
|
66
69
|
* @param options - Optional request options.
|
|
67
|
-
* @returns A promise that resolves to the response
|
|
70
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
68
71
|
*/
|
|
69
72
|
getJSON<T>(url: string, options?: GetRequestOptions): Promise<FetchClientResponse<T>>;
|
|
70
73
|
/**
|
|
@@ -73,17 +76,18 @@ export declare class FetchClient {
|
|
|
73
76
|
* @param url - The URL to send the request to.
|
|
74
77
|
* @param body - The request body, can be an object, a string, or FormData.
|
|
75
78
|
* @param options - Additional options for the request.
|
|
76
|
-
* @returns A
|
|
79
|
+
* @returns A ResponsePromise that resolves to the response. Can use `.json<T>()` for typed JSON.
|
|
77
80
|
*/
|
|
78
|
-
post(url: string, body?: object | string | FormData, options?: RequestOptions):
|
|
81
|
+
post(url: string, body?: object | string | FormData, options?: RequestOptions): ResponsePromise<unknown>;
|
|
79
82
|
/**
|
|
80
83
|
* Sends a POST request with JSON payload to the specified URL.
|
|
84
|
+
* The response will have the parsed JSON in `response.data`.
|
|
81
85
|
*
|
|
82
86
|
* @template T - The type of the response data.
|
|
83
87
|
* @param {string} url - The URL to send the request to.
|
|
84
88
|
* @param {object | string | FormData} [body] - The JSON payload or form data to send with the request.
|
|
85
89
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
86
|
-
* @returns
|
|
90
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
87
91
|
*/
|
|
88
92
|
postJSON<T>(url: string, body?: object | string | FormData, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
89
93
|
/**
|
|
@@ -91,17 +95,18 @@ export declare class FetchClient {
|
|
|
91
95
|
* @param url - The URL to send the request to.
|
|
92
96
|
* @param body - The request body, can be an object, a string, or FormData.
|
|
93
97
|
* @param options - The request options.
|
|
94
|
-
* @returns A
|
|
98
|
+
* @returns A ResponsePromise that resolves to the response. Can use `.json<T>()` for typed JSON.
|
|
95
99
|
*/
|
|
96
|
-
put(url: string, body?: object | string | FormData, options?: RequestOptions):
|
|
100
|
+
put(url: string, body?: object | string | FormData, options?: RequestOptions): ResponsePromise<unknown>;
|
|
97
101
|
/**
|
|
98
102
|
* Sends a PUT request with JSON payload to the specified URL.
|
|
103
|
+
* The response will have the parsed JSON in `response.data`.
|
|
99
104
|
*
|
|
100
105
|
* @template T - The type of the response data.
|
|
101
106
|
* @param {string} url - The URL to send the request to.
|
|
102
107
|
* @param {object | string} [body] - The JSON payload to send with the request.
|
|
103
108
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
104
|
-
* @returns
|
|
109
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
105
110
|
*/
|
|
106
111
|
putJSON<T>(url: string, body?: object | string, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
107
112
|
/**
|
|
@@ -109,17 +114,18 @@ export declare class FetchClient {
|
|
|
109
114
|
* @param url - The URL to send the PATCH request to.
|
|
110
115
|
* @param body - The body of the request. It can be an object, a string, or FormData.
|
|
111
116
|
* @param options - The options for the request.
|
|
112
|
-
* @returns A
|
|
117
|
+
* @returns A ResponsePromise that resolves to the response. Can use `.json<T>()` for typed JSON.
|
|
113
118
|
*/
|
|
114
|
-
patch(url: string, body?: object | string | FormData, options?: RequestOptions):
|
|
119
|
+
patch(url: string, body?: object | string | FormData, options?: RequestOptions): ResponsePromise<unknown>;
|
|
115
120
|
/**
|
|
116
121
|
* Sends a PATCH request with JSON payload to the specified URL.
|
|
122
|
+
* The response will have the parsed JSON in `response.data`.
|
|
117
123
|
*
|
|
118
124
|
* @template T - The type of the response data.
|
|
119
125
|
* @param {string} url - The URL to send the request to.
|
|
120
126
|
* @param {object | string} [body] - The JSON payload to send with the request.
|
|
121
127
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
122
|
-
* @returns
|
|
128
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
123
129
|
*/
|
|
124
130
|
patchJSON<T>(url: string, body?: object | string, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
125
131
|
/**
|
|
@@ -127,18 +133,28 @@ export declare class FetchClient {
|
|
|
127
133
|
*
|
|
128
134
|
* @param url - The URL to send the DELETE request to.
|
|
129
135
|
* @param options - The options for the request.
|
|
130
|
-
* @returns A
|
|
136
|
+
* @returns A ResponsePromise that resolves to the response. Can use `.json<T>()` for typed JSON.
|
|
131
137
|
*/
|
|
132
|
-
delete(url: string, options?: RequestOptions):
|
|
138
|
+
delete(url: string, options?: RequestOptions): ResponsePromise<unknown>;
|
|
133
139
|
/**
|
|
134
140
|
* Sends a DELETE request with JSON payload to the specified URL.
|
|
141
|
+
* The response will have the parsed JSON in `response.data`.
|
|
135
142
|
*
|
|
136
143
|
* @template T - The type of the response data.
|
|
137
144
|
* @param {string} url - The URL to send the request to.
|
|
138
145
|
* @param {RequestOptions} [options] - Additional options for the request.
|
|
139
|
-
* @returns
|
|
146
|
+
* @returns A promise that resolves to the response with parsed JSON in `data`.
|
|
140
147
|
*/
|
|
141
148
|
deleteJSON<T>(url: string, options?: RequestOptions): Promise<FetchClientResponse<T>>;
|
|
149
|
+
/**
|
|
150
|
+
* Sends a HEAD request to the specified URL.
|
|
151
|
+
* HEAD requests are identical to GET requests but without the response body.
|
|
152
|
+
*
|
|
153
|
+
* @param url - The URL to send the HEAD request to.
|
|
154
|
+
* @param options - The optional request options.
|
|
155
|
+
* @returns A ResponsePromise that resolves to the response.
|
|
156
|
+
*/
|
|
157
|
+
head(url: string, options?: GetRequestOptions): ResponsePromise<void>;
|
|
142
158
|
private validate;
|
|
143
159
|
private fetchInternal;
|
|
144
160
|
private invokeMiddleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchClient.d.ts","sourceRoot":"","sources":["../../src/src/FetchClient.ts"],"names":[],"mappings":"AACA,OAAO,KA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for non-2xx responses.
|
|
4
|
+
* Exposes the underlying response for compatibility and debugging.
|
|
5
|
+
*/
|
|
6
|
+
export declare class FetchClientError extends Error {
|
|
7
|
+
readonly response: FetchClientResponse<unknown>;
|
|
8
|
+
constructor(response: FetchClientResponse<unknown>, message?: string);
|
|
9
|
+
get status(): number;
|
|
10
|
+
get statusText(): string;
|
|
11
|
+
get ok(): boolean;
|
|
12
|
+
get headers(): Headers;
|
|
13
|
+
get url(): string;
|
|
14
|
+
get redirected(): boolean;
|
|
15
|
+
get type(): ResponseType;
|
|
16
|
+
get body(): ReadableStream<Uint8Array> | null;
|
|
17
|
+
get bodyUsed(): boolean;
|
|
18
|
+
get data(): unknown;
|
|
19
|
+
get problem(): unknown;
|
|
20
|
+
get meta(): unknown;
|
|
21
|
+
json(): Promise<unknown>;
|
|
22
|
+
text(): Promise<string>;
|
|
23
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
24
|
+
blob(): Promise<Blob>;
|
|
25
|
+
formData(): Promise<FormData>;
|
|
26
|
+
bytes(): Promise<Uint8Array>;
|
|
27
|
+
clone(): Response;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=FetchClientError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FetchClientError.d.ts","sourceRoot":"","sources":["../../src/src/FetchClientError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAgB,QAAQ,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC;gBAGrD,QAAQ,EAAE,mBAAmB,CAAC,OAAO,CAAC,EACtC,OAAO,CAAC,EAAE,MAAM;IAWlB,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,UAAU,IAAI,OAAO,CAExB;IAED,IAAI,IAAI,IAAI,YAAY,CAEvB;IAED,IAAI,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAE5C;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAInC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAK7B,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC;IAK5B,KAAK,IAAI,QAAQ;CAGlB"}
|
|
@@ -9,6 +9,7 @@ import { type RateLimitMiddlewareOptions } from "./RateLimitMiddleware.js";
|
|
|
9
9
|
import { type RateLimiter } from "./RateLimiter.js";
|
|
10
10
|
import { type CircuitBreakerMiddlewareOptions } from "./CircuitBreakerMiddleware.js";
|
|
11
11
|
import { type CircuitBreaker } from "./CircuitBreaker.js";
|
|
12
|
+
import { type RetryMiddlewareOptions } from "./RetryMiddleware.js";
|
|
12
13
|
type Fetch = typeof globalThis.fetch;
|
|
13
14
|
/**
|
|
14
15
|
* Represents a provider for creating instances of the FetchClient class with shared default options and cache.
|
|
@@ -127,6 +128,16 @@ export declare class FetchClientProvider {
|
|
|
127
128
|
* Removes the circuit breaker middleware from all FetchClient instances created by this provider.
|
|
128
129
|
*/
|
|
129
130
|
removeCircuitBreaker(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Enables automatic retry for failed requests.
|
|
133
|
+
* Retries are performed with exponential backoff and jitter.
|
|
134
|
+
* @param options - The retry configuration options.
|
|
135
|
+
*/
|
|
136
|
+
useRetry(options?: RetryMiddlewareOptions): void;
|
|
137
|
+
/**
|
|
138
|
+
* Removes the retry middleware from all FetchClient instances created by this provider.
|
|
139
|
+
*/
|
|
140
|
+
removeRetry(): void;
|
|
130
141
|
}
|
|
131
142
|
export declare const defaultInstance: FetchClientProvider;
|
|
132
143
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchClientProvider.d.ts","sourceRoot":"","sources":["../../src/src/FetchClientProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"FetchClientProvider.d.ts","sourceRoot":"","sources":["../../src/src/FetchClientProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,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Y,CAAC,OAAO,EAAE,kBAAkB;IAO/C;;;OAGG;IACI,kBAAkB,CAAC,eAAe,EAAE,MAAM,MAAM,GAAG,IAAI;IAO9D;;;OAGG;IACI,iBAAiB,CACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAQpE;;;OAGG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM;IAO7B;;;OAGG;IACI,aAAa,CAAC,UAAU,EAAE,qBAAqB;IAUtD;;;OAGG;IACI,YAAY,CAAC,OAAO,EAAE,0BAA0B;IAMvD;;;OAGG;IACI,qBAAqB,CAC1B,OAAO,EAAE,IAAI,CAAC,0BAA0B,EAAE,cAAc,CAAC;IAU3D;;;OAGG;IACH,IAAW,WAAW,IAAI,WAAW,GAAG,SAAS,CAEhD;IAED;;OAEG;IACI,eAAe;IAWtB;;;;;OAKG;IACI,iBAAiB,CAAC,OAAO,CAAC,EAAE,+BAA+B;IAOlE;;;;OAIG;IACI,0BAA0B,CAC/B,OAAO,CAAC,EAAE,IAAI,CAAC,+BAA+B,EAAE,cAAc,CAAC;IAWjE;;;OAGG;IACH,IAAW,cAAc,IAAI,cAAc,GAAG,SAAS,CAEtD;IAED;;OAEG;IACI,oBAAoB;IAW3B;;;;OAIG;IACI,QAAQ,CAAC,OAAO,CAAC,EAAE,sBAAsB;IAMhD;;OAEG;IACI,WAAW;CAUnB;AAGD,eAAO,MAAM,eAAe,EAAE,mBAA8B,CAAC"}
|
|
@@ -47,4 +47,31 @@ export declare class RateLimitMiddleware {
|
|
|
47
47
|
*/
|
|
48
48
|
middleware(): FetchClientMiddleware;
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a rate limit middleware with the given options.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const client = new FetchClient();
|
|
56
|
+
* client.use(createRateLimitMiddleware({
|
|
57
|
+
* maxRequests: 100,
|
|
58
|
+
* windowSeconds: 60,
|
|
59
|
+
* }));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function createRateLimitMiddleware(options: RateLimitMiddlewareOptions): FetchClientMiddleware;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a per-domain rate limit middleware where each domain is tracked separately.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const client = new FetchClient();
|
|
69
|
+
* client.use(createPerDomainRateLimitMiddleware({
|
|
70
|
+
* maxRequests: 100,
|
|
71
|
+
* windowSeconds: 60,
|
|
72
|
+
* }));
|
|
73
|
+
* // api.example.com and api.other.com will have separate rate limits
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function createPerDomainRateLimitMiddleware(options: RateLimitMiddlewareOptions): FetchClientMiddleware;
|
|
50
77
|
//# sourceMappingURL=RateLimitMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RateLimitMiddleware.d.ts","sourceRoot":"","sources":["../../src/src/RateLimitMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,
|
|
1
|
+
{"version":3,"file":"RateLimitMiddleware.d.ts","sourceRoot":"","sources":["../../src/src/RateLimitMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,EAIL,WAAW,EACX,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,iBAAiB,EAAE,MAAM,CAAC;gBAE9B,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAW3E;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;GAEG;AACH,qBAAa,mBAAmB;;IAG9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAU;gBAEpC,OAAO,EAAE,0BAA0B;IAO/C;;OAEG;IACH,IAAW,WAAW,IAAI,WAAW,CAEpC;IAED;;;OAGG;IACI,UAAU,IAAI,qBAAqB;CA8F3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,qBAAqB,CAEvB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,0BAA0B,GAClC,qBAAqB,CAKvB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { FetchClientResponse } from "./FetchClientResponse.js";
|
|
2
|
+
import type { RequestOptions } from "./RequestOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* A promise that resolves to a FetchClientResponse with additional helper methods
|
|
5
|
+
* for parsing the response body. This allows for a fluent API similar to ky:
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Await to get the full response
|
|
10
|
+
* const response = await client.get("/api/users");
|
|
11
|
+
*
|
|
12
|
+
* // Or use helper methods for direct access to parsed body
|
|
13
|
+
* const users = await client.get("/api/users").json<User[]>();
|
|
14
|
+
* const html = await client.get("/page").text();
|
|
15
|
+
* const file = await client.get("/file").blob();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class ResponsePromise<T = unknown> implements PromiseLike<FetchClientResponse<T>> {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(responsePromise: Promise<FetchClientResponse<T>>, options?: RequestOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Implements PromiseLike interface so the ResponsePromise can be awaited.
|
|
23
|
+
*/
|
|
24
|
+
then<TResult1 = FetchClientResponse<T>, TResult2 = never>(onfulfilled?: ((value: FetchClientResponse<T>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
25
|
+
/**
|
|
26
|
+
* Catches any errors from the response promise.
|
|
27
|
+
*/
|
|
28
|
+
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<FetchClientResponse<T> | TResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Executes a callback when the promise settles (fulfilled or rejected).
|
|
31
|
+
*/
|
|
32
|
+
finally(onfinally?: (() => void) | null): Promise<FetchClientResponse<T>>;
|
|
33
|
+
/**
|
|
34
|
+
* Parses the response body as JSON.
|
|
35
|
+
*
|
|
36
|
+
* If the response was already parsed as JSON (via getJSON, postJSON, etc.),
|
|
37
|
+
* returns the parsed data directly. Otherwise, parses the response body.
|
|
38
|
+
*
|
|
39
|
+
* @template TJson - The expected type of the JSON response
|
|
40
|
+
* @returns A promise that resolves to the parsed JSON
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const user = await client.get("/api/user/1").json<User>();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
json<TJson = T>(): Promise<TJson>;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the response body as text.
|
|
50
|
+
*
|
|
51
|
+
* @returns A promise that resolves to the response text
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const html = await client.get("/page").text();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
text(): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the response body as a Blob.
|
|
61
|
+
*
|
|
62
|
+
* @returns A promise that resolves to the response as a Blob
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const imageBlob = await client.get("/image.png").blob();
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
blob(): Promise<Blob>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the response body as an ArrayBuffer.
|
|
72
|
+
*
|
|
73
|
+
* @returns A promise that resolves to the response as an ArrayBuffer
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const buffer = await client.get("/file").arrayBuffer();
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
81
|
+
/**
|
|
82
|
+
* Returns the response body as FormData.
|
|
83
|
+
*
|
|
84
|
+
* @returns A promise that resolves to the response as FormData
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const formData = await client.get("/form").formData();
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
formData(): Promise<FormData>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=ResponsePromise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResponsePromise.d.ts","sourceRoot":"","sources":["../../src/src/ResponsePromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAe,CAAC,CAAC,GAAG,OAAO,CACtC,YAAW,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;;gBAK5C,eAAe,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC,C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|
2
|
+
/**
|
|
3
|
+
* Configuration options for the retry middleware.
|
|
4
|
+
*/
|
|
5
|
+
export interface RetryMiddlewareOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Maximum number of retry attempts.
|
|
8
|
+
* @default 2
|
|
9
|
+
*/
|
|
10
|
+
limit?: number;
|
|
11
|
+
/**
|
|
12
|
+
* HTTP methods eligible for retry.
|
|
13
|
+
* @default ['GET', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'TRACE']
|
|
14
|
+
*/
|
|
15
|
+
methods?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* HTTP status codes that trigger a retry.
|
|
18
|
+
* @default [408, 413, 429, 500, 502, 503, 504]
|
|
19
|
+
*/
|
|
20
|
+
statusCodes?: number[];
|
|
21
|
+
/**
|
|
22
|
+
* Maximum value of Retry-After header to respect, in milliseconds.
|
|
23
|
+
* If Retry-After exceeds this value, the request will not be retried.
|
|
24
|
+
* @default Infinity
|
|
25
|
+
*/
|
|
26
|
+
maxRetryAfter?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum backoff delay in milliseconds.
|
|
29
|
+
* @default 30000
|
|
30
|
+
*/
|
|
31
|
+
backoffLimit?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Custom delay function that receives the attempt number (0-indexed) and returns delay in ms.
|
|
34
|
+
* If not provided, exponential backoff is used: min(1000 * 2^attempt, backoffLimit)
|
|
35
|
+
*/
|
|
36
|
+
delay?: (attemptNumber: number, response?: Response) => number;
|
|
37
|
+
/**
|
|
38
|
+
* Jitter fraction for randomizing delay.
|
|
39
|
+
* For example, 0.1 means +/- 10% randomization.
|
|
40
|
+
* @default 0.1
|
|
41
|
+
*/
|
|
42
|
+
jitter?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Custom predicate to determine if a request should be retried.
|
|
45
|
+
* Called after default checks pass. Return true to retry, false to stop.
|
|
46
|
+
*/
|
|
47
|
+
shouldRetry?: (response: Response, attemptNumber: number) => boolean | Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Callback invoked before each retry attempt.
|
|
50
|
+
*/
|
|
51
|
+
onRetry?: (attemptNumber: number, response: Response, delayMs: number) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Retry middleware that automatically retries failed requests with exponential backoff.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const provider = new FetchClientProvider();
|
|
59
|
+
* provider.useRetry({
|
|
60
|
+
* limit: 3,
|
|
61
|
+
* statusCodes: [500, 502, 503, 504],
|
|
62
|
+
* jitter: 0.1,
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* const client = provider.getFetchClient();
|
|
66
|
+
* const response = await client.getJSON('/api/data');
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare class RetryMiddleware {
|
|
70
|
+
#private;
|
|
71
|
+
constructor(options?: RetryMiddlewareOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Creates the middleware function.
|
|
74
|
+
* @returns The middleware function
|
|
75
|
+
*/
|
|
76
|
+
middleware(): FetchClientMiddleware;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a retry middleware with the given options.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const client = new FetchClient();
|
|
84
|
+
* client.use(createRetryMiddleware({ limit: 3 }));
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function createRetryMiddleware(options?: RetryMiddlewareOptions): FetchClientMiddleware;
|
|
88
|
+
//# sourceMappingURL=RetryMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetryMiddleware.d.ts","sourceRoot":"","sources":["../../src/src/RetryMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AA4BxE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAEvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,MAAM,CAAC;IAE/D;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,CACZ,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,KAClB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhC;;OAEG;IACH,OAAO,CAAC,EAAE,CACR,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,KACZ,IAAI,CAAC;CACX;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,eAAe;;gBAoBd,OAAO,CAAC,EAAE,sBAAsB;IAgB5C;;;OAGG;IACI,UAAU,IAAI,qBAAqB;CAuI3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,qBAAqB,CAEvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockHistory.d.ts","sourceRoot":"","sources":["../../../src/src/mocks/MockHistory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,qBAAa,eAAgB,YAAW,WAAW;;
|
|
1
|
+
{"version":3,"file":"MockHistory.d.ts","sourceRoot":"","sources":["../../../src/src/mocks/MockHistory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,qBAAa,eAAgB,YAAW,WAAW;;IASjD,IAAI,GAAG,IAAI,OAAO,EAAE,CAEnB;IAED,IAAI,IAAI,IAAI,OAAO,EAAE,CAEpB;IAED,IAAI,IAAI,IAAI,OAAO,EAAE,CAEpB;IAED,IAAI,GAAG,IAAI,OAAO,EAAE,CAEnB;IAED,IAAI,KAAK,IAAI,OAAO,EAAE,CAErB;IAED,IAAI,MAAM,IAAI,OAAO,EAAE,CAEtB;IAED,IAAI,GAAG,IAAI,OAAO,EAAE,CAEnB;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAyB9B;;OAEG;IACH,KAAK,IAAI,IAAI;CASd"}
|
|
@@ -38,6 +38,11 @@ export declare class MockRegistry {
|
|
|
38
38
|
* @param url - URL string or RegExp to match
|
|
39
39
|
*/
|
|
40
40
|
onGet(url: string | RegExp): MockResponseBuilder<MockRegistry>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a mock for HEAD requests matching the given URL.
|
|
43
|
+
* @param url - URL string or RegExp to match
|
|
44
|
+
*/
|
|
45
|
+
onHead(url: string | RegExp): MockResponseBuilder<MockRegistry>;
|
|
41
46
|
/**
|
|
42
47
|
* Creates a mock for POST requests matching the given URL.
|
|
43
48
|
* @param url - URL string or RegExp to match
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockRegistry.d.ts","sourceRoot":"","sources":["../../../src/src/mocks/MockRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,KAA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