Socket
Socket
Sign inDemoInstall

got

Package Overview
Dependencies
Maintainers
2
Versions
176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

got - npm Package Compare versions

Comparing version 10.2.2 to 10.3.0

1

dist/source/as-promise.d.ts
import { CancelableRequest, NormalizedOptions } from './types';
export declare function createRejection(error: Error): CancelableRequest<never>;
export default function asPromise<T>(options: NormalizedOptions): CancelableRequest<T>;

@@ -22,2 +22,12 @@ "use strict";

};
function createRejection(error) {
const promise = Promise.reject(error);
const returnPromise = () => promise;
promise.json = returnPromise;
promise.text = returnPromise;
promise.buffer = returnPromise;
promise.on = returnPromise;
return promise;
}
exports.createRejection = createRejection;
function asPromise(options) {

@@ -24,0 +34,0 @@ const proxy = new EventEmitter();

7

dist/source/create.d.ts

@@ -36,3 +36,6 @@ /// <reference types="node" />

};
interface GotFunctions {
/**
Can be used to match methods explicitly or parameters extraction: `Parameters<GotRequestMethod>`.
*/
export interface GotRequestMethod {
<T = string>(url: string | OptionsOfDefaultResponseBody, options?: OptionsOfDefaultResponseBody): CancelableRequest<Response<T>>;

@@ -52,3 +55,3 @@ (url: string | OptionsOfTextResponseBody, options?: OptionsOfTextResponseBody): CancelableRequest<Response<string>>;

}
export interface Got extends Record<HTTPAlias, GotFunctions>, GotFunctions {
export interface Got extends Record<HTTPAlias, GotRequestMethod>, GotRequestMethod {
stream: GotStream;

@@ -55,0 +58,0 @@ defaults: Defaults;

@@ -52,3 +52,3 @@ "use strict";

// @ts-ignore It's an Error not a response, but TS thinks it's calling .resolve
return Promise.reject(error);
return as_promise_1.createRejection(error);
}

@@ -61,3 +61,3 @@ }

let handlers = [...defaults._rawHandlers];
let mutableDefaults;
let isMutableDefaults;
for (const value of instancesOrOptions) {

@@ -67,3 +67,3 @@ if (isGotInstance(value)) {

handlers.push(...value.defaults._rawHandlers);
mutableDefaults = value.defaults.mutableDefaults;
isMutableDefaults = value.defaults.mutableDefaults;
}

@@ -75,3 +75,3 @@ else {

}
mutableDefaults = value.mutableDefaults;
isMutableDefaults = value.mutableDefaults;
}

@@ -86,3 +86,3 @@ }

handlers,
mutableDefaults: Boolean(mutableDefaults)
mutableDefaults: Boolean(isMutableDefaults)
});

@@ -89,0 +89,0 @@ };

declare const got: import("./create").Got;
export default got;
export * from './types';
export { Got, GotStream, ReturnStream, GotReturn } from './create';
export { Got, GotStream, ReturnStream, GotRequestMethod, GotReturn } from './create';
export { ProxyStream as ResponseStream } from './as-stream';
export { GotError, CacheError, RequestError, ParseError, HTTPError, MaxRedirectsError, UnsupportedProtocolError, TimeoutError, CancelError } from './errors';
export { GotError, CacheError, RequestError, ReadError, ParseError, HTTPError, MaxRedirectsError, UnsupportedProtocolError, TimeoutError, CancelError } from './errors';
export { InitHook, BeforeRequestHook, BeforeRedirectHook, BeforeRetryHook, BeforeErrorHook, AfterResponseHook, HookType, Hooks, HookEvent } from './known-hook-events';

@@ -88,2 +88,3 @@ "use strict";

exports.RequestError = errors_1.RequestError;
exports.ReadError = errors_1.ReadError;
exports.ParseError = errors_1.ParseError;

@@ -90,0 +91,0 @@ exports.HTTPError = errors_1.HTTPError;

@@ -279,12 +279,12 @@ "use strict";

const { headers } = options;
const noContentType = is_1.default.undefined(headers['content-type']);
const hasNoContentType = is_1.default.undefined(headers['content-type']);
{
// TODO: these checks should be moved to `preNormalizeArguments`
const isForm = !is_1.default.undefined(options.form);
const isJSON = !is_1.default.undefined(options.json);
const isJson = !is_1.default.undefined(options.json);
const isBody = !is_1.default.undefined(options.body);
if ((isBody || isForm || isJSON) && withoutBody.has(options.method)) {
if ((isBody || isForm || isJson) && withoutBody.has(options.method)) {
throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
}
if ([isBody, isForm, isJSON].filter(isTrue => isTrue).length > 1) {
if ([isBody, isForm, isJson].filter(isTrue => isTrue).length > 1) {
throw new TypeError('The `body`, `json` and `form` options are mutually exclusive');

@@ -305,3 +305,3 @@ }

// Special case for https://github.com/form-data/form-data
if (is_1.default.object(options.body) && is_form_data_1.default(options.body) && noContentType) {
if (is_1.default.object(options.body) && is_form_data_1.default(options.body) && hasNoContentType) {
headers['content-type'] = `multipart/form-data; boundary=${options.body.getBoundary()}`;

@@ -311,3 +311,3 @@ }

else if (options.form) {
if (noContentType) {
if (hasNoContentType) {
headers['content-type'] = 'application/x-www-form-urlencoded';

@@ -318,3 +318,3 @@ }

else if (options.json) {
if (noContentType) {
if (hasNoContentType) {
headers['content-type'] = 'application/json';

@@ -338,3 +338,3 @@ }

if (is_1.default.undefined(headers['content-length']) && is_1.default.undefined(headers['transfer-encoding'])) {
if ((options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH') &&
if ((options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH' || options.method === 'DELETE') &&
!is_1.default.undefined(uploadBodySize)) {

@@ -341,0 +341,0 @@ // @ts-ignore We assign if it is undefined, so this IS correct

@@ -24,3 +24,3 @@ "use strict";

const emitter = new EventEmitter();
const requestURL = options.url.toString();
const requestUrl = options.url.toString();
const redirects = [];

@@ -64,3 +64,3 @@ let retryCount = 0;

typedResponse.url = options.url.toString();
typedResponse.requestUrl = requestURL;
typedResponse.requestUrl = requestUrl;
typedResponse.retryCount = retryCount;

@@ -105,9 +105,9 @@ typedResponse.redirectUrls = redirects;

const redirectBuffer = Buffer.from(typedResponse.headers.location, 'binary').toString();
const redirectURL = new url_1.URL(redirectBuffer, options.url);
const redirectUrl = new url_1.URL(redirectBuffer, options.url);
// Redirecting to a different site, clear cookies.
if (redirectURL.hostname !== options.url.hostname && Reflect.has(options.headers, 'cookie')) {
if (redirectUrl.hostname !== options.url.hostname && Reflect.has(options.headers, 'cookie')) {
delete options.headers.cookie;
}
redirects.push(redirectURL.toString());
options.url = redirectURL;
redirects.push(redirectUrl.toString());
options.url = redirectUrl;
for (const hook of options.hooks.beforeRedirect) {

@@ -114,0 +114,0 @@ // eslint-disable-next-line no-await-in-loop

@@ -193,3 +193,3 @@ /// <reference types="node" />

export interface CancelableRequest<T extends Response | Response['body']> extends PCancelable<T>, GotEvents<CancelableRequest<T>> {
json<TReturnType>(): CancelableRequest<TReturnType>;
json<ReturnType>(): CancelableRequest<ReturnType>;
buffer(): CancelableRequest<Buffer>;

@@ -196,0 +196,0 @@ text(): CancelableRequest<string>;

/// <reference types="node" />
import { URL, UrlWithStringQuery } from 'url';
export interface LegacyURLOptions {
export interface LegacyUrlOptions {
protocol: string;

@@ -15,3 +15,3 @@ hostname: string;

}
declare const _default: (url: URL | UrlWithStringQuery) => LegacyURLOptions;
declare const _default: (url: URL | UrlWithStringQuery) => LegacyUrlOptions;
export default _default;
{
"name": "got",
"version": "10.2.2",
"version": "10.3.0",
"description": "Human-friendly and powerful HTTP request library for Node.js",

@@ -48,3 +48,3 @@ "license": "MIT",

"cacheable-lookup": "^0.2.1",
"cacheable-request": "^7.0.0",
"cacheable-request": "^7.0.1",
"decompress-response": "^5.0.0",

@@ -58,3 +58,3 @@ "duplexer3": "^0.1.4",

"to-readable-stream": "^2.0.0",
"type-fest": "^0.8.0"
"type-fest": "^0.9.0"
},

@@ -66,8 +66,8 @@ "devDependencies": {

"@types/lolex": "^5.1.0",
"@types/node": "^13.1.2",
"@types/node": "13.1.2",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^7.0.13",
"@types/tough-cookie": "^2.3.5",
"@typescript-eslint/eslint-plugin": "2.14.0",
"@typescript-eslint/parser": "2.14.0",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"ava": "^2.4.0",

@@ -89,3 +89,3 @@ "coveralls": "^3.0.4",

"proxyquire": "^2.0.1",
"sinon": "^8.0.2",
"sinon": "^8.1.1",
"slow-stream": "0.0.4",

@@ -95,3 +95,3 @@ "tempy": "^0.3.0",

"ts-node": "^8.5.2",
"typescript": "3.7.4",
"typescript": "3.7.5",
"xo": "^0.25.3"

@@ -98,0 +98,0 @@ },

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

- [Instances with custom defaults](#instances)
- [Types](#types)
- [Composable](documentation/advanced-creation.md#merging-instances)

@@ -995,2 +996,30 @@ - [Plugins](documentation/lets-make-a-plugin.md)

## Types
Got exports some handy TypeScript types and interfaces. See the type definition for all the exported types.
### Got
TypeScript will automatically infer types for Got instances, but in case you want to define something like dependencies, you can import the available types directly from Got.
```ts
import {GotRequestMethod} from 'got';
interface Dependencies {
readonly post: GotRequestMethod
}
```
### Hooks
When writing hooks, you can refer to their types to keep your interfaces consistent.
```ts
import {BeforeRequestHook} from 'got';
const addAccessToken = (accessToken: string): BeforeRequestHook => options => {
options.path = `${options.path}?access_token=${accessToken}`;
}
```
## Errors

@@ -997,0 +1026,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc