Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

ky

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ky - npm Package Compare versions

Comparing version
1.14.0
to
1.14.1
+3
-1
distribution/core/Ky.js

@@ -214,3 +214,5 @@ import { HTTPError } from '../errors/HTTPError.js';

}
return Math.min(this.#options.retry.backoffLimit, jitteredDelay);
// Handle undefined backoffLimit by treating it as no limit (Infinity)
const backoffLimit = this.#options.retry.backoffLimit ?? Number.POSITIVE_INFINITY;
return Math.min(backoffLimit, jitteredDelay);
}

@@ -217,0 +219,0 @@ async #calculateRetryDelay(error) {

@@ -47,3 +47,3 @@ import { type stop, type RetryMarker } from '../core/constants.js';

A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) can be returned from this hook to completely avoid making a 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**.
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**.

@@ -167,12 +167,15 @@ @example

// Or retry with a fresh token on a 403 error
async (request, options, response) => {
if (response.status === 403) {
// Get a fresh token
const token = await ky('https://example.com/token').text();
// Or retry with a fresh token on a 401 error
async (request, _options, response, state) => {
if (response.status === 401 && state.retryCount === 0) {
// Only refresh on first 401, not on subsequent retries
const {token} = await ky.post('https://example.com/auth/refresh').json();
// Retry with the token
options.headers.set('Authorization', `token ${token}`);
const headers = new Headers(request.headers);
headers.set('Authorization', `Bearer ${token}`);
return ky(request, options);
return ky.retry({
request: new Request(request, {headers}),
code: 'TOKEN_REFRESHED'
});
}

@@ -210,3 +213,3 @@ },

/**
This hook enables you to modify the `HTTPError` right before it is thrown. The hook function receives a `HTTPError` and a state object as arguments and should return an instance of `HTTPError`.
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`.

@@ -213,0 +216,0 @@ @default []

@@ -30,7 +30,8 @@ import { requestMethods } from '../core/constants.js';

}
const normalizedRetry = Object.fromEntries(Object.entries(retry).filter(([, value]) => value !== undefined));
return {
...defaultRetryOptions,
...retry,
...normalizedRetry,
};
};
//# sourceMappingURL=normalize.js.map
{
"name": "ky",
"version": "1.14.0",
"version": "1.14.1",
"description": "Tiny and elegant HTTP client based on the Fetch API",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -451,3 +451,3 @@ <div align="center">

This hook enables you to modify the `HTTPError` right before it is thrown. The hook function receives a `HTTPError` and a state object as arguments and should return an instance of `HTTPError`.
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`.

@@ -511,12 +511,15 @@ The `state.retryCount` is `0` for the initial request and increments with each retry. 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).

// Or retry with a fresh token on a 403 error
async (request, options, response) => {
if (response.status === 403) {
// Get a fresh token
const token = await ky('https://example.com/token').text();
// Or retry with a fresh token on a 401 error
async (request, _options, response, state) => {
if (response.status === 401 && state.retryCount === 0) {
// Only refresh on first 401, not on subsequent retries
const {token} = await ky.post('https://example.com/auth/refresh').json();
// Retry with the token
request.headers.set('Authorization', `token ${token}`);
const headers = new Headers(request.headers);
headers.set('Authorization', `Bearer ${token}`);
return ky(request, options);
return ky.retry({
request: new Request(request, {headers}),
code: 'TOKEN_REFRESHED'
});
}

@@ -523,0 +526,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet