@musallam/ffs-cloud-storage-client 1.0.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/dist/distribution-BwPC3bzJ.cjs +3 -0
- package/dist/distribution-WitwksSh.mjs +4 -0
- package/dist/distribution-WitwksSh.mjs.map +1 -0
- package/dist/flat.cjs +7 -0
- package/dist/flat.d.cts +5419 -0
- package/dist/flat.d.cts.map +1 -0
- package/dist/flat.d.mts +5419 -0
- package/dist/flat.d.mts.map +1 -0
- package/dist/flat.mjs +8 -0
- package/dist/flat.mjs.map +1 -0
- package/dist/index-B2PznWi7.d.cts +979 -0
- package/dist/index-B2PznWi7.d.cts.map +1 -0
- package/dist/index-IOhsyoSY.d.mts +979 -0
- package/dist/index-IOhsyoSY.d.mts.map +1 -0
- package/dist/sdk.cjs +7 -0
- package/dist/sdk.d.cts +5438 -0
- package/dist/sdk.d.cts.map +1 -0
- package/dist/sdk.d.mts +5438 -0
- package/dist/sdk.d.mts.map +1 -0
- package/dist/sdk.mjs +8 -0
- package/dist/sdk.mjs.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,979 @@
|
|
|
1
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/common.d.ts
|
|
2
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
3
|
+
type LiteralUnion<LiteralType extends BaseType, BaseType extends Primitive> = LiteralType | (BaseType & {
|
|
4
|
+
_?: never;
|
|
5
|
+
});
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/hooks.d.ts
|
|
8
|
+
type BeforeRequestState = {
|
|
9
|
+
/**
|
|
10
|
+
The number of retries attempted. `0` for the initial request, increments with each retry.
|
|
11
|
+
This allows you to distinguish between initial requests and retries, which is useful when you need different behavior for retries (e.g., avoiding overwriting headers set in `beforeRetry`).
|
|
12
|
+
*/
|
|
13
|
+
retryCount: number;
|
|
14
|
+
};
|
|
15
|
+
type BeforeRequestHook = (request: KyRequest, options: NormalizedOptions, state: BeforeRequestState) => Request | Response | void | Promise<Request | Response | void>;
|
|
16
|
+
type BeforeRetryState = {
|
|
17
|
+
request: KyRequest;
|
|
18
|
+
options: NormalizedOptions;
|
|
19
|
+
error: Error;
|
|
20
|
+
/**
|
|
21
|
+
The number of retries attempted. Always `>= 1` since this hook is only called during retries, not on the initial request.
|
|
22
|
+
*/
|
|
23
|
+
retryCount: number;
|
|
24
|
+
};
|
|
25
|
+
type BeforeRetryHook = (options: BeforeRetryState) => Request | Response | typeof stop | void | Promise<Request | Response | typeof stop | void>;
|
|
26
|
+
type AfterResponseState = {
|
|
27
|
+
/**
|
|
28
|
+
The number of retries attempted. `0` for the initial request, increments with each retry.
|
|
29
|
+
This allows you to distinguish between initial requests and retries, which is useful when you need different behavior for retries (e.g., showing a notification only on the final retry).
|
|
30
|
+
*/
|
|
31
|
+
retryCount: number;
|
|
32
|
+
};
|
|
33
|
+
type AfterResponseHook = (request: KyRequest, options: NormalizedOptions, response: KyResponse, state: AfterResponseState) => Response | RetryMarker | void | Promise<Response | RetryMarker | void>;
|
|
34
|
+
type BeforeErrorState = {
|
|
35
|
+
/**
|
|
36
|
+
The number of retries attempted. `0` for the initial request, increments with each retry.
|
|
37
|
+
This allows you to distinguish between the initial request and retries, which is useful when you need different error handling based on retry attempts (e.g., showing different error messages on the final attempt).
|
|
38
|
+
*/
|
|
39
|
+
retryCount: number;
|
|
40
|
+
};
|
|
41
|
+
type BeforeErrorHook = (error: HTTPError, state: BeforeErrorState) => HTTPError | Promise<HTTPError>;
|
|
42
|
+
type Hooks = {
|
|
43
|
+
/**
|
|
44
|
+
This hook enables you to modify the request right before it is sent. Ky will make no further changes to the request after this. The hook function receives the normalized request, options, and a state object. You could, for example, modify `request.headers` here.
|
|
45
|
+
The `state.retryCount` is `0` for the initial request and increments with each retry. This allows you to distinguish between initial requests and retries, which is useful when you need different behavior for retries (e.g., avoiding overwriting headers set in `beforeRetry`).
|
|
46
|
+
A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) can be returned from this hook to completely avoid making an HTTP request. This can be used to mock a request, check an internal cache, etc. An **important** consideration when returning a `Response` from this hook is that all the following hooks will be skipped, so **ensure you only return a `Response` from the last hook**.
|
|
47
|
+
@example
|
|
48
|
+
```
|
|
49
|
+
import ky from 'ky';
|
|
50
|
+
const response = await ky('https://example.com', {
|
|
51
|
+
hooks: {
|
|
52
|
+
beforeRequest: [
|
|
53
|
+
(request, options, {retryCount}) => {
|
|
54
|
+
// Only set default auth header on initial request, not on retries
|
|
55
|
+
// (retries may have refreshed token set by beforeRetry)
|
|
56
|
+
if (retryCount === 0) {
|
|
57
|
+
request.headers.set('Authorization', 'token initial-token');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
@default []
|
|
65
|
+
*/
|
|
66
|
+
beforeRequest?: BeforeRequestHook[];
|
|
67
|
+
/**
|
|
68
|
+
This hook enables you to modify the request right before retry. Ky will make no further changes to the request after this. The hook function receives an object with the normalized request and options, an error instance, and the retry count. You could, for example, modify `request.headers` here.
|
|
69
|
+
The hook can return a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) to replace the outgoing retry request, or return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) to skip the retry and use that response instead. **Note:** Returning a request or response skips remaining `beforeRetry` hooks.
|
|
70
|
+
If the request received a response, the error will be of type `HTTPError` and the `Response` object will be available at `error.response`. Be aware that some types of errors, such as network errors, inherently mean that a response was not received. In that case, the error will not be an instance of `HTTPError`.
|
|
71
|
+
You can prevent Ky from retrying the request by throwing an error. Ky will not handle it in any way and the error will be propagated to the request initiator. The rest of the `beforeRetry` hooks will not be called in this case. Alternatively, you can return the [`ky.stop`](#ky.stop) symbol to do the same thing but without propagating an error (this has some limitations, see `ky.stop` docs for details).
|
|
72
|
+
**Modifying headers:**
|
|
73
|
+
@example
|
|
74
|
+
```
|
|
75
|
+
import ky from 'ky';
|
|
76
|
+
const response = await ky('https://example.com', {
|
|
77
|
+
hooks: {
|
|
78
|
+
beforeRetry: [
|
|
79
|
+
async ({request, options, error, retryCount}) => {
|
|
80
|
+
const token = await ky('https://example.com/refresh-token');
|
|
81
|
+
request.headers.set('Authorization', `token ${token}`);
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
**Modifying the request URL:**
|
|
88
|
+
@example
|
|
89
|
+
```
|
|
90
|
+
import ky from 'ky';
|
|
91
|
+
const response = await ky('https://example.com/api', {
|
|
92
|
+
hooks: {
|
|
93
|
+
beforeRetry: [
|
|
94
|
+
async ({request, error}) => {
|
|
95
|
+
// Add query parameters based on error response
|
|
96
|
+
if (error.response) {
|
|
97
|
+
const body = await error.response.json();
|
|
98
|
+
const url = new URL(request.url);
|
|
99
|
+
url.searchParams.set('processId', body.processId);
|
|
100
|
+
return new Request(url, request);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
**Returning a cached response:**
|
|
108
|
+
@example
|
|
109
|
+
```
|
|
110
|
+
import ky from 'ky';
|
|
111
|
+
const response = await ky('https://example.com/api', {
|
|
112
|
+
hooks: {
|
|
113
|
+
beforeRetry: [
|
|
114
|
+
({error, retryCount}) => {
|
|
115
|
+
// Use cached response instead of retrying
|
|
116
|
+
if (retryCount > 1 && cachedResponse) {
|
|
117
|
+
return cachedResponse;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
@default []
|
|
125
|
+
*/
|
|
126
|
+
beforeRetry?: BeforeRetryHook[];
|
|
127
|
+
/**
|
|
128
|
+
This hook enables you to read and optionally modify the response. The hook function receives normalized request, options, a clone of the response, and a state object. The return value of the hook function will be used by Ky as the response object if it's an instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
|
|
129
|
+
You can also force a retry by returning `ky.retry()` or `ky.retry(options)`. This is useful when you need to retry based on the response body content, even if the response has a successful status code. The retry will respect the retry limit and be observable in `beforeRetry` hooks.
|
|
130
|
+
@default []
|
|
131
|
+
@example
|
|
132
|
+
```
|
|
133
|
+
import ky from 'ky';
|
|
134
|
+
const response = await ky('https://example.com', {
|
|
135
|
+
hooks: {
|
|
136
|
+
afterResponse: [
|
|
137
|
+
(_request, _options, response) => {
|
|
138
|
+
// You could do something with the response, for example, logging.
|
|
139
|
+
log(response);
|
|
140
|
+
// Or return a `Response` instance to overwrite the response.
|
|
141
|
+
return new Response('A different response', {status: 200});
|
|
142
|
+
},
|
|
143
|
+
// Or retry with a fresh token on a 401 error
|
|
144
|
+
async (request, _options, response, state) => {
|
|
145
|
+
if (response.status === 401 && state.retryCount === 0) {
|
|
146
|
+
// Only refresh on first 401, not on subsequent retries
|
|
147
|
+
const {token} = await ky.post('https://example.com/auth/refresh').json();
|
|
148
|
+
const headers = new Headers(request.headers);
|
|
149
|
+
headers.set('Authorization', `Bearer ${token}`);
|
|
150
|
+
return ky.retry({
|
|
151
|
+
request: new Request(request, {headers}),
|
|
152
|
+
code: 'TOKEN_REFRESHED'
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
// Or force retry based on response body content
|
|
157
|
+
async (request, options, response) => {
|
|
158
|
+
if (response.status === 200) {
|
|
159
|
+
const data = await response.clone().json();
|
|
160
|
+
if (data.error?.code === 'RATE_LIMIT') {
|
|
161
|
+
// Force retry with custom delay from API response
|
|
162
|
+
return ky.retry({
|
|
163
|
+
delay: data.error.retryAfter * 1000,
|
|
164
|
+
code: 'RATE_LIMIT'
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
// Or show a notification only on the last retry for 5xx errors
|
|
170
|
+
(request, options, response, {retryCount}) => {
|
|
171
|
+
if (response.status >= 500 && response.status <= 599) {
|
|
172
|
+
if (retryCount === options.retry.limit) {
|
|
173
|
+
showNotification('Request failed after all retries');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
*/
|
|
182
|
+
afterResponse?: AfterResponseHook[];
|
|
183
|
+
/**
|
|
184
|
+
This hook enables you to modify the `HTTPError` right before it is thrown. The hook function receives an `HTTPError` and a state object as arguments and should return an instance of `HTTPError`.
|
|
185
|
+
@default []
|
|
186
|
+
@example
|
|
187
|
+
```
|
|
188
|
+
import ky from 'ky';
|
|
189
|
+
await ky('https://example.com', {
|
|
190
|
+
hooks: {
|
|
191
|
+
beforeError: [
|
|
192
|
+
async error => {
|
|
193
|
+
const {response} = error;
|
|
194
|
+
if (response) {
|
|
195
|
+
const body = await response.json();
|
|
196
|
+
error.name = 'GitHubError';
|
|
197
|
+
error.message = `${body.message} (${response.status})`;
|
|
198
|
+
}
|
|
199
|
+
return error;
|
|
200
|
+
},
|
|
201
|
+
// Or show different message based on retry count
|
|
202
|
+
(error, {retryCount}) => {
|
|
203
|
+
if (retryCount === error.options.retry.limit) {
|
|
204
|
+
error.message = `${error.message} (failed after ${retryCount} retries)`;
|
|
205
|
+
}
|
|
206
|
+
return error;
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
*/
|
|
213
|
+
beforeError?: BeforeErrorHook[];
|
|
214
|
+
};
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/retry.d.ts
|
|
217
|
+
type ShouldRetryState = {
|
|
218
|
+
/**
|
|
219
|
+
The error that caused the request to fail.
|
|
220
|
+
*/
|
|
221
|
+
error: Error;
|
|
222
|
+
/**
|
|
223
|
+
The number of retries attempted. Starts at 1 for the first retry.
|
|
224
|
+
*/
|
|
225
|
+
retryCount: number;
|
|
226
|
+
};
|
|
227
|
+
type RetryOptions = {
|
|
228
|
+
/**
|
|
229
|
+
The number of times to retry failed requests.
|
|
230
|
+
@default 2
|
|
231
|
+
*/
|
|
232
|
+
limit?: number;
|
|
233
|
+
/**
|
|
234
|
+
The HTTP methods allowed to retry.
|
|
235
|
+
@default ['get', 'put', 'head', 'delete', 'options', 'trace']
|
|
236
|
+
*/
|
|
237
|
+
methods?: HttpMethod[];
|
|
238
|
+
/**
|
|
239
|
+
The HTTP status codes allowed to retry.
|
|
240
|
+
@default [408, 413, 429, 500, 502, 503, 504]
|
|
241
|
+
*/
|
|
242
|
+
statusCodes?: number[];
|
|
243
|
+
/**
|
|
244
|
+
The HTTP status codes allowed to retry with a `Retry-After` header.
|
|
245
|
+
@default [413, 429, 503]
|
|
246
|
+
*/
|
|
247
|
+
afterStatusCodes?: number[];
|
|
248
|
+
/**
|
|
249
|
+
If the `Retry-After` header is greater than `maxRetryAfter`, the request will be canceled.
|
|
250
|
+
@default Infinity
|
|
251
|
+
*/
|
|
252
|
+
maxRetryAfter?: number;
|
|
253
|
+
/**
|
|
254
|
+
The upper limit of the delay per retry in milliseconds.
|
|
255
|
+
To clamp the delay, set `backoffLimit` to 1000, for example.
|
|
256
|
+
By default, the delay is calculated in the following way:
|
|
257
|
+
```
|
|
258
|
+
0.3 * (2 ** (attemptCount - 1)) * 1000
|
|
259
|
+
```
|
|
260
|
+
The delay increases exponentially.
|
|
261
|
+
@default Infinity
|
|
262
|
+
*/
|
|
263
|
+
backoffLimit?: number;
|
|
264
|
+
/**
|
|
265
|
+
A function to calculate the delay between retries given `attemptCount` (starts from 1).
|
|
266
|
+
@default attemptCount => 0.3 * (2 ** (attemptCount - 1)) * 1000
|
|
267
|
+
*/
|
|
268
|
+
delay?: (attemptCount: number) => number;
|
|
269
|
+
/**
|
|
270
|
+
Add random jitter to retry delays to prevent thundering herd problems.
|
|
271
|
+
When many clients retry simultaneously (e.g., after hitting a rate limit), they can overwhelm the server again. Jitter adds randomness to break this synchronization.
|
|
272
|
+
Set to `true` to use full jitter, which randomizes the delay between 0 and the computed delay.
|
|
273
|
+
Alternatively, pass a function to implement custom jitter strategies.
|
|
274
|
+
@default undefined (no jitter)
|
|
275
|
+
@example
|
|
276
|
+
```
|
|
277
|
+
import ky from 'ky';
|
|
278
|
+
const json = await ky('https://example.com', {
|
|
279
|
+
retry: {
|
|
280
|
+
limit: 5,
|
|
281
|
+
// Full jitter (randomizes delay between 0 and computed value)
|
|
282
|
+
jitter: true
|
|
283
|
+
// Percentage jitter (80-120% of delay)
|
|
284
|
+
// jitter: delay => delay * (0.8 + Math.random() * 0.4)
|
|
285
|
+
// Absolute jitter (±100ms)
|
|
286
|
+
// jitter: delay => delay + (Math.random() * 200 - 100)
|
|
287
|
+
}
|
|
288
|
+
}).json();
|
|
289
|
+
```
|
|
290
|
+
*/
|
|
291
|
+
jitter?: boolean | ((delay: number) => number) | undefined;
|
|
292
|
+
/**
|
|
293
|
+
Whether to retry when the request times out.
|
|
294
|
+
@default false
|
|
295
|
+
@example
|
|
296
|
+
```
|
|
297
|
+
import ky from 'ky';
|
|
298
|
+
const json = await ky('https://example.com', {
|
|
299
|
+
retry: {
|
|
300
|
+
limit: 3,
|
|
301
|
+
retryOnTimeout: true
|
|
302
|
+
}
|
|
303
|
+
}).json();
|
|
304
|
+
```
|
|
305
|
+
*/
|
|
306
|
+
retryOnTimeout?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
A function to determine whether a retry should be attempted.
|
|
309
|
+
This function takes precedence over all other retry checks and is called first, before any other retry validation.
|
|
310
|
+
**Note:** This is different from the `beforeRetry` hook:
|
|
311
|
+
- `shouldRetry`: Controls WHETHER to retry (called before the retry decision is made)
|
|
312
|
+
- `beforeRetry`: Called AFTER retry is confirmed, allowing you to modify the request
|
|
313
|
+
Should return:
|
|
314
|
+
- `true` to force a retry (bypasses `retryOnTimeout`, status code checks, and other validations)
|
|
315
|
+
- `false` to prevent a retry (no retry will occur)
|
|
316
|
+
- `undefined` to use the default retry logic (`retryOnTimeout`, status codes, etc.)
|
|
317
|
+
@example
|
|
318
|
+
```
|
|
319
|
+
import ky, {HTTPError} from 'ky';
|
|
320
|
+
const json = await ky('https://example.com', {
|
|
321
|
+
retry: {
|
|
322
|
+
limit: 3,
|
|
323
|
+
shouldRetry: ({error, retryCount}) => {
|
|
324
|
+
// Retry on specific business logic errors from API
|
|
325
|
+
if (error instanceof HTTPError) {
|
|
326
|
+
const status = error.response.status;
|
|
327
|
+
// Retry on 429 (rate limit) but only for first 2 attempts
|
|
328
|
+
if (status === 429 && retryCount <= 2) {
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
// Don't retry on 4xx errors except rate limits
|
|
332
|
+
if (status >= 400 && status < 500) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
// Use default retry logic for other errors
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}).json();
|
|
341
|
+
```
|
|
342
|
+
*/
|
|
343
|
+
shouldRetry?: (state: ShouldRetryState) => boolean | undefined | Promise<boolean | undefined>;
|
|
344
|
+
};
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/options.d.ts
|
|
347
|
+
type SearchParamsInit = string | string[][] | Record<string, string> | URLSearchParams | undefined;
|
|
348
|
+
type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean | undefined> | Array<Array<string | number | boolean>>;
|
|
349
|
+
type RequestHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
|
|
350
|
+
type HttpMethod = LiteralUnion<RequestHttpMethod | 'options' | 'trace', string>;
|
|
351
|
+
type Input = string | URL | Request;
|
|
352
|
+
type Progress = {
|
|
353
|
+
percent: number;
|
|
354
|
+
transferredBytes: number;
|
|
355
|
+
/**
|
|
356
|
+
Note: If it's not possible to retrieve the body size, it will be `0`.
|
|
357
|
+
*/
|
|
358
|
+
totalBytes: number;
|
|
359
|
+
};
|
|
360
|
+
type KyHeadersInit = NonNullable<RequestInit['headers']> | Record<string, string | undefined>;
|
|
361
|
+
/**
|
|
362
|
+
Custom Ky options
|
|
363
|
+
*/
|
|
364
|
+
type KyOptions = {
|
|
365
|
+
/**
|
|
366
|
+
Shortcut for sending JSON. Use this instead of the `body` option.
|
|
367
|
+
Accepts any plain object or value, which will be `JSON.stringify()`'d and sent in the body with the correct header set.
|
|
368
|
+
*/
|
|
369
|
+
json?: unknown;
|
|
370
|
+
/**
|
|
371
|
+
User-defined JSON-parsing function.
|
|
372
|
+
Use-cases:
|
|
373
|
+
1. Parse JSON via the [`bourne` package](https://github.com/hapijs/bourne) to protect from prototype pollution.
|
|
374
|
+
2. Parse JSON with [`reviver` option of `JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
|
|
375
|
+
@default JSON.parse()
|
|
376
|
+
@example
|
|
377
|
+
```
|
|
378
|
+
import ky from 'ky';
|
|
379
|
+
import bourne from '@hapijs/bourne';
|
|
380
|
+
const json = await ky('https://example.com', {
|
|
381
|
+
parseJson: text => bourne(text)
|
|
382
|
+
}).json();
|
|
383
|
+
```
|
|
384
|
+
*/
|
|
385
|
+
parseJson?: (text: string) => unknown;
|
|
386
|
+
/**
|
|
387
|
+
User-defined JSON-stringifying function.
|
|
388
|
+
Use-cases:
|
|
389
|
+
1. Stringify JSON with a custom `replacer` function.
|
|
390
|
+
@default JSON.stringify()
|
|
391
|
+
@example
|
|
392
|
+
```
|
|
393
|
+
import ky from 'ky';
|
|
394
|
+
import {DateTime} from 'luxon';
|
|
395
|
+
const json = await ky('https://example.com', {
|
|
396
|
+
stringifyJson: data => JSON.stringify(data, (key, value) => {
|
|
397
|
+
if (key.endsWith('_at')) {
|
|
398
|
+
return DateTime.fromISO(value).toSeconds();
|
|
399
|
+
}
|
|
400
|
+
return value;
|
|
401
|
+
})
|
|
402
|
+
}).json();
|
|
403
|
+
```
|
|
404
|
+
*/
|
|
405
|
+
stringifyJson?: (data: unknown) => string;
|
|
406
|
+
/**
|
|
407
|
+
Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.
|
|
408
|
+
Accepts any value supported by [`URLSearchParams()`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams).
|
|
409
|
+
When passing an object, `undefined` values are automatically filtered out, while `null` values are preserved and converted to the string `'null'`.
|
|
410
|
+
*/
|
|
411
|
+
searchParams?: SearchParamsOption;
|
|
412
|
+
/**
|
|
413
|
+
A prefix to prepend to the `input` URL when making the request. It can be any valid URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string. The `input` argument cannot start with a slash `/` when using this option.
|
|
414
|
+
Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.
|
|
415
|
+
Notes:
|
|
416
|
+
- After `prefixUrl` and `input` are joined, the result is resolved against the [base URL](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) of the page (if any).
|
|
417
|
+
- Leading slashes in `input` are disallowed when using this option to enforce consistency and avoid confusion about how the `input` URL is handled, given that `input` will not follow the normal URL resolution rules when `prefixUrl` is being used, which changes the meaning of a leading slash.
|
|
418
|
+
@example
|
|
419
|
+
```
|
|
420
|
+
import ky from 'ky';
|
|
421
|
+
// On https://example.com
|
|
422
|
+
const response = await ky('unicorn', {prefixUrl: '/api'});
|
|
423
|
+
//=> 'https://example.com/api/unicorn'
|
|
424
|
+
const response = await ky('unicorn', {prefixUrl: 'https://cats.com'});
|
|
425
|
+
//=> 'https://cats.com/unicorn'
|
|
426
|
+
```
|
|
427
|
+
*/
|
|
428
|
+
prefixUrl?: URL | string;
|
|
429
|
+
/**
|
|
430
|
+
An object representing `limit`, `methods`, `statusCodes`, `afterStatusCodes`, and `maxRetryAfter` fields for maximum retry count, allowed methods, allowed status codes, status codes allowed to use the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time, and maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time.
|
|
431
|
+
If `retry` is a number, it will be used as `limit` and other defaults will remain in place.
|
|
432
|
+
If the response provides an HTTP status contained in `afterStatusCodes`, Ky will wait until the date or timeout given in the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header has passed to retry the request. If `Retry-After` is missing, the non-standard [`RateLimit-Reset`](https://www.ietf.org/archive/id/draft-polli-ratelimit-headers-02.html#section-3.3) header is used in its place as a fallback. If the provided status code is not in the list, the [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header will be ignored.
|
|
433
|
+
If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`. If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.
|
|
434
|
+
By default, delays between retries are calculated with the function `0.3 * (2 ** (attemptCount - 1)) * 1000`, where `attemptCount` is the attempt number (starts from 1), however this can be changed by passing a `delay` function.
|
|
435
|
+
Retries are not triggered following a timeout.
|
|
436
|
+
@example
|
|
437
|
+
```
|
|
438
|
+
import ky from 'ky';
|
|
439
|
+
const json = await ky('https://example.com', {
|
|
440
|
+
retry: {
|
|
441
|
+
limit: 10,
|
|
442
|
+
methods: ['get'],
|
|
443
|
+
statusCodes: [413]
|
|
444
|
+
}
|
|
445
|
+
}).json();
|
|
446
|
+
```
|
|
447
|
+
*/
|
|
448
|
+
retry?: RetryOptions | number;
|
|
449
|
+
/**
|
|
450
|
+
Timeout in milliseconds for getting a response, including any retries. Can not be greater than 2147483647.
|
|
451
|
+
If set to `false`, there will be no timeout.
|
|
452
|
+
@default 10000
|
|
453
|
+
*/
|
|
454
|
+
timeout?: number | false;
|
|
455
|
+
/**
|
|
456
|
+
Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.
|
|
457
|
+
*/
|
|
458
|
+
hooks?: Hooks;
|
|
459
|
+
/**
|
|
460
|
+
Throw an `HTTPError` when, after following redirects, the response has a non-2xx status code. To also throw for redirects instead of following them, set the [`redirect`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) option to `'manual'`.
|
|
461
|
+
Setting this to `false` may be useful if you are checking for resource availability and are expecting error responses.
|
|
462
|
+
You can also pass a function that accepts the HTTP status code and returns a boolean for selective error handling. Note that this can violate the principle of least surprise, so it's recommended to use the boolean form unless you have a specific use case like treating 404 responses differently.
|
|
463
|
+
Note: If `false`, error responses are considered successful and the request will not be retried.
|
|
464
|
+
@default true
|
|
465
|
+
*/
|
|
466
|
+
throwHttpErrors?: boolean | ((status: number) => boolean);
|
|
467
|
+
/**
|
|
468
|
+
Download progress event handler.
|
|
469
|
+
@param progress - Object containing download progress information.
|
|
470
|
+
@param chunk - Data that was received. Note: It's empty for the first call.
|
|
471
|
+
@example
|
|
472
|
+
```
|
|
473
|
+
import ky from 'ky';
|
|
474
|
+
const response = await ky('https://example.com', {
|
|
475
|
+
onDownloadProgress: (progress, chunk) => {
|
|
476
|
+
// Example output:
|
|
477
|
+
// `0% - 0 of 1271 bytes`
|
|
478
|
+
// `100% - 1271 of 1271 bytes`
|
|
479
|
+
console.log(`${progress.percent * 100}% - ${progress.transferredBytes} of ${progress.totalBytes} bytes`);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
```
|
|
483
|
+
*/
|
|
484
|
+
onDownloadProgress?: (progress: Progress, chunk: Uint8Array) => void;
|
|
485
|
+
/**
|
|
486
|
+
Upload progress event handler.
|
|
487
|
+
@param progress - Object containing upload progress information.
|
|
488
|
+
@param chunk - Data that was sent. Note: It's empty for the last call.
|
|
489
|
+
@example
|
|
490
|
+
```
|
|
491
|
+
import ky from 'ky';
|
|
492
|
+
const response = await ky.post('https://example.com/upload', {
|
|
493
|
+
body: largeFile,
|
|
494
|
+
onUploadProgress: (progress, chunk) => {
|
|
495
|
+
// Example output:
|
|
496
|
+
// `0% - 0 of 1271 bytes`
|
|
497
|
+
// `100% - 1271 of 1271 bytes`
|
|
498
|
+
console.log(`${progress.percent * 100}% - ${progress.transferredBytes} of ${progress.totalBytes} bytes`);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
```
|
|
502
|
+
*/
|
|
503
|
+
onUploadProgress?: (progress: Progress, chunk: Uint8Array) => void;
|
|
504
|
+
/**
|
|
505
|
+
User-defined `fetch` function.
|
|
506
|
+
Has to be fully compatible with the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) standard.
|
|
507
|
+
Use-cases:
|
|
508
|
+
1. Use custom `fetch` implementations like [`isomorphic-unfetch`](https://www.npmjs.com/package/isomorphic-unfetch).
|
|
509
|
+
2. Use the `fetch` wrapper function provided by some frameworks that use server-side rendering (SSR).
|
|
510
|
+
@default fetch
|
|
511
|
+
@example
|
|
512
|
+
```
|
|
513
|
+
import ky from 'ky';
|
|
514
|
+
import fetch from 'isomorphic-unfetch';
|
|
515
|
+
const json = await ky('https://example.com', {fetch}).json();
|
|
516
|
+
```
|
|
517
|
+
*/
|
|
518
|
+
fetch?: (input: Input, init?: RequestInit) => Promise<Response>;
|
|
519
|
+
/**
|
|
520
|
+
User-defined data passed to hooks.
|
|
521
|
+
This option allows you to pass arbitrary contextual data to hooks without polluting the request itself. The context is available in all hooks and is **guaranteed to always be an object** (never `undefined`), so you can safely access properties without optional chaining.
|
|
522
|
+
Use cases:
|
|
523
|
+
- Pass authentication tokens or API keys to hooks
|
|
524
|
+
- Attach request metadata for logging or debugging
|
|
525
|
+
- Implement conditional logic in hooks based on the request context
|
|
526
|
+
- Pass serverless environment bindings (e.g., Cloudflare Workers)
|
|
527
|
+
**Note:** Context is shallow merged. Top-level properties are merged, but nested objects are replaced. Only enumerable properties are copied.
|
|
528
|
+
@example
|
|
529
|
+
```
|
|
530
|
+
import ky from 'ky';
|
|
531
|
+
// Pass data to hooks
|
|
532
|
+
const api = ky.create({
|
|
533
|
+
hooks: {
|
|
534
|
+
beforeRequest: [
|
|
535
|
+
(request, options) => {
|
|
536
|
+
const {token} = options.context;
|
|
537
|
+
if (token) {
|
|
538
|
+
request.headers.set('Authorization', `Bearer ${token}`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
]
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
await api('https://example.com', {
|
|
545
|
+
context: {
|
|
546
|
+
token: 'secret123'
|
|
547
|
+
}
|
|
548
|
+
}).json();
|
|
549
|
+
// Shallow merge: only top-level properties are merged
|
|
550
|
+
const instance = ky.create({
|
|
551
|
+
context: {
|
|
552
|
+
a: 1,
|
|
553
|
+
b: {
|
|
554
|
+
nested: true
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
const extended = instance.extend({
|
|
559
|
+
context: {
|
|
560
|
+
b: {
|
|
561
|
+
updated: true
|
|
562
|
+
},
|
|
563
|
+
c: 3
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
// Result: {a: 1, b: {updated: true}, c: 3}
|
|
567
|
+
// Note: The original `b.nested` is gone (shallow merge)
|
|
568
|
+
```
|
|
569
|
+
*/
|
|
570
|
+
context?: Record<string, unknown>;
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
Options are the same as `window.fetch`, except for the KyOptions
|
|
574
|
+
*/
|
|
575
|
+
interface Options extends KyOptions, Omit<RequestInit, 'headers'> {
|
|
576
|
+
/**
|
|
577
|
+
HTTP method used to make the request.
|
|
578
|
+
Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
|
|
579
|
+
*/
|
|
580
|
+
method?: LiteralUnion<HttpMethod, string>;
|
|
581
|
+
/**
|
|
582
|
+
HTTP headers used to make the request.
|
|
583
|
+
You can pass a `Headers` instance or a plain object.
|
|
584
|
+
You can remove a header with `.extend()` by passing the header with an `undefined` value.
|
|
585
|
+
@example
|
|
586
|
+
```
|
|
587
|
+
import ky from 'ky';
|
|
588
|
+
const url = 'https://sindresorhus.com';
|
|
589
|
+
const original = ky.create({
|
|
590
|
+
headers: {
|
|
591
|
+
rainbow: 'rainbow',
|
|
592
|
+
unicorn: 'unicorn'
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
const extended = original.extend({
|
|
596
|
+
headers: {
|
|
597
|
+
rainbow: undefined
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
const response = await extended(url).json();
|
|
601
|
+
console.log('rainbow' in response);
|
|
602
|
+
//=> false
|
|
603
|
+
console.log('unicorn' in response);
|
|
604
|
+
//=> true
|
|
605
|
+
```
|
|
606
|
+
*/
|
|
607
|
+
headers?: KyHeadersInit;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
Normalized options passed to the `fetch` call and the `beforeRequest` hooks.
|
|
611
|
+
*/
|
|
612
|
+
interface NormalizedOptions extends RequestInit {
|
|
613
|
+
method: NonNullable<RequestInit['method']>;
|
|
614
|
+
credentials?: NonNullable<RequestInit['credentials']>;
|
|
615
|
+
retry: RetryOptions;
|
|
616
|
+
prefixUrl: string;
|
|
617
|
+
onDownloadProgress: Options['onDownloadProgress'];
|
|
618
|
+
onUploadProgress: Options['onUploadProgress'];
|
|
619
|
+
context: Record<string, unknown>;
|
|
620
|
+
}
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/core/constants.d.ts
|
|
623
|
+
declare const stop: unique symbol;
|
|
624
|
+
/**
|
|
625
|
+
Options for forcing a retry via `ky.retry()`.
|
|
626
|
+
*/
|
|
627
|
+
type ForceRetryOptions = {
|
|
628
|
+
/**
|
|
629
|
+
Custom delay in milliseconds before retrying.
|
|
630
|
+
If not provided, uses the default retry delay calculation based on `retry.delay` configuration.
|
|
631
|
+
**Note:** Custom delays bypass jitter and `backoffLimit`. This is intentional, as custom delays often come from server responses (e.g., `Retry-After` headers) and should be respected exactly as specified.
|
|
632
|
+
*/
|
|
633
|
+
delay?: number;
|
|
634
|
+
/**
|
|
635
|
+
Error code for the retry.
|
|
636
|
+
This machine-readable identifier will be included in the error message passed to `beforeRetry` hooks, allowing you to distinguish between different types of forced retries.
|
|
637
|
+
@example
|
|
638
|
+
```
|
|
639
|
+
return ky.retry({code: 'RATE_LIMIT'});
|
|
640
|
+
// Resulting error message: 'Forced retry: RATE_LIMIT'
|
|
641
|
+
```
|
|
642
|
+
*/
|
|
643
|
+
code?: string;
|
|
644
|
+
/**
|
|
645
|
+
Original error that caused the retry.
|
|
646
|
+
This allows you to preserve the error chain when forcing a retry based on caught exceptions. The error will be set as the `cause` of the `ForceRetryError`, enabling proper error chain traversal.
|
|
647
|
+
@example
|
|
648
|
+
```
|
|
649
|
+
try {
|
|
650
|
+
const data = await response.clone().json();
|
|
651
|
+
validateBusinessLogic(data);
|
|
652
|
+
} catch (error) {
|
|
653
|
+
return ky.retry({
|
|
654
|
+
code: 'VALIDATION_FAILED',
|
|
655
|
+
cause: error // Preserves original error in chain
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
```
|
|
659
|
+
*/
|
|
660
|
+
cause?: Error;
|
|
661
|
+
/**
|
|
662
|
+
Custom request to use for the retry.
|
|
663
|
+
This allows you to modify or completely replace the request during a forced retry. The custom request becomes the starting point for the retry - `beforeRetry` hooks can still further modify it if needed.
|
|
664
|
+
**Note:** The custom request's `signal` will be replaced with Ky's managed signal to handle timeouts and user-provided abort signals correctly. If the original request body has been consumed, you must provide a new body or clone the request before consuming.
|
|
665
|
+
@example
|
|
666
|
+
```
|
|
667
|
+
// Fallback to a different endpoint
|
|
668
|
+
return ky.retry({
|
|
669
|
+
request: new Request('https://backup-api.com/endpoint', {
|
|
670
|
+
method: request.method,
|
|
671
|
+
headers: request.headers,
|
|
672
|
+
}),
|
|
673
|
+
code: 'BACKUP_ENDPOINT'
|
|
674
|
+
});
|
|
675
|
+
// Retry with refreshed authentication token
|
|
676
|
+
const data = await response.clone().json();
|
|
677
|
+
return ky.retry({
|
|
678
|
+
request: new Request(request, {
|
|
679
|
+
headers: {
|
|
680
|
+
...Object.fromEntries(request.headers),
|
|
681
|
+
'Authorization': `Bearer ${data.newToken}`
|
|
682
|
+
}
|
|
683
|
+
}),
|
|
684
|
+
code: 'TOKEN_REFRESHED'
|
|
685
|
+
});
|
|
686
|
+
```
|
|
687
|
+
*/
|
|
688
|
+
request?: Request;
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
Marker returned by ky.retry() to signal a forced retry from afterResponse hooks.
|
|
692
|
+
*/
|
|
693
|
+
declare class RetryMarker {
|
|
694
|
+
options?: ForceRetryOptions | undefined;
|
|
695
|
+
constructor(options?: ForceRetryOptions | undefined);
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
Force a retry from an `afterResponse` hook.
|
|
699
|
+
|
|
700
|
+
This allows you to retry a request based on the response content, even if the response has a successful status code. The retry will respect the `retry.limit` option and skip the `shouldRetry` check. The forced retry is observable in `beforeRetry` hooks, where the error will be a `ForceRetryError`.
|
|
701
|
+
|
|
702
|
+
@param options - Optional configuration for the retry.
|
|
703
|
+
|
|
704
|
+
@example
|
|
705
|
+
```
|
|
706
|
+
import ky, {isForceRetryError} from 'ky';
|
|
707
|
+
|
|
708
|
+
const api = ky.extend({
|
|
709
|
+
hooks: {
|
|
710
|
+
afterResponse: [
|
|
711
|
+
async (request, options, response) => {
|
|
712
|
+
// Retry based on response body content
|
|
713
|
+
if (response.status === 200) {
|
|
714
|
+
const data = await response.clone().json();
|
|
715
|
+
|
|
716
|
+
// Simple retry with default delay
|
|
717
|
+
if (data.error?.code === 'TEMPORARY_ERROR') {
|
|
718
|
+
return ky.retry();
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// Retry with custom delay from API response
|
|
722
|
+
if (data.error?.code === 'RATE_LIMIT') {
|
|
723
|
+
return ky.retry({
|
|
724
|
+
delay: data.error.retryAfter * 1000,
|
|
725
|
+
code: 'RATE_LIMIT'
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// Retry with a modified request (e.g., fallback endpoint)
|
|
730
|
+
if (data.error?.code === 'FALLBACK_TO_BACKUP') {
|
|
731
|
+
return ky.retry({
|
|
732
|
+
request: new Request('https://backup-api.com/endpoint', {
|
|
733
|
+
method: request.method,
|
|
734
|
+
headers: request.headers,
|
|
735
|
+
}),
|
|
736
|
+
code: 'BACKUP_ENDPOINT'
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// Retry with refreshed authentication
|
|
741
|
+
if (data.error?.code === 'TOKEN_REFRESH' && data.newToken) {
|
|
742
|
+
return ky.retry({
|
|
743
|
+
request: new Request(request, {
|
|
744
|
+
headers: {
|
|
745
|
+
...Object.fromEntries(request.headers),
|
|
746
|
+
'Authorization': `Bearer ${data.newToken}`
|
|
747
|
+
}
|
|
748
|
+
}),
|
|
749
|
+
code: 'TOKEN_REFRESHED'
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Retry with cause to preserve error chain
|
|
754
|
+
try {
|
|
755
|
+
validateResponse(data);
|
|
756
|
+
} catch (error) {
|
|
757
|
+
return ky.retry({
|
|
758
|
+
code: 'VALIDATION_FAILED',
|
|
759
|
+
cause: error
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
],
|
|
765
|
+
beforeRetry: [
|
|
766
|
+
({error, retryCount}) => {
|
|
767
|
+
// Observable in beforeRetry hooks
|
|
768
|
+
if (isForceRetryError(error)) {
|
|
769
|
+
console.log(`Forced retry #${retryCount}: ${error.message}`);
|
|
770
|
+
// Example output: "Forced retry #1: Forced retry: RATE_LIMIT"
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
]
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
const response = await api.get('https://example.com/api');
|
|
778
|
+
```
|
|
779
|
+
*/
|
|
780
|
+
declare const retry: (options?: ForceRetryOptions) => RetryMarker;
|
|
781
|
+
//#endregion
|
|
782
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/response.d.ts
|
|
783
|
+
type KyResponse<T = unknown> = {
|
|
784
|
+
json: <J = T>() => Promise<J>;
|
|
785
|
+
} & Response;
|
|
786
|
+
//#endregion
|
|
787
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/ResponsePromise.d.ts
|
|
788
|
+
type ResponsePromise<T = unknown> = {
|
|
789
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
790
|
+
blob: () => Promise<Blob>;
|
|
791
|
+
formData: () => Promise<FormData>;
|
|
792
|
+
/**
|
|
793
|
+
Get the response body as raw bytes.
|
|
794
|
+
Note: This shortcut is only available when the runtime supports `Response.prototype.bytes()`.
|
|
795
|
+
*/
|
|
796
|
+
bytes: () => Promise<Uint8Array>;
|
|
797
|
+
/**
|
|
798
|
+
Get the response body as JSON.
|
|
799
|
+
@example
|
|
800
|
+
```
|
|
801
|
+
import ky from 'ky';
|
|
802
|
+
const json = await ky(…).json();
|
|
803
|
+
```
|
|
804
|
+
@example
|
|
805
|
+
```
|
|
806
|
+
import ky from 'ky';
|
|
807
|
+
interface Result {
|
|
808
|
+
value: number;
|
|
809
|
+
}
|
|
810
|
+
const result1 = await ky(…).json<Result>();
|
|
811
|
+
// or
|
|
812
|
+
const result2 = await ky<Result>(…).json();
|
|
813
|
+
```
|
|
814
|
+
*/
|
|
815
|
+
json: <J = T>() => Promise<J>;
|
|
816
|
+
text: () => Promise<string>;
|
|
817
|
+
} & Promise<KyResponse<T>>;
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/ky.d.ts
|
|
820
|
+
type KyInstance = {
|
|
821
|
+
/**
|
|
822
|
+
Fetch the given `url`.
|
|
823
|
+
@param url - `Request` object, `URL` object, or URL string.
|
|
824
|
+
@returns A promise with `Body` method added.
|
|
825
|
+
@example
|
|
826
|
+
```
|
|
827
|
+
import ky from 'ky';
|
|
828
|
+
const json = await ky('https://example.com', {json: {foo: true}}).json();
|
|
829
|
+
console.log(json);
|
|
830
|
+
//=> `{data: '🦄'}`
|
|
831
|
+
```
|
|
832
|
+
*/
|
|
833
|
+
<T>(url: Input, options?: Options): ResponsePromise<T>;
|
|
834
|
+
/**
|
|
835
|
+
Fetch the given `url` using the option `{method: 'get'}`.
|
|
836
|
+
@param url - `Request` object, `URL` object, or URL string.
|
|
837
|
+
@returns A promise with `Body` methods added.
|
|
838
|
+
*/
|
|
839
|
+
get: <T>(url: Input, options?: Options) => ResponsePromise<T>;
|
|
840
|
+
/**
|
|
841
|
+
Fetch the given `url` using the option `{method: 'post'}`.
|
|
842
|
+
@param url - `Request` object, `URL` object, or URL string.
|
|
843
|
+
@returns A promise with `Body` methods added.
|
|
844
|
+
*/
|
|
845
|
+
post: <T>(url: Input, options?: Options) => ResponsePromise<T>;
|
|
846
|
+
/**
|
|
847
|
+
Fetch the given `url` using the option `{method: 'put'}`.
|
|
848
|
+
@param url - `Request` object, `URL` object, or URL string.
|
|
849
|
+
@returns A promise with `Body` methods added.
|
|
850
|
+
*/
|
|
851
|
+
put: <T>(url: Input, options?: Options) => ResponsePromise<T>;
|
|
852
|
+
/**
|
|
853
|
+
Fetch the given `url` using the option `{method: 'delete'}`.
|
|
854
|
+
@param url - `Request` object, `URL` object, or URL string.
|
|
855
|
+
@returns A promise with `Body` methods added.
|
|
856
|
+
*/
|
|
857
|
+
delete: <T>(url: Input, options?: Options) => ResponsePromise<T>;
|
|
858
|
+
/**
|
|
859
|
+
Fetch the given `url` using the option `{method: 'patch'}`.
|
|
860
|
+
@param url - `Request` object, `URL` object, or URL string.
|
|
861
|
+
@returns A promise with `Body` methods added.
|
|
862
|
+
*/
|
|
863
|
+
patch: <T>(url: Input, options?: Options) => ResponsePromise<T>;
|
|
864
|
+
/**
|
|
865
|
+
Fetch the given `url` using the option `{method: 'head'}`.
|
|
866
|
+
@param url - `Request` object, `URL` object, or URL string.
|
|
867
|
+
@returns A promise with `Body` methods added.
|
|
868
|
+
*/
|
|
869
|
+
head: (url: Input, options?: Options) => ResponsePromise;
|
|
870
|
+
/**
|
|
871
|
+
Create a new Ky instance with complete new defaults.
|
|
872
|
+
@returns A new Ky instance.
|
|
873
|
+
*/
|
|
874
|
+
create: (defaultOptions?: Options) => KyInstance;
|
|
875
|
+
/**
|
|
876
|
+
Create a new Ky instance with some defaults overridden with your own.
|
|
877
|
+
In contrast to `ky.create()`, `ky.extend()` inherits defaults from its parent.
|
|
878
|
+
You can also refer to parent defaults by providing a function to `.extend()`.
|
|
879
|
+
@example
|
|
880
|
+
```
|
|
881
|
+
import ky from 'ky';
|
|
882
|
+
const api = ky.create({prefixUrl: 'https://example.com/api'});
|
|
883
|
+
const usersApi = api.extend((options) => ({prefixUrl: `${options.prefixUrl}/users`}));
|
|
884
|
+
const response = await usersApi.get('123');
|
|
885
|
+
//=> 'https://example.com/api/users/123'
|
|
886
|
+
const response = await api.get('version');
|
|
887
|
+
//=> 'https://example.com/api/version'
|
|
888
|
+
```
|
|
889
|
+
@returns A new Ky instance.
|
|
890
|
+
*/
|
|
891
|
+
extend: (defaultOptions: Options | ((parentOptions: Options) => Options)) => KyInstance;
|
|
892
|
+
/**
|
|
893
|
+
A `Symbol` that can be returned by a `beforeRetry` hook to stop the retry. This will also short circuit the remaining `beforeRetry` hooks.
|
|
894
|
+
Note: Returning this symbol makes Ky abort and return with an `undefined` response. Be sure to check for a response before accessing any properties on it or use [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining). It is also incompatible with body methods, such as `.json()` or `.text()`, because there is no response to parse. In general, we recommend throwing an error instead of returning this symbol, as that will cause Ky to abort and then throw, which avoids these limitations.
|
|
895
|
+
A valid use-case for `ky.stop` is to prevent retries when making requests for side effects, where the returned data is not important. For example, logging client activity to the server.
|
|
896
|
+
@example
|
|
897
|
+
```
|
|
898
|
+
import ky from 'ky';
|
|
899
|
+
const options = {
|
|
900
|
+
hooks: {
|
|
901
|
+
beforeRetry: [
|
|
902
|
+
async ({request, options, error, retryCount}) => {
|
|
903
|
+
const shouldStopRetry = await ky('https://example.com/api');
|
|
904
|
+
if (shouldStopRetry) {
|
|
905
|
+
return ky.stop;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
]
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
// Note that response will be `undefined` in case `ky.stop` is returned.
|
|
912
|
+
const response = await ky.post('https://example.com', options);
|
|
913
|
+
// Using `.text()` or other body methods is not supported.
|
|
914
|
+
const text = await ky('https://example.com', options).text();
|
|
915
|
+
```
|
|
916
|
+
*/
|
|
917
|
+
readonly stop: typeof stop;
|
|
918
|
+
/**
|
|
919
|
+
Force a retry from an `afterResponse` hook.
|
|
920
|
+
This allows you to retry a request based on the response content, even if the response has a successful status code. The retry will respect the `retry.limit` option and skip the `shouldRetry` check. The forced retry is observable in `beforeRetry` hooks, where the error will be a `ForceRetryError`.
|
|
921
|
+
@example
|
|
922
|
+
```
|
|
923
|
+
import ky, {isForceRetryError} from 'ky';
|
|
924
|
+
const api = ky.extend({
|
|
925
|
+
hooks: {
|
|
926
|
+
afterResponse: [
|
|
927
|
+
async (request, options, response) => {
|
|
928
|
+
// Retry based on response body content
|
|
929
|
+
if (response.status === 200) {
|
|
930
|
+
const data = await response.clone().json();
|
|
931
|
+
// Simple retry with default delay
|
|
932
|
+
if (data.error?.code === 'TEMPORARY_ERROR') {
|
|
933
|
+
return ky.retry();
|
|
934
|
+
}
|
|
935
|
+
// Retry with custom delay from API response
|
|
936
|
+
if (data.error?.code === 'RATE_LIMIT') {
|
|
937
|
+
return ky.retry({
|
|
938
|
+
delay: data.error.retryAfter * 1000,
|
|
939
|
+
code: 'RATE_LIMIT'
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
],
|
|
945
|
+
beforeRetry: [
|
|
946
|
+
({error, retryCount}) => {
|
|
947
|
+
// Observable in beforeRetry hooks
|
|
948
|
+
if (isForceRetryError(error)) {
|
|
949
|
+
console.log(`Forced retry #${retryCount}: ${error.message}`);
|
|
950
|
+
// Example output: "Forced retry #1: Forced retry: RATE_LIMIT"
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
]
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
const response = await api.get('https://example.com/api');
|
|
957
|
+
```
|
|
958
|
+
*/
|
|
959
|
+
readonly retry: typeof retry;
|
|
960
|
+
};
|
|
961
|
+
//#endregion
|
|
962
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/types/request.d.ts
|
|
963
|
+
type KyRequest<T = unknown> = {
|
|
964
|
+
json: <J = T>() => Promise<J>;
|
|
965
|
+
} & Request;
|
|
966
|
+
//#endregion
|
|
967
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/HTTPError.d.ts
|
|
968
|
+
declare class HTTPError<T = unknown> extends Error {
|
|
969
|
+
response: KyResponse<T>;
|
|
970
|
+
request: KyRequest;
|
|
971
|
+
options: NormalizedOptions;
|
|
972
|
+
constructor(response: Response, request: Request, options: NormalizedOptions);
|
|
973
|
+
}
|
|
974
|
+
//#endregion
|
|
975
|
+
//#region node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/index.d.ts
|
|
976
|
+
declare const ky: KyInstance;
|
|
977
|
+
//#endregion
|
|
978
|
+
export { Options as n, ky as t };
|
|
979
|
+
//# sourceMappingURL=index-IOhsyoSY.d.mts.map
|