got-cjs
Advanced tools
Comparing version 12.0.4 to 12.3.1
@@ -138,2 +138,6 @@ "use strict"; | ||
}; | ||
promise.off = (event, fn) => { | ||
emitter.off(event, fn); | ||
return promise; | ||
}; | ||
const shortcut = (responseType) => { | ||
@@ -140,0 +144,0 @@ const newPromise = (async () => { |
@@ -84,2 +84,8 @@ /// <reference types="node" /> | ||
} | ||
/** | ||
An error to be thrown when the request is aborted by AbortController. | ||
*/ | ||
export declare class AbortError extends RequestError { | ||
constructor(request: Request); | ||
} | ||
export {}; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RetryError = exports.ReadError = exports.TimeoutError = exports.UploadError = exports.CacheError = exports.HTTPError = exports.MaxRedirectsError = exports.RequestError = void 0; | ||
exports.AbortError = exports.RetryError = exports.ReadError = exports.TimeoutError = exports.UploadError = exports.CacheError = exports.HTTPError = exports.MaxRedirectsError = exports.RequestError = void 0; | ||
const is_1 = __importDefault(require("@sindresorhus/is")); | ||
@@ -185,1 +185,12 @@ // A hacky check to prevent circular references. | ||
exports.RetryError = RetryError; | ||
/** | ||
An error to be thrown when the request is aborted by AbortController. | ||
*/ | ||
class AbortError extends RequestError { | ||
constructor(request) { | ||
super('This operation was aborted.', {}, request); | ||
this.code = 'ERR_ABORTED'; | ||
this.name = 'AbortError'; | ||
} | ||
} | ||
exports.AbortError = AbortError; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Duplex } from 'stream'; | ||
@@ -29,2 +34,4 @@ import { URL } from 'url'; | ||
``` | ||
import got from 'got'; | ||
got.stream('https://github.com') | ||
@@ -59,2 +66,4 @@ .on('request', request => setTimeout(() => request.destroy(), 50)); | ||
``` | ||
import got from 'got'; | ||
const response = await got('https://sindresorhus.com') | ||
@@ -83,2 +92,3 @@ .on('downloadProgress', progress => { | ||
once: GotEventFunction<T>; | ||
off: GotEventFunction<T>; | ||
} | ||
@@ -85,0 +95,0 @@ export declare type CacheableRequestFunction = (options: string | URL | NativeRequestOptions, cb?: (response: ServerResponse | ResponseLike) => void) => CacheableRequest.Emitter; |
@@ -50,2 +50,3 @@ "use strict"; | ||
const is_client_request_js_1 = __importDefault(require("./utils/is-client-request.js")); | ||
const is_unix_socket_url_js_1 = __importDefault(require("./utils/is-unix-socket-url.js")); | ||
const errors_js_1 = require("./errors.js"); | ||
@@ -66,2 +67,3 @@ const supportsBrotli = is_1.default.string(process_1.default.versions.brotli); | ||
constructor(url, options, defaults) { | ||
var _a, _b; | ||
super({ | ||
@@ -73,2 +75,3 @@ // Don't destroy immediately, as the error may be emitted on unsuccessful retry | ||
}); | ||
// @ts-expect-error - Ignoring for now. | ||
Object.defineProperty(this, 'constructor', { | ||
@@ -266,2 +269,8 @@ enumerable: true, | ||
} | ||
if ((_a = this.options.signal) === null || _a === void 0 ? void 0 : _a.aborted) { | ||
this.destroy(new errors_js_1.AbortError(this)); | ||
} | ||
(_b = this.options.signal) === null || _b === void 0 ? void 0 : _b.addEventListener('abort', () => { | ||
this.destroy(new errors_js_1.AbortError(this)); | ||
}); | ||
// Important! If you replace `body` in a handler with another stream, make sure it's readable first. | ||
@@ -526,3 +535,3 @@ // The below is run only once. | ||
// Body is spec-compliant FormData | ||
if ((0, form_data_encoder_1.isFormDataLike)(options.body)) { | ||
if ((0, form_data_encoder_1.isFormData)(options.body)) { | ||
const encoder = new form_data_encoder_1.FormDataEncoder(options.body); | ||
@@ -597,2 +606,3 @@ if (noContentType) { | ||
typedResponse.retryCount = this.retryCount; | ||
typedResponse.ok = (0, response_js_1.isResponseOk)(typedResponse); | ||
this._isFromCache = typedResponse.isFromCache; | ||
@@ -671,2 +681,6 @@ this._responseSize = Number(response.headers['content-length']) || undefined; | ||
const redirectUrl = new url_1.URL(redirectBuffer, url); | ||
if (!(0, is_unix_socket_url_js_1.default)(url) && (0, is_unix_socket_url_js_1.default)(redirectUrl)) { | ||
this._beforeError(new errors_js_1.RequestError('Cannot redirect to UNIX socket', {}, this)); | ||
return; | ||
} | ||
// Redirecting to a different site, clear sensitive data. | ||
@@ -673,0 +687,0 @@ if (redirectUrl.hostname !== url.hostname || redirectUrl.port !== url.port) { |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import { Buffer } from 'buffer'; | ||
@@ -734,2 +742,24 @@ import { URL, URLSearchParams } from 'url'; | ||
/** | ||
You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). | ||
*Requires Node.js 16 or later.* | ||
@example | ||
``` | ||
import got from 'got'; | ||
const abortController = new AbortController(); | ||
const request = got('https://httpbin.org/anything', { | ||
signal: abortController.signal | ||
}); | ||
setTimeout(() => { | ||
abortController.abort(); | ||
}, 100); | ||
``` | ||
*/ | ||
get signal(): any | undefined; | ||
set signal(value: any | undefined); | ||
/** | ||
Ignore invalid cookies instead of throwing an error. | ||
@@ -1100,2 +1130,4 @@ Only useful when the `cookieJar` option has been set. Not recommended. | ||
set maxHeaderSize(value: number | undefined); | ||
get enableUnixSockets(): boolean; | ||
set enableUnixSockets(value: boolean); | ||
toJSON(): { | ||
@@ -1117,2 +1149,3 @@ headers: Headers; | ||
cookieJar: PromiseCookieJar | ToughCookieJar | undefined; | ||
signal: any; | ||
ignoreInvalidCookies: boolean; | ||
@@ -1153,2 +1186,3 @@ searchParams: string | SearchParameters | URLSearchParams | undefined; | ||
maxHeaderSize: number | undefined; | ||
enableUnixSockets: boolean; | ||
}; | ||
@@ -1155,0 +1189,0 @@ createNativeRequestOptions(): { |
@@ -42,3 +42,3 @@ "use strict"; | ||
const parse_link_header_js_1 = __importDefault(require("./parse-link-header.js")); | ||
const [major, minor] = process_1.default.versions.node.split('.').map(v => Number(v)); | ||
const [major, minor] = process_1.default.versions.node.split('.').map(Number); | ||
function validateSearchParameters(searchParameters) { | ||
@@ -212,2 +212,4 @@ // eslint-disable-next-line guard-for-in | ||
maxHeaderSize: undefined, | ||
signal: undefined, | ||
enableUnixSockets: true, | ||
}; | ||
@@ -642,3 +644,3 @@ const cloneInternals = (internals) => { | ||
set body(value) { | ||
is_1.assert.any([is_1.default.string, is_1.default.buffer, is_1.default.nodeStream, is_1.default.generator, is_1.default.asyncGenerator, form_data_encoder_1.isFormDataLike, is_1.default.undefined], value); | ||
is_1.assert.any([is_1.default.string, is_1.default.buffer, is_1.default.nodeStream, is_1.default.generator, is_1.default.asyncGenerator, form_data_encoder_1.isFormData, is_1.default.undefined], value); | ||
if (is_1.default.nodeStream(value)) { | ||
@@ -745,2 +747,5 @@ is_1.assert.truthy(value.readable); | ||
if (url.hostname === 'unix') { | ||
if (!this._internals.enableUnixSockets) { | ||
throw new Error('Using UNIX domain sockets but option `enableUnixSockets` is not enabled'); | ||
} | ||
const matches = /(?<socketPath>.+?):(?<path>.+)/.exec(`${url.pathname}${url.search}`); | ||
@@ -793,2 +798,31 @@ if (matches === null || matches === void 0 ? void 0 : matches.groups) { | ||
/** | ||
You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). | ||
*Requires Node.js 16 or later.* | ||
@example | ||
``` | ||
import got from 'got'; | ||
const abortController = new AbortController(); | ||
const request = got('https://httpbin.org/anything', { | ||
signal: abortController.signal | ||
}); | ||
setTimeout(() => { | ||
abortController.abort(); | ||
}, 100); | ||
``` | ||
*/ | ||
// TODO: Replace `any` with `AbortSignal` when targeting Node 16. | ||
get signal() { | ||
return this._internals.signal; | ||
} | ||
// TODO: Replace `any` with `AbortSignal` when targeting Node 16. | ||
set signal(value) { | ||
is_1.assert.object(value); | ||
this._internals.signal = value; | ||
} | ||
/** | ||
Ignore invalid cookies instead of throwing an error. | ||
@@ -1536,2 +1570,9 @@ Only useful when the `cookieJar` option has been set. Not recommended. | ||
} | ||
get enableUnixSockets() { | ||
return this._internals.enableUnixSockets; | ||
} | ||
set enableUnixSockets(value) { | ||
is_1.assert.boolean(value); | ||
this._internals.enableUnixSockets = value; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
@@ -1538,0 +1579,0 @@ toJSON() { |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import type { Buffer } from 'buffer'; | ||
@@ -83,2 +84,8 @@ import type { URL } from 'url'; | ||
body?: unknown; | ||
/** | ||
Whether the response was successful. | ||
__Note__: Got throws automatically when `response.ok` is `false` and `throwHttpErrors` is `true`. | ||
*/ | ||
ok: boolean; | ||
} | ||
@@ -104,2 +111,2 @@ export interface Response<T = unknown> extends PlainResponse { | ||
} | ||
export declare const parseBody: (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: BufferEncoding | undefined) => unknown; | ||
export declare const parseBody: (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: BufferEncoding) => unknown; |
@@ -10,3 +10,3 @@ declare const got: import("./types.js").Got; | ||
export * from './core/errors.js'; | ||
export { Delays } from './core/timed-out.js'; | ||
export type { Delays } from './core/timed-out.js'; | ||
export { default as calculateRetryDelay } from './core/calculate-retry-delay.js'; | ||
@@ -13,0 +13,0 @@ export * from './as-promise/types.js'; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import type { Buffer } from 'buffer'; | ||
@@ -112,2 +113,4 @@ import type { URL } from 'url'; | ||
``` | ||
import got from 'got'; | ||
const countLimit = 10; | ||
@@ -134,2 +137,4 @@ | ||
``` | ||
import got from 'got'; | ||
const countLimit = 10; | ||
@@ -208,2 +213,4 @@ | ||
``` | ||
import got from 'got'; | ||
const countLimit = 10; | ||
@@ -240,2 +247,4 @@ | ||
``` | ||
import got from 'got'; | ||
const client = got.extend({ | ||
@@ -242,0 +251,0 @@ prefixUrl: 'https://example.com', |
{ | ||
"name": "got-cjs", | ||
"version": "12.0.4", | ||
"version": "12.3.1", | ||
"description": "Human-friendly and powerful HTTP request library for Node.js", | ||
@@ -9,2 +9,3 @@ "license": "MIT", | ||
"type": "commonjs", | ||
"types": "./dist/source/index.d.ts", | ||
"engines": { | ||
@@ -47,3 +48,3 @@ "node": ">=12" | ||
"dependencies": { | ||
"@sindresorhus/is": "^4.6.0", | ||
"@sindresorhus/is": "4.6.0", | ||
"@szmarczak/http-timer": "4.0.6", | ||
@@ -55,3 +56,3 @@ "@types/cacheable-request": "^6.0.2", | ||
"decompress-response": "^6.0.0", | ||
"form-data-encoder": "1.7.1", | ||
"form-data-encoder": "1.7.2", | ||
"get-stream": "^6.0.1", | ||
@@ -64,3 +65,3 @@ "http2-wrapper": "^2.1.10", | ||
"devDependencies": { | ||
"@hapi/bourne": "^2.0.0", | ||
"@hapi/bourne": "^3.0.0", | ||
"@sindresorhus/tsconfig": "^2.0.0", | ||
@@ -70,3 +71,3 @@ "@sinonjs/fake-timers": "^9.1.1", | ||
"@types/express": "^4.17.13", | ||
"@types/node": "^17.0.21", | ||
"@types/node": "^18.0.1", | ||
"@types/pem": "^1.9.6", | ||
@@ -80,3 +81,3 @@ "@types/pify": "^5.0.1", | ||
"ava": "^3.15.0", | ||
"axios": "^0.26.1", | ||
"axios": "^0.27.2", | ||
"benchmark": "^2.1.4", | ||
@@ -98,16 +99,15 @@ "bluebird": "^3.7.2", | ||
"pem": "^1.14.6", | ||
"pify": "^5.0.0", | ||
"readable-stream": "^3.6.0", | ||
"pify": "^6.0.0", | ||
"readable-stream": "^4.0.0", | ||
"request": "^2.88.2", | ||
"sinon": "^13.0.1", | ||
"sinon": "^14.0.0", | ||
"slow-stream": "0.0.4", | ||
"tempy": "^2.0.0", | ||
"tempy": "^3.0.0", | ||
"then-busboy": "^5.1.1", | ||
"to-readable-stream": "^3.0.0", | ||
"tough-cookie": "^4.0.0", | ||
"ts-node": "^10.7.0", | ||
"typescript": "4.6.2", | ||
"xo": "^0.48.0" | ||
"ts-node": "^10.8.2", | ||
"typescript": "^4.7.4", | ||
"xo": "^0.50.0" | ||
}, | ||
"types": "dist/source", | ||
"sideEffects": false, | ||
@@ -149,5 +149,5 @@ "ava": { | ||
"@typescript-eslint/no-empty-function": "off", | ||
"node/no-deprecated-api": "off", | ||
"node/prefer-global/url": "off", | ||
"node/prefer-global/url-search-params": "off", | ||
"n/no-deprecated-api": "off", | ||
"n/prefer-global/url": "off", | ||
"n/prefer-global/url-search-params": "off", | ||
"@typescript-eslint/no-implicit-any-catch": "off", | ||
@@ -161,2 +161,3 @@ "unicorn/prefer-node-protocol": "off", | ||
"@typescript-eslint/await-thenable": "off", | ||
"@typescript-eslint/no-redundant-type-constituents": "off", | ||
"no-lone-blocks": "off", | ||
@@ -163,0 +164,0 @@ "unicorn/no-await-expression-member": "off" |
@@ -49,3 +49,34 @@ <div align="center"> | ||
<br> | ||
<a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-light-mode-only"> | ||
<div> | ||
<img src="https://sindresorhus.com/assets/thanks/anvil-logo-light.svg" width="200" alt="Anvil"> | ||
</div> | ||
<br> | ||
<b>Paperwork that makes the data work.</b> | ||
<div> | ||
<sub> | ||
Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms. | ||
<br> | ||
The easiest way to build paperwork automation into your product. | ||
</sub> | ||
</div> | ||
</a> | ||
<a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-dark-mode-only"> | ||
<div> | ||
<img src="https://sindresorhus.com/assets/thanks/anvil-logo-dark.svg" width="200" alt="Anvil"> | ||
</div> | ||
<br> | ||
<b>Paperwork that makes the data work.</b> | ||
<div> | ||
<sub> | ||
Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms. | ||
<br> | ||
The easiest way to build paperwork automation into your product. | ||
</sub> | ||
</div> | ||
</a> | ||
<br> | ||
<br> | ||
<br> | ||
<br> | ||
</p> | ||
@@ -78,3 +109,3 @@ <br> | ||
**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you'll have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM. You can also use [Got v11](https://github.com/sindresorhus/got/tree/v11.8.3) instead which is pretty stable. | ||
**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you'll have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM. You can also use [Got v11](https://github.com/sindresorhus/got/tree/v11.8.3) instead which is pretty stable. We will backport security fixes to v11 for the foreseeable future. | ||
@@ -107,3 +138,3 @@ ## Take a peek | ||
- [Used by 6K+ packages and 3M+ repos](https://github.com/sindresorhus/got/network/dependents) | ||
- [Used by 8K+ packages and 4M+ repos](https://github.com/sindresorhus/got/network/dependents) | ||
- [Actively maintained](https://github.com/sindresorhus/got/graphs/contributors) | ||
@@ -114,2 +145,4 @@ - [Trusted by many companies](#widely-used) | ||
By default, Got will retry on failure. To disable this option, set [`options.retry.limit`](documentation/7-retry.md#retry) to 0. | ||
#### Main API | ||
@@ -123,3 +156,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) | ||
@@ -144,3 +177,3 @@ #### Timeouts and retries | ||
- [x] [Proxy support](documentation/tips.md#proxying) | ||
- [x] [Unix Domain Sockets](documentation/tips.md#unix) | ||
- [x] [Unix Domain Sockets](documentation/2-options.md#enableunixsockets) | ||
@@ -147,0 +180,0 @@ #### Integration |
263395
45
5675
560
+ Addedform-data-encoder@1.7.2(transitive)
- Removedform-data-encoder@1.7.1(transitive)
Updated@sindresorhus/is@4.6.0
Updatedform-data-encoder@1.7.2