got 12.6.0 → 13.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.
@@ -4,7 +4,6 @@
4
4
  /// <reference types="node" resolution-mode="require"/>
5
5
  /// <reference types="node" resolution-mode="require"/>
6
6
  import { Duplex } from 'node:stream';
7
- import { URL } from 'node:url';
8
7
  import type { ClientRequest } from 'node:http';
9
8
  import type { Socket } from 'node:net';
10
9
  import type { Timings } from '@szmarczak/http-timer';
@@ -107,7 +106,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
107
106
  private _isFromCache?;
108
107
  private _cannotHaveBody;
109
108
  private _triggerRead;
110
- private _jobs;
109
+ private readonly _jobs;
111
110
  private _cancelTimeouts;
112
111
  private readonly _removeListeners;
113
112
  private _nativeResponse?;
@@ -1,13 +1,12 @@
1
1
  import process from 'node:process';
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { Duplex } from 'node:stream';
4
- import { URL, URLSearchParams } from 'node:url';
5
4
  import http, { ServerResponse } from 'node:http';
6
5
  import timer from '@szmarczak/http-timer';
7
6
  import CacheableRequest, { CacheError as CacheableCacheError, } from 'cacheable-request';
8
7
  import decompressResponse from 'decompress-response';
9
8
  import is from '@sindresorhus/is';
10
- import { buffer as getBuffer } from 'get-stream';
9
+ import getStream from 'get-stream';
11
10
  import { FormDataEncoder, isFormData as isFormDataLike } from 'form-data-encoder';
12
11
  import getBodySize from './utils/get-body-size.js';
13
12
  import isFormData from './utils/is-form-data.js';
@@ -21,6 +20,7 @@ import { isResponseOk } from './response.js';
21
20
  import isClientRequest from './utils/is-client-request.js';
22
21
  import isUnixSocketURL from './utils/is-unix-socket-url.js';
23
22
  import { RequestError, ReadError, MaxRedirectsError, HTTPError, TimeoutError, UploadError, CacheError, AbortError, } from './errors.js';
23
+ const { buffer: getStreamAsBuffer } = getStream;
24
24
  const supportsBrotli = is.string(process.versions.brotli);
25
25
  const methodsWithoutBody = new Set(['GET', 'HEAD']);
26
26
  const cacheableStore = new WeakableMap();
@@ -210,8 +210,8 @@ export default class Request extends Duplex {
210
210
  this.redirectUrls = [];
211
211
  this.retryCount = 0;
212
212
  this._stopRetry = noop;
213
- this.on('pipe', source => {
214
- if (source.headers) {
213
+ this.on('pipe', (source) => {
214
+ if (source?.headers) {
215
215
  Object.assign(this.options.headers, source.headers);
216
216
  }
217
217
  });
@@ -267,7 +267,7 @@ export default class Request extends Duplex {
267
267
  else {
268
268
  this.options.signal.addEventListener('abort', abort);
269
269
  this._removeListeners = () => {
270
- this.options.signal.removeEventListener('abort', abort);
270
+ this.options.signal?.removeEventListener('abort', abort);
271
271
  };
272
272
  }
273
273
  }
@@ -749,7 +749,10 @@ export default class Request extends Duplex {
749
749
  }
750
750
  try {
751
751
  // Errors are emitted via the `error` event
752
- const rawBody = await getBuffer(from);
752
+ const rawBody = await getStreamAsBuffer(from);
753
+ // TODO: Switch to this:
754
+ // let rawBody = await from.toArray();
755
+ // rawBody = Buffer.concat(rawBody);
753
756
  // On retry Request is destroyed with no error, therefore the above will successfully resolve.
754
757
  // So in order to check if this was really successfull, we need to check if it has been properly ended.
755
758
  if (!this.isAborted) {
@@ -843,7 +846,6 @@ export default class Request extends Duplex {
843
846
  // We only need to implement the error handler in order to support HTTP2 caching.
844
847
  // The result will be a promise anyway.
845
848
  // @ts-expect-error ignore
846
- // eslint-disable-next-line @typescript-eslint/promise-function-async
847
849
  result.once = (event, handler) => {
848
850
  if (event === 'error') {
849
851
  (async () => {
@@ -8,7 +8,6 @@
8
8
  /// <reference types="node" resolution-mode="require"/>
9
9
  /// <reference types="node" resolution-mode="require"/>
10
10
  import type { Buffer } from 'node:buffer';
11
- import { URL, URLSearchParams } from 'node:url';
12
11
  import { checkServerIdentity } from 'node:tls';
13
12
  import http from 'node:http';
14
13
  import https from 'node:https';
@@ -567,7 +566,7 @@ export type OptionsInit = Except<Partial<InternalsType>, 'hooks' | 'retry'> & {
567
566
  };
568
567
  export default class Options {
569
568
  private _unixOptions?;
570
- private _internals;
569
+ private readonly _internals;
571
570
  private _merging;
572
571
  private readonly _init;
573
572
  constructor(input?: string | URL | OptionsInit, options?: OptionsInit, defaults?: Options);
@@ -741,8 +740,6 @@ export default class Options {
741
740
  /**
742
741
  You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
743
742
 
744
- *Requires Node.js 16 or later.*
745
-
746
743
  @example
747
744
  ```
748
745
  import got from 'got';
@@ -758,8 +755,8 @@ export default class Options {
758
755
  }, 100);
759
756
  ```
760
757
  */
761
- get signal(): any | undefined;
762
- set signal(value: any | undefined);
758
+ get signal(): AbortSignal | undefined;
759
+ set signal(value: AbortSignal | undefined);
763
760
  /**
764
761
  Ignore invalid cookies instead of throwing an error.
765
762
  Only useful when the `cookieJar` option has been set. Not recommended.
@@ -1147,7 +1144,7 @@ export default class Options {
1147
1144
  form: Record<string, any> | undefined;
1148
1145
  url: string | URL | undefined;
1149
1146
  cookieJar: PromiseCookieJar | ToughCookieJar | undefined;
1150
- signal: any;
1147
+ signal: AbortSignal | undefined;
1151
1148
  ignoreInvalidCookies: boolean;
1152
1149
  searchParams: string | SearchParameters | URLSearchParams | undefined;
1153
1150
  dnsLookup: {
@@ -1235,6 +1232,7 @@ export default class Options {
1235
1232
  signal?: AbortSignal | undefined;
1236
1233
  socketPath?: string | undefined;
1237
1234
  uniqueHeaders?: (string | string[])[] | undefined;
1235
+ joinDuplicateHeaders?: boolean | undefined;
1238
1236
  clientCertEngine?: string | undefined;
1239
1237
  privateKeyEngine?: string | undefined;
1240
1238
  privateKeyIdentifier?: string | undefined;
@@ -1,6 +1,5 @@
1
1
  import process from 'node:process';
2
2
  import { promisify, inspect } from 'node:util';
3
- import { URL, URLSearchParams } from 'node:url';
4
3
  import { checkServerIdentity } from 'node:tls';
5
4
  // DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`.
6
5
  import http from 'node:http';
@@ -181,7 +180,7 @@ const defaultInternals = {
181
180
  setHost: true,
182
181
  maxHeaderSize: undefined,
183
182
  signal: undefined,
184
- enableUnixSockets: true,
183
+ enableUnixSockets: false,
185
184
  };
186
185
  const cloneInternals = (internals) => {
187
186
  const { hooks, retry } = internals;
@@ -408,7 +407,12 @@ export default class Options {
408
407
  throw new Error(`Unexpected option: ${key}`);
409
408
  }
410
409
  // @ts-expect-error Type 'unknown' is not assignable to type 'never'.
411
- this[key] = options[key];
410
+ const value = options[key];
411
+ if (value === undefined) {
412
+ continue;
413
+ }
414
+ // @ts-expect-error Type 'unknown' is not assignable to type 'never'.
415
+ this[key] = value;
412
416
  push = true;
413
417
  }
414
418
  if (push) {
@@ -764,8 +768,6 @@ export default class Options {
764
768
  /**
765
769
  You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
766
770
 
767
- *Requires Node.js 16 or later.*
768
-
769
771
  @example
770
772
  ```
771
773
  import got from 'got';
@@ -781,11 +783,9 @@ export default class Options {
781
783
  }, 100);
782
784
  ```
783
785
  */
784
- // TODO: Replace `any` with `AbortSignal` when targeting Node 16.
785
786
  get signal() {
786
787
  return this._internals.signal;
787
788
  }
788
- // TODO: Replace `any` with `AbortSignal` when targeting Node 16.
789
789
  set signal(value) {
790
790
  assert.object(value);
791
791
  this._internals.signal = value;
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  import type { Buffer } from 'node:buffer';
4
- import type { URL } from 'node:url';
5
4
  import type { IncomingMessageWithTimings, Timings } from '@szmarczak/http-timer';
6
5
  import { RequestError } from './errors.js';
7
6
  import type { ParseJsonFunction, ResponseType } from './options.js';
@@ -55,13 +55,13 @@ export default function timedOut(request, delays, options) {
55
55
  throw error;
56
56
  }
57
57
  });
58
- if (typeof delays.request !== 'undefined') {
58
+ if (delays.request !== undefined) {
59
59
  const cancelTimeout = addTimeout(delays.request, timeoutHandler, 'request');
60
60
  once(request, 'response', (response) => {
61
61
  once(response, 'end', cancelTimeout);
62
62
  });
63
63
  }
64
- if (typeof delays.socket !== 'undefined') {
64
+ if (delays.socket !== undefined) {
65
65
  const { socket } = delays;
66
66
  const socketTimeoutHandler = () => {
67
67
  timeoutHandler(socket, 'socket');
@@ -74,17 +74,17 @@ export default function timedOut(request, delays, options) {
74
74
  request.removeListener('timeout', socketTimeoutHandler);
75
75
  });
76
76
  }
77
- const hasLookup = typeof delays.lookup !== 'undefined';
78
- const hasConnect = typeof delays.connect !== 'undefined';
79
- const hasSecureConnect = typeof delays.secureConnect !== 'undefined';
80
- const hasSend = typeof delays.send !== 'undefined';
77
+ const hasLookup = delays.lookup !== undefined;
78
+ const hasConnect = delays.connect !== undefined;
79
+ const hasSecureConnect = delays.secureConnect !== undefined;
80
+ const hasSend = delays.send !== undefined;
81
81
  if (hasLookup || hasConnect || hasSecureConnect || hasSend) {
82
82
  once(request, 'socket', (socket) => {
83
83
  const { socketPath } = request;
84
84
  /* istanbul ignore next: hard to test */
85
85
  if (socket.connecting) {
86
86
  const hasPath = Boolean(socketPath ?? net.isIP(hostname ?? host ?? '') !== 0);
87
- if (hasLookup && !hasPath && typeof socket.address().address === 'undefined') {
87
+ if (hasLookup && !hasPath && socket.address().address === undefined) {
88
88
  const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
89
89
  once(socket, 'lookup', cancelTimeout);
90
90
  }
@@ -122,13 +122,13 @@ export default function timedOut(request, delays, options) {
122
122
  }
123
123
  });
124
124
  }
125
- if (typeof delays.response !== 'undefined') {
125
+ if (delays.response !== undefined) {
126
126
  once(request, 'upload-complete', () => {
127
127
  const cancelTimeout = addTimeout(delays.response, timeoutHandler, 'response');
128
128
  once(request, 'response', cancelTimeout);
129
129
  });
130
130
  }
131
- if (typeof delays.read !== 'undefined') {
131
+ if (delays.read !== undefined) {
132
132
  once(request, 'response', (response) => {
133
133
  const cancelTimeout = addTimeout(delays.read, timeoutHandler, 'read');
134
134
  once(response, 'end', cancelTimeout);
@@ -1,3 +1,2 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { URL } from 'url';
3
2
  export default function isUnixSocketURL(url: URL): boolean;
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import { URL } from 'node:url';
3
2
  export type URLOptions = {
4
3
  href?: string;
5
4
  protocol?: string;
@@ -1,5 +1,3 @@
1
- /* istanbul ignore file: deprecated */
2
- import { URL } from 'node:url';
3
1
  const keys = [
4
2
  'protocol',
5
3
  'host',
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { URL, UrlWithStringQuery } from 'node:url';
2
+ import type { UrlWithStringQuery } from 'node:url';
3
3
  export type LegacyUrlOptions = {
4
4
  protocol: string;
5
5
  hostname: string;
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  import type { Buffer } from 'node:buffer';
4
- import type { URL } from 'node:url';
5
4
  import type { CancelableRequest } from './as-promise/types.js';
6
5
  import type { Response } from './core/response.js';
7
6
  import type Options from './core/options.js';
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "12.6.0",
3
+ "version": "13.0.0",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",
7
7
  "funding": "https://github.com/sindresorhus/got?sponsor=1",
8
8
  "type": "module",
9
- "exports": "./dist/source/index.js",
10
- "types": "./dist/source/index.d.ts",
9
+ "exports": {
10
+ "types": "./dist/source/index.d.ts",
11
+ "default": "./dist/source/index.js"
12
+ },
11
13
  "engines": {
12
- "node": ">=14.16"
14
+ "node": ">=16"
13
15
  },
14
16
  "scripts": {
15
17
  "test": "xo && tsc --noEmit && ava",
@@ -99,8 +101,8 @@
99
101
  "tough-cookie": "4.1.2",
100
102
  "ts-node": "^10.8.2",
101
103
  "type-fest": "^3.6.1",
102
- "typescript": "~4.9.5",
103
- "xo": "^0.53.1"
104
+ "typescript": "^5.0.4",
105
+ "xo": "^0.54.2"
104
106
  },
105
107
  "sideEffects": false,
106
108
  "ava": {
@@ -135,10 +137,7 @@
135
137
  "rules": {
136
138
  "@typescript-eslint/no-empty-function": "off",
137
139
  "n/no-deprecated-api": "off",
138
- "n/prefer-global/url": "off",
139
- "n/prefer-global/url-search-params": "off",
140
140
  "@typescript-eslint/no-implicit-any-catch": "off",
141
- "unicorn/prefer-node-protocol": "off",
142
141
  "ava/assertion-arguments": "off",
143
142
  "@typescript-eslint/no-unsafe-member-access": "off",
144
143
  "@typescript-eslint/no-unsafe-return": "off",
@@ -146,6 +145,8 @@
146
145
  "@typescript-eslint/no-unsafe-call": "off",
147
146
  "@typescript-eslint/await-thenable": "off",
148
147
  "@typescript-eslint/no-redundant-type-constituents": "off",
148
+ "@typescript-eslint/no-unsafe-argument": "off",
149
+ "@typescript-eslint/promise-function-async": "off",
149
150
  "no-lone-blocks": "off",
150
151
  "unicorn/no-await-expression-member": "off"
151
152
  }
package/readme.md CHANGED
@@ -29,38 +29,42 @@
29
29
  <br>
30
30
  <br>
31
31
  <br>
32
- <a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-light-mode-only">
32
+ <a href="https://serpapi.com#gh-light-mode-only">
33
33
  <div>
34
- <img src="https://sindresorhus.com/assets/thanks/anvil-logo-light.svg" width="200" alt="Anvil">
34
+ <img src="https://sindresorhus.com/assets/thanks/serpapi-logo-light.svg" width="130" alt="SerpApi">
35
35
  </div>
36
- <br>
37
- <b>Paperwork that makes the data work.</b>
36
+ <b>API to get search engine results with ease.</b>
37
+ </a>
38
+ <a href="https://serpapi.com#gh-dark-mode-only">
38
39
  <div>
39
- <sub>
40
- Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
41
- <br>
42
- The easiest way to build paperwork automation into your product.
43
- </sub>
40
+ <img src="https://sindresorhus.com/assets/thanks/serpapi-logo-dark.svg" width="120" alt="SerpApi">
44
41
  </div>
42
+ <b>API to get search engine results with ease.</b>
45
43
  </a>
46
- <a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-dark-mode-only">
44
+ <br>
45
+ <br>
46
+ <br>
47
+ <br>
48
+ <a href="https://dutchis.net/?ref=sindresorhus#gh-light-mode-only">
47
49
  <div>
48
- <img src="https://sindresorhus.com/assets/thanks/anvil-logo-dark.svg" width="200" alt="Anvil">
50
+ <img src="https://sindresorhus.com/assets/thanks/dutchis-logo-light.png" width="200" alt="DutchIS">
49
51
  </div>
50
52
  <br>
51
- <b>Paperwork that makes the data work.</b>
53
+ <b>VPS hosting with taste 😛</b>
54
+ </a>
55
+ <a href="https://dutchis.net/?ref=sindresorhus#gh-dark-mode-only">
52
56
  <div>
53
- <sub>
54
- Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
55
- <br>
56
- The easiest way to build paperwork automation into your product.
57
- </sub>
57
+ <img src="https://sindresorhus.com/assets/thanks/dutchis-logo-dark.png" width="200" alt="DutchIS">
58
58
  </div>
59
+ <br>
60
+ <b>VPS hosting with taste 😛</b>
59
61
  </a>
60
62
  <br>
61
63
  <br>
62
64
  <br>
63
65
  <br>
66
+ <br>
67
+ <br>
64
68
  </p>
65
69
  <br>
66
70
  <br>
@@ -90,7 +94,7 @@ npm install got
90
94
 
91
95
  **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 will 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.
92
96
 
93
- **Got v11 (the previous major version) is no longer maintained and we will not accept any backport requests.**
97
+ **Got v11 is no longer maintained and we will not accept any backport requests.**
94
98
 
95
99
  ## Take a peek
96
100
 
@@ -199,7 +203,7 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
199
203
  | Pagination API | :heavy_check_mark: | :x: | :x: | :x: | :x: |
200
204
  | Request cancelation | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
201
205
  | RFC compliant caching | :heavy_check_mark: | :x: | :x: | :x: | :x: |
202
- | Cookies (out-of-box) | :heavy_check_mark: | :x: | :x: | :x: | :x: |
206
+ | Cookies (out-of-the-box) | :heavy_check_mark: | :x: | :x: | :x: | :x: |
203
207
  | Follows redirects | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
204
208
  | Retries on failure | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: | :heavy_check_mark: |
205
209
  | Progress events | :heavy_check_mark: | :x: | :heavy_check_mark:\*\*\* | Browser only | :heavy_check_mark: |
@@ -305,13 +309,13 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
305
309
  [gbg]: https://img.shields.io/github/issues-raw/sindresorhus/got/bug?color=darkred&label
306
310
  [kbg]: https://img.shields.io/github/issues-raw/sindresorhus/ky/bug?color=darkred&label
307
311
  [nbg]: https://img.shields.io/github/issues-raw/bitinn/node-fetch/bug?color=darkred&label
308
- [abg]: https://img.shields.io/github/issues-raw/axios/axios/type:confirmed%20bug?color=darkred&label
312
+ [abg]: https://img.shields.io/github/issues-raw/axios/axios/bug-fix?color=darkred&label
309
313
  [sbg]: https://img.shields.io/github/issues-raw/visionmedia/superagent/Bug?color=darkred&label
310
314
 
311
315
  [g6]: https://github.com/sindresorhus/got/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug
312
316
  [k6]: https://github.com/sindresorhus/ky/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug
313
317
  [n6]: https://github.com/bitinn/node-fetch/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Abug
314
- [a6]: https://github.com/axios/axios/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22type%3Aconfirmed+bug%22
318
+ [a6]: https://github.com/axios/axios/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22bug-fix%22
315
319
  [s6]: https://github.com/visionmedia/superagent/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3ABug
316
320
 
317
321
  <!-- DEPENDENTS -->
@@ -432,7 +436,7 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
432
436
  </td>
433
437
  <td align="center">
434
438
  <a href="https://github.com/renovatebot/renovate">
435
- <img width="150" valign="middle" src="https://camo.githubusercontent.com/206d470ac709b9a702a97b0c08d6f389a086793d/68747470733a2f2f72656e6f76617465626f742e636f6d2f696d616765732f6c6f676f2e737667">
439
+ <img width="150" valign="middle" src="https://camo.githubusercontent.com/7c2dc41a8407d4cfa700f762a1abf46b232858ae7e3a2bf5aee7d9f36416127c/68747470733a2f2f6170702e72656e6f76617465626f742e636f6d2f696d616765732f72656e6f766174655f3636305f3232302e6a7067">
436
440
  </a>
437
441
  </td>
438
442
  <td align="center">