Comparing version 12.3.1 to 12.4.0
import Request from '../core/index.js'; | ||
import type { CancelableRequest } from './types.js'; | ||
import { type CancelableRequest } from './types.js'; | ||
export default function asPromise<T>(firstRequest?: Request): CancelableRequest<T>; |
/// <reference types="node" /> | ||
import type { Buffer } from 'node:buffer'; | ||
import PCancelable from 'p-cancelable'; | ||
import type PCancelable from 'p-cancelable'; | ||
import { RequestError } from '../core/errors.js'; | ||
@@ -5,0 +5,0 @@ import type Request from '../core/index.js'; |
@@ -15,13 +15,11 @@ /// <reference types="node" /> | ||
import type ResponseLike from 'responselike'; | ||
import Options from './options.js'; | ||
import { Response } from './response.js'; | ||
import Options, { type NativeRequestOptions } from './options.js'; | ||
import { type PlainResponse, type Response } from './response.js'; | ||
import { RequestError } from './errors.js'; | ||
import type { PlainResponse } from './response.js'; | ||
import type { NativeRequestOptions } from './options.js'; | ||
declare type Error = NodeJS.ErrnoException; | ||
export interface Progress { | ||
export declare type Progress = { | ||
percent: number; | ||
transferred: number; | ||
total?: number; | ||
} | ||
}; | ||
export declare type GotEventFunction<T> = | ||
@@ -88,7 +86,7 @@ /** | ||
& ((name: 'retry', listener: (retryCount: number, error: RequestError) => void) => T); | ||
export interface RequestEvents<T> { | ||
export declare type RequestEvents<T> = { | ||
on: GotEventFunction<T>; | ||
once: GotEventFunction<T>; | ||
off: GotEventFunction<T>; | ||
} | ||
}; | ||
export declare type CacheableRequestFunction = (options: string | URL | NativeRequestOptions, cb?: (response: ServerResponse | ResponseLike) => void) => CacheableRequest.Emitter; | ||
@@ -95,0 +93,0 @@ declare type UrlType = ConstructorParameters<typeof Options>[0]; |
@@ -504,3 +504,5 @@ import process from 'node:process'; | ||
} | ||
headers['content-length'] = encoder.headers['Content-Length']; | ||
if ('Content-Length' in encoder.headers) { | ||
headers['content-length'] = encoder.headers['Content-Length']; | ||
} | ||
options.body = encoder.encode(); | ||
@@ -684,2 +686,6 @@ } | ||
} | ||
// `HTTPError`s always have `error.response.body` defined. | ||
// Therefore we cannot retry if `options.throwHttpErrors` is false. | ||
// On the last retry, if `options.throwHttpErrors` is false, we would need to return the body, | ||
// but that wouldn't be possible since the body would be already read in `error.response.body`. | ||
if (options.isStream && options.throwHttpErrors && !isResponseOk(typedResponse)) { | ||
@@ -974,6 +980,13 @@ this._beforeError(new HTTPError(typedResponse)); | ||
try { | ||
for (const hook of this.options.hooks.beforeError) { | ||
// eslint-disable-next-line no-await-in-loop | ||
error = await hook(error); | ||
if (error instanceof HTTPError && !this.options.throwHttpErrors) { | ||
// This branch can be reached only when using the Promise API | ||
// Skip calling the hooks on purpose. | ||
// See https://github.com/sindresorhus/got/issues/2103 | ||
} | ||
else { | ||
for (const hook of this.options.hooks.beforeError) { | ||
// eslint-disable-next-line no-await-in-loop | ||
error = await hook(error); | ||
} | ||
} | ||
} | ||
@@ -980,0 +993,0 @@ catch (error_) { |
@@ -10,3 +10,3 @@ /// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Buffer } from 'node:buffer'; | ||
import type { Buffer } from 'node:buffer'; | ||
import { URL, URLSearchParams } from 'node:url'; | ||
@@ -22,3 +22,3 @@ import { checkServerIdentity } from 'node:tls'; | ||
import CacheableLookup from 'cacheable-lookup'; | ||
import http2wrapper, { ClientHttp2Session } from 'http2-wrapper'; | ||
import http2wrapper, { type ClientHttp2Session } from 'http2-wrapper'; | ||
import type { FormDataLike } from 'form-data-encoder'; | ||
@@ -41,16 +41,16 @@ import type CacheableRequest from 'cacheable-request'; | ||
export declare type RequestFunction = (url: URL, options: NativeRequestOptions, callback?: (response: AcceptableResponse) => void) => AcceptableRequestResult; | ||
export interface Agents { | ||
export declare type Agents = { | ||
http?: HttpAgent | false; | ||
https?: HttpsAgent | false; | ||
http2?: unknown | false; | ||
} | ||
}; | ||
export declare type Headers = Record<string, string | string[] | undefined>; | ||
export interface ToughCookieJar { | ||
export declare type ToughCookieJar = { | ||
getCookieString: ((currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookies: string) => void) => void) & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void); | ||
setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record<string, unknown>, cb: (error: Error | null, cookie: unknown) => void) => void) & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void); | ||
} | ||
export interface PromiseCookieJar { | ||
}; | ||
export declare type PromiseCookieJar = { | ||
getCookieString: (url: string) => Promise<string>; | ||
setCookie: (rawCookie: string, url: string) => Promise<unknown>; | ||
} | ||
}; | ||
export declare type InitHook = (init: OptionsInit, self: Options) => void; | ||
@@ -65,3 +65,3 @@ export declare type BeforeRequestHook = (options: Options) => Promisable<void | Response | ResponseLike>; | ||
*/ | ||
export interface Hooks { | ||
export declare type Hooks = { | ||
/** | ||
@@ -334,3 +334,3 @@ Called with the plain request options, right before their normalization. | ||
afterResponse: AfterResponseHook[]; | ||
} | ||
}; | ||
export declare type ParseJsonFunction = (text: string) => unknown; | ||
@@ -342,3 +342,3 @@ export declare type StringifyJsonFunction = (object: unknown) => string; | ||
export declare type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'HEAD' | 'DELETE' | 'OPTIONS' | 'TRACE' | 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options' | 'trace'; | ||
export interface RetryObject { | ||
export declare type RetryObject = { | ||
attemptCount: number; | ||
@@ -349,3 +349,3 @@ retryOptions: RetryOptions; | ||
retryAfter?: number; | ||
} | ||
}; | ||
export declare type RetryFunction = (retryObject: RetryObject) => Promisable<number>; | ||
@@ -374,3 +374,3 @@ /** | ||
*/ | ||
export interface RetryOptions { | ||
export declare type RetryOptions = { | ||
limit: number; | ||
@@ -384,6 +384,6 @@ methods: Method[]; | ||
maxRetryAfter?: number; | ||
} | ||
}; | ||
export declare type CreateConnectionFunction = (options: NativeRequestOptions, oncreate: (error: NodeJS.ErrnoException, socket: Socket) => void) => Socket; | ||
export declare type CheckServerIdentityFunction = (hostname: string, certificate: DetailedPeerCertificate) => NodeJS.ErrnoException | void; | ||
export interface CacheOptions { | ||
export declare type CacheOptions = { | ||
shared?: boolean; | ||
@@ -393,3 +393,3 @@ cacheHeuristic?: number; | ||
ignoreCargoCult?: boolean; | ||
} | ||
}; | ||
declare type PfxObject = { | ||
@@ -400,3 +400,3 @@ buffer: string | Buffer; | ||
declare type PfxType = string | Buffer | Array<string | Buffer | PfxObject> | undefined; | ||
export interface HttpsOptions { | ||
export declare type HttpsOptions = { | ||
alpnProtocols?: string[]; | ||
@@ -452,17 +452,17 @@ rejectUnauthorized?: NativeRequestOptions['rejectUnauthorized']; | ||
certificateRevocationLists?: SecureContextOptions['crl']; | ||
} | ||
export interface PaginateData<BodyType, ElementType> { | ||
}; | ||
export declare type PaginateData<BodyType, ElementType> = { | ||
response: Response<BodyType>; | ||
currentItems: ElementType[]; | ||
allItems: ElementType[]; | ||
} | ||
export interface FilterData<ElementType> { | ||
}; | ||
export declare type FilterData<ElementType> = { | ||
item: ElementType; | ||
currentItems: ElementType[]; | ||
allItems: ElementType[]; | ||
} | ||
}; | ||
/** | ||
All options accepted by `got.paginate()`. | ||
*/ | ||
export interface PaginationOptions<ElementType, BodyType> { | ||
export declare type PaginationOptions<ElementType, BodyType> = { | ||
/** | ||
@@ -565,3 +565,3 @@ A function that transform [`Response`](#response) into an array of items. | ||
stackAllItems?: boolean; | ||
} | ||
}; | ||
export declare type SearchParameters = Record<string, string | number | boolean | null | undefined>; | ||
@@ -568,0 +568,0 @@ /** |
@@ -467,2 +467,3 @@ import process from 'node:process'; | ||
} | ||
// @ts-expect-error - No idea why `value[key]` doesn't work here. | ||
assert.any([is.object, is.undefined], value[key]); | ||
@@ -527,2 +528,3 @@ } | ||
} | ||
// @ts-expect-error - No idea why `value[key]` doesn't work here. | ||
assert.any([is.number, is.undefined], value[key]); | ||
@@ -981,4 +983,3 @@ } | ||
const typedKnownHookEvent = knownHookEvent; | ||
const typedValue = value; | ||
const hooks = typedValue[typedKnownHookEvent]; | ||
const hooks = value[typedKnownHookEvent]; | ||
assert.any([is.array, is.undefined], hooks); | ||
@@ -985,0 +986,0 @@ if (hooks) { |
@@ -9,3 +9,3 @@ /// <reference types="node" /> | ||
import type Request from './index.js'; | ||
export interface PlainResponse extends IncomingMessageWithTimings { | ||
export declare type PlainResponse = { | ||
/** | ||
@@ -91,4 +91,4 @@ The original request URL. | ||
ok: boolean; | ||
} | ||
export interface Response<T = unknown> extends PlainResponse { | ||
} & IncomingMessageWithTimings; | ||
export declare type Response<T = unknown> = { | ||
/** | ||
@@ -102,3 +102,3 @@ The result of the request. | ||
rawBody: Buffer; | ||
} | ||
} & PlainResponse; | ||
export declare const isResponseOk: (response: PlainResponse) => boolean; | ||
@@ -105,0 +105,0 @@ /** |
@@ -1,9 +0,9 @@ | ||
import { ClientRequest } from 'node:http'; | ||
import type { ClientRequest } from 'node:http'; | ||
declare const reentry: unique symbol; | ||
interface TimedOutOptions { | ||
declare type TimedOutOptions = { | ||
host?: string; | ||
hostname?: string; | ||
protocol?: string; | ||
} | ||
export interface Delays { | ||
}; | ||
export declare type Delays = { | ||
lookup?: number; | ||
@@ -17,3 +17,3 @@ socket?: number; | ||
request?: number; | ||
} | ||
}; | ||
export declare type ErrorCode = 'ETIMEDOUT' | 'ECONNRESET' | 'EADDRINUSE' | 'ECONNREFUSED' | 'EPIPE' | 'ENOTFOUND' | 'ENETUNREACH' | 'EAI_AGAIN'; | ||
@@ -20,0 +20,0 @@ export declare class TimeoutError extends Error { |
/// <reference types="node" /> | ||
import { ClientRequestArgs } from 'node:http'; | ||
import type { ClientRequestArgs } from 'node:http'; | ||
export default function getBodySize(body: unknown, headers: ClientRequestArgs['headers']): Promise<number | undefined>; |
/// <reference types="node" /> | ||
import { Readable } from 'node:stream'; | ||
interface FormData extends Readable { | ||
import type { Readable } from 'node:stream'; | ||
declare type FormData = { | ||
getBoundary: () => string; | ||
getLength: (callback: (error: Error | null, length: number) => void) => void; | ||
} | ||
} & Readable; | ||
export default function isFormData(body: unknown): body is FormData; | ||
export {}; |
/// <reference types="node" /> | ||
import { URL } from 'url'; | ||
import type { URL } from 'url'; | ||
export default function isUnixSocketURL(url: URL): boolean; |
/// <reference types="node" /> | ||
import { URL } from 'node:url'; | ||
export interface URLOptions { | ||
export declare type URLOptions = { | ||
href?: string; | ||
@@ -13,3 +13,3 @@ protocol?: string; | ||
path?: string; | ||
} | ||
}; | ||
export default function optionsToUrl(origin: string, options: URLOptions): URL; |
/// <reference types="node" /> | ||
import { EventEmitter } from 'node:events'; | ||
import type { EventEmitter } from 'node:events'; | ||
export default function proxyEvents(from: EventEmitter, to: EventEmitter, events: Readonly<string[]>): () => void; |
/// <reference types="node" /> | ||
import { EventEmitter } from 'node:events'; | ||
import type { EventEmitter } from 'node:events'; | ||
declare type Origin = EventEmitter; | ||
declare type Event = string | symbol; | ||
declare type Fn = (...args: any[]) => void; | ||
interface Unhandler { | ||
declare type Unhandler = { | ||
once: (origin: Origin, event: Event, fn: Fn) => void; | ||
unhandleAll: () => void; | ||
} | ||
}; | ||
export default function unhandle(): Unhandler; | ||
export {}; |
/// <reference types="node" /> | ||
import { URL, UrlWithStringQuery } from 'node:url'; | ||
export interface LegacyUrlOptions { | ||
import type { URL, UrlWithStringQuery } from 'node:url'; | ||
export declare type LegacyUrlOptions = { | ||
protocol: string; | ||
@@ -14,3 +14,3 @@ hostname: string; | ||
auth?: string; | ||
} | ||
}; | ||
export default function urlToOptions(url: URL | UrlWithStringQuery): LegacyUrlOptions; |
@@ -1,3 +0,3 @@ | ||
import { Got, InstanceDefaults } from './types.js'; | ||
import type { Got, InstanceDefaults } from './types.js'; | ||
declare const create: (defaults: InstanceDefaults) => Got; | ||
export default create; |
@@ -15,3 +15,3 @@ /// <reference types="node" /> | ||
*/ | ||
export interface InstanceDefaults { | ||
export declare type InstanceDefaults = { | ||
/** | ||
@@ -36,3 +36,3 @@ An object containing the default options of Got. | ||
mutableDefaults: boolean; | ||
} | ||
}; | ||
/** | ||
@@ -50,3 +50,3 @@ A Request object returned by calling Got, or any of the Got HTTP alias request functions. | ||
*/ | ||
export interface ExtendOptions extends OptionsInit { | ||
export declare type ExtendOptions = { | ||
/** | ||
@@ -67,3 +67,3 @@ An array of functions. You execute them directly by calling `got()`. | ||
mutableDefaults?: boolean; | ||
} | ||
} & OptionsInit; | ||
export declare type OptionsOfTextResponseBody = Merge<OptionsInit, { | ||
@@ -101,3 +101,3 @@ isStream?: false; | ||
*/ | ||
export interface GotPaginate { | ||
export declare type GotPaginate = { | ||
/** | ||
@@ -154,4 +154,4 @@ Same as `GotPaginate.each`. | ||
all: (<T, R = unknown>(url: string | URL, options?: OptionsWithPagination<T, R>) => Promise<T[]>) & (<T, R = unknown>(options?: OptionsWithPagination<T, R>) => Promise<T[]>); | ||
} | ||
export interface GotRequestFunction { | ||
}; | ||
export declare type GotRequestFunction = { | ||
(url: string | URL, options?: OptionsOfTextResponseBody): CancelableRequest<Response<string>>; | ||
@@ -180,3 +180,3 @@ <T>(url: string | URL, options?: OptionsOfJSONResponseBody): CancelableRequest<Response<T>>; | ||
(url: undefined, options: undefined, defaults: Options): CancelableRequest | Request; | ||
} | ||
}; | ||
/** | ||
@@ -198,3 +198,3 @@ All available HTTP request methods provided by Got. | ||
*/ | ||
export interface Got extends Record<HTTPAlias, GotRequestFunction>, GotRequestFunction { | ||
export declare type Got = { | ||
/** | ||
@@ -270,3 +270,3 @@ Sets `options.isStream` to `true`. | ||
extend: (...instancesOrOptions: Array<Got | ExtendOptions>) => Got; | ||
} | ||
} & Record<HTTPAlias, GotRequestFunction> & GotRequestFunction; | ||
export {}; |
{ | ||
"name": "got", | ||
"version": "12.3.1", | ||
"version": "12.4.0", | ||
"description": "Human-friendly and powerful HTTP request library for Node.js", | ||
@@ -15,3 +15,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava", | ||
"test": "xo && tsc --noEmit && ava", | ||
"release": "np", | ||
@@ -52,7 +52,6 @@ "build": "del-cli dist && tsc", | ||
"@types/cacheable-request": "^6.0.2", | ||
"@types/responselike": "^1.0.0", | ||
"cacheable-lookup": "^6.0.4", | ||
"cacheable-request": "^7.0.2", | ||
"decompress-response": "^6.0.0", | ||
"form-data-encoder": "^2.0.1", | ||
"form-data-encoder": "^2.1.0", | ||
"get-stream": "^6.0.1", | ||
@@ -62,3 +61,3 @@ "http2-wrapper": "^2.1.10", | ||
"p-cancelable": "^3.0.0", | ||
"responselike": "^2.0.0" | ||
"responselike": "^3.0.0" | ||
}, | ||
@@ -69,5 +68,5 @@ "devDependencies": { | ||
"@sinonjs/fake-timers": "^9.1.1", | ||
"@types/benchmark": "^2.1.1", | ||
"@types/benchmark": "^2.1.2", | ||
"@types/express": "^4.17.13", | ||
"@types/node": "^18.0.1", | ||
"@types/node": "^18.7.13", | ||
"@types/pem": "^1.9.6", | ||
@@ -87,3 +86,3 @@ "@types/pify": "^5.0.1", | ||
"create-test-server": "^3.0.1", | ||
"del-cli": "^4.0.1", | ||
"del-cli": "^5.0.0", | ||
"delay": "^5.0.0", | ||
@@ -107,6 +106,6 @@ "express": "^4.17.3", | ||
"to-readable-stream": "^3.0.0", | ||
"tough-cookie": "^4.0.0", | ||
"tough-cookie": "4.0.0", | ||
"ts-node": "^10.8.2", | ||
"typescript": "^4.7.4", | ||
"xo": "^0.50.0" | ||
"typescript": "~4.8.2", | ||
"xo": "^0.52.2" | ||
}, | ||
@@ -113,0 +112,0 @@ "sideEffects": false, |
@@ -112,2 +112,4 @@ <div align="center"> | ||
**A [quick start](documentation/quick-start.md) guide is available.** | ||
### JSON mode | ||
@@ -153,3 +155,3 @@ | ||
- [x] [HTTP/2 support](documentation/2-options.md#http2) | ||
- [x] [`Response` class](documentation/3-streams.md#response-1) | ||
- [x] [`Response` class](documentation/3-streams.md#response-2) | ||
@@ -156,0 +158,0 @@ #### Timeouts and retries |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
249674
12
5477
562
+ Addedresponselike@3.0.0(transitive)
- Removed@types/responselike@^1.0.0
Updatedform-data-encoder@^2.1.0
Updatedresponselike@^3.0.0