got 14.4.0 → 14.4.2

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { Buffer } from 'node:buffer';
3
2
  import type PCancelable from 'p-cancelable';
4
3
  import { RequestError } from '../core/errors.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { Timings } from '@szmarczak/http-timer';
3
2
  import type Options from './options.js';
4
3
  import type { TimeoutError as TimedOutTimeoutError } from './timed-out.js';
@@ -1,8 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- /// <reference types="node" resolution-mode="require"/>
4
- /// <reference types="node" resolution-mode="require"/>
5
- /// <reference types="node" resolution-mode="require"/>
6
1
  import { Duplex } from 'node:stream';
7
2
  import { type ClientRequest } from 'node:http';
8
3
  import type { Socket } from 'node:net';
@@ -5,8 +5,7 @@ import http, { ServerResponse } from 'node:http';
5
5
  import timer from '@szmarczak/http-timer';
6
6
  import CacheableRequest, { CacheError as CacheableCacheError, } from 'cacheable-request';
7
7
  import decompressResponse from 'decompress-response';
8
- import is from '@sindresorhus/is';
9
- import { getStreamAsBuffer } from 'get-stream';
8
+ import is, { isBuffer } from '@sindresorhus/is';
10
9
  import { FormDataEncoder, isFormData as isFormDataLike } from 'form-data-encoder';
11
10
  import getBodySize from './utils/get-body-size.js';
12
11
  import isFormData from './utils/is-form-data.js';
@@ -627,10 +626,8 @@ export default class Request extends Duplex {
627
626
  }
628
627
  try {
629
628
  // Errors are emitted via the `error` event
630
- const rawBody = await getStreamAsBuffer(from);
631
- // TODO: Switch to this:
632
- // let rawBody = await from.toArray();
633
- // rawBody = Buffer.concat(rawBody);
629
+ const fromArray = await from.toArray();
630
+ const rawBody = isBuffer(fromArray.at(0)) ? Buffer.concat(fromArray) : Buffer.from(fromArray.join(''));
634
631
  // On retry Request is destroyed with no error, therefore the above will successfully resolve.
635
632
  // So in order to check if this was really successfull, we need to check if it has been properly ended.
636
633
  if (!this.isAborted) {
@@ -794,7 +791,7 @@ export default class Request extends Duplex {
794
791
  // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
795
792
  delete headers[key];
796
793
  }
797
- else if (is.null_(headers[key])) {
794
+ else if (is.null(headers[key])) {
798
795
  throw new TypeError(`Use \`undefined\` instead of \`null\` to delete the \`${key}\` header`);
799
796
  }
800
797
  }
@@ -1,11 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- /// <reference types="node" resolution-mode="require"/>
4
- /// <reference types="node" resolution-mode="require"/>
5
- /// <reference types="node" resolution-mode="require"/>
6
- /// <reference types="node" resolution-mode="require"/>
7
- /// <reference types="node" resolution-mode="require"/>
8
- /// <reference types="node" resolution-mode="require"/>
9
1
  import type { Buffer } from 'node:buffer';
10
2
  import { checkServerIdentity, type SecureContextOptions, type DetailedPeerCertificate } from 'node:tls';
11
3
  import https, { type RequestOptions as HttpsRequestOptions, type Agent as HttpsAgent } from 'node:https';
@@ -1151,7 +1143,7 @@ export default class Options {
1151
1143
  (hostname: string, callback: (error: NodeJS.ErrnoException | null, address: string, family: import("cacheable-lookup").IPFamily) => void): void;
1152
1144
  (hostname: string, options: import("cacheable-lookup").LookupOptions & {
1153
1145
  all: true;
1154
- }, callback: (error: NodeJS.ErrnoException | null, result: readonly import("cacheable-lookup").EntryObject[]) => void): void;
1146
+ }, callback: (error: NodeJS.ErrnoException | null, result: ReadonlyArray<import("cacheable-lookup").EntryObject>) => void): void;
1155
1147
  (hostname: string, options: import("cacheable-lookup").LookupOptions, callback: (error: NodeJS.ErrnoException | null, address: string, family: import("cacheable-lookup").IPFamily) => void): void;
1156
1148
  } | undefined;
1157
1149
  dnsCache: boolean | CacheableLookup | undefined;
@@ -1203,7 +1195,7 @@ export default class Options {
1203
1195
  (hostname: string, callback: (error: NodeJS.ErrnoException | null, address: string, family: import("cacheable-lookup").IPFamily) => void): void;
1204
1196
  (hostname: string, options: import("cacheable-lookup").LookupOptions & {
1205
1197
  all: true;
1206
- }, callback: (error: NodeJS.ErrnoException | null, result: readonly import("cacheable-lookup").EntryObject[]) => void): void;
1198
+ }, callback: (error: NodeJS.ErrnoException | null, result: ReadonlyArray<import("cacheable-lookup").EntryObject>) => void): void;
1207
1199
  (hostname: string, options: import("cacheable-lookup").LookupOptions, callback: (error: NodeJS.ErrnoException | null, address: string, family: import("cacheable-lookup").IPFamily) => void): void;
1208
1200
  } | undefined;
1209
1201
  family: DnsLookupIpVersion;
@@ -1218,19 +1210,19 @@ export default class Options {
1218
1210
  h2session: http2wrapper.ClientHttp2Session | undefined;
1219
1211
  _defaultAgent?: http.Agent | undefined;
1220
1212
  auth?: string | null | undefined;
1221
- defaultPort?: string | number | undefined;
1222
- hints?: number | undefined;
1213
+ defaultPort?: number | string | undefined;
1214
+ hints?: import("dns").LookupOptions["hints"];
1223
1215
  host?: string | null | undefined;
1224
1216
  hostname?: string | null | undefined;
1225
1217
  insecureHTTPParser?: boolean | undefined;
1226
1218
  localPort?: number | undefined;
1227
1219
  path?: string | null | undefined;
1228
- port?: string | number | null | undefined;
1220
+ port?: number | string | null | undefined;
1229
1221
  protocol?: string | null | undefined;
1230
1222
  signal?: AbortSignal | undefined;
1231
1223
  socketPath?: string | undefined;
1232
- uniqueHeaders?: (string | string[])[] | undefined;
1233
- joinDuplicateHeaders?: boolean | undefined;
1224
+ uniqueHeaders?: Array<string | string[]> | undefined;
1225
+ joinDuplicateHeaders?: boolean;
1234
1226
  ALPNCallback?: ((arg: {
1235
1227
  servername: string;
1236
1228
  protocols: string[];
@@ -1243,10 +1235,10 @@ export default class Options {
1243
1235
  sessionIdContext?: string | undefined;
1244
1236
  ticketKeys?: Buffer | undefined;
1245
1237
  servername?: string | undefined;
1246
- shared?: boolean | undefined;
1247
- cacheHeuristic?: number | undefined;
1248
- immutableMinTimeToLive?: number | undefined;
1249
- ignoreCargoCult?: boolean | undefined;
1238
+ shared?: boolean;
1239
+ cacheHeuristic?: number;
1240
+ immutableMinTimeToLive?: number;
1241
+ ignoreCargoCult?: boolean;
1250
1242
  };
1251
1243
  getRequestFunction(): RequestFunction | typeof https.request | undefined;
1252
1244
  getFallbackRequestFunction(): RequestFunction | typeof https.request | undefined;
@@ -15,7 +15,7 @@ function validateSearchParameters(searchParameters) {
15
15
  // eslint-disable-next-line guard-for-in
16
16
  for (const key in searchParameters) {
17
17
  const value = searchParameters[key];
18
- assert.any([is.string, is.number, is.boolean, is.null_, is.undefined], value);
18
+ assert.any([is.string, is.number, is.boolean, is.null, is.undefined], value);
19
19
  }
20
20
  }
21
21
  const globalCache = new Map();
@@ -413,7 +413,7 @@ export default class Options {
413
413
  return this._internals.request;
414
414
  }
415
415
  set request(value) {
416
- assert.any([is.function_, is.undefined], value);
416
+ assert.any([is.function, is.undefined], value);
417
417
  this._internals.request = value;
418
418
  }
419
419
  /**
@@ -730,8 +730,8 @@ export default class Options {
730
730
  return;
731
731
  }
732
732
  let { setCookie, getCookieString } = value;
733
- assert.function_(setCookie);
734
- assert.function_(getCookieString);
733
+ assert.function(setCookie);
734
+ assert.function(getCookieString);
735
735
  /* istanbul ignore next: Horrible `tough-cookie` v3 check */
736
736
  if (setCookie.length === 4 && getCookieString.length === 0) {
737
737
  setCookie = promisify(setCookie.bind(value));
@@ -871,7 +871,7 @@ export default class Options {
871
871
  return this._internals.dnsLookup;
872
872
  }
873
873
  set dnsLookup(value) {
874
- assert.any([is.function_, is.undefined], value);
874
+ assert.any([is.function, is.undefined], value);
875
875
  this._internals.dnsLookup = value;
876
876
  }
877
877
  /**
@@ -961,7 +961,7 @@ export default class Options {
961
961
  assert.any([is.array, is.undefined], hooks);
962
962
  if (hooks) {
963
963
  for (const hook of hooks) {
964
- assert.function_(hook);
964
+ assert.function(hook);
965
965
  }
966
966
  }
967
967
  if (this._merging) {
@@ -993,7 +993,7 @@ export default class Options {
993
993
  return this._internals.followRedirect;
994
994
  }
995
995
  set followRedirect(value) {
996
- assert.any([is.boolean, is.function_], value);
996
+ assert.any([is.boolean, is.function], value);
997
997
  this._internals.followRedirect = value;
998
998
  }
999
999
  get followRedirects() {
@@ -1199,7 +1199,7 @@ export default class Options {
1199
1199
  return this._internals.parseJson;
1200
1200
  }
1201
1201
  set parseJson(value) {
1202
- assert.function_(value);
1202
+ assert.function(value);
1203
1203
  this._internals.parseJson = value;
1204
1204
  }
1205
1205
  /**
@@ -1247,7 +1247,7 @@ export default class Options {
1247
1247
  return this._internals.stringifyJson;
1248
1248
  }
1249
1249
  set stringifyJson(value) {
1250
- assert.function_(value);
1250
+ assert.function(value);
1251
1251
  this._internals.stringifyJson = value;
1252
1252
  }
1253
1253
  /**
@@ -1277,7 +1277,7 @@ export default class Options {
1277
1277
  }
1278
1278
  set retry(value) {
1279
1279
  assert.plainObject(value);
1280
- assert.any([is.function_, is.undefined], value.calculateDelay);
1280
+ assert.any([is.function, is.undefined], value.calculateDelay);
1281
1281
  assert.any([is.number, is.undefined], value.maxRetryAfter);
1282
1282
  assert.any([is.number, is.undefined], value.limit);
1283
1283
  assert.any([is.array, is.undefined], value.methods);
@@ -1331,7 +1331,7 @@ export default class Options {
1331
1331
  return this._internals.createConnection;
1332
1332
  }
1333
1333
  set createConnection(value) {
1334
- assert.any([is.function_, is.undefined], value);
1334
+ assert.any([is.function, is.undefined], value);
1335
1335
  this._internals.createConnection = value;
1336
1336
  }
1337
1337
  /**
@@ -1369,7 +1369,7 @@ export default class Options {
1369
1369
  set https(value) {
1370
1370
  assert.plainObject(value);
1371
1371
  assert.any([is.boolean, is.undefined], value.rejectUnauthorized);
1372
- assert.any([is.function_, is.undefined], value.checkServerIdentity);
1372
+ assert.any([is.function, is.undefined], value.checkServerIdentity);
1373
1373
  assert.any([is.string, is.object, is.array, is.undefined], value.certificateAuthority);
1374
1374
  assert.any([is.string, is.object, is.array, is.undefined], value.key);
1375
1375
  assert.any([is.string, is.object, is.array, is.undefined], value.certificate);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { Buffer } from 'node:buffer';
3
2
  import type { IncomingMessageWithTimings, Timings } from '@szmarczak/http-timer';
4
3
  import { RequestError } from './errors.js';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { ClientRequest } from 'node:http';
3
2
  declare const reentry: unique symbol;
4
3
  type TimedOutOptions = {
@@ -1,3 +1,2 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { ClientRequestArgs } from 'node:http';
3
2
  export default function getBodySize(body: unknown, headers: ClientRequestArgs['headers']): Promise<number | undefined>;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
1
  import type { Writable, Readable } from 'node:stream';
4
2
  import type { ClientRequest } from 'node:http';
5
3
  declare function isClientRequest(clientRequest: Writable | Readable): clientRequest is ClientRequest;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { Readable } from 'node:stream';
3
2
  type FormData = {
4
3
  getBoundary: () => string;
@@ -1,4 +1,4 @@
1
1
  import is from '@sindresorhus/is';
2
2
  export default function isFormData(body) {
3
- return is.nodeStream(body) && is.function_(body.getBoundary);
3
+ return is.nodeStream(body) && is.function(body.getBoundary);
4
4
  }
@@ -1,3 +1,2 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { EventEmitter } from 'node:events';
3
2
  export default function proxyEvents(from: EventEmitter, to: EventEmitter, events: Readonly<string[]>): () => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { EventEmitter } from 'node:events';
3
2
  type Origin = EventEmitter;
4
3
  type Event = string | symbol;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { UrlWithStringQuery } from 'node:url';
3
2
  export type LegacyUrlOptions = {
4
3
  protocol: string;
@@ -6,7 +6,7 @@ import Options from './core/options.js';
6
6
  const delay = async (ms) => new Promise(resolve => {
7
7
  setTimeout(resolve, ms);
8
8
  });
9
- const isGotInstance = (value) => is.function_(value);
9
+ const isGotInstance = (value) => is.function(value);
10
10
  const aliases = [
11
11
  'get',
12
12
  'post',
@@ -33,9 +33,9 @@ const create = (defaults) => {
33
33
  const lastHandler = (normalized) => {
34
34
  // Note: `options` is `undefined` when `new Options(...)` fails
35
35
  request.options = normalized;
36
- request._noPipe = !normalized.isStream;
36
+ request._noPipe = !normalized?.isStream;
37
37
  void request.flush();
38
- if (normalized.isStream) {
38
+ if (normalized?.isStream) {
39
39
  return request;
40
40
  }
41
41
  promise ||= asPromise(request);
@@ -45,7 +45,7 @@ const create = (defaults) => {
45
45
  const iterateHandlers = (newOptions) => {
46
46
  const handler = defaults.handlers[iteration++] ?? lastHandler;
47
47
  const result = handler(newOptions, iterateHandlers);
48
- if (is.promise(result) && !request.options.isStream) {
48
+ if (is.promise(result) && !request.options?.isStream) {
49
49
  promise ||= asPromise(request);
50
50
  if (result !== promise) {
51
51
  const descriptors = Object.getOwnPropertyDescriptors(promise);
@@ -93,10 +93,10 @@ const create = (defaults) => {
93
93
  let normalizedOptions = new Options(url, options, defaults.options);
94
94
  normalizedOptions.resolveBodyOnly = false;
95
95
  const { pagination } = normalizedOptions;
96
- assert.function_(pagination.transform);
97
- assert.function_(pagination.shouldContinue);
98
- assert.function_(pagination.filter);
99
- assert.function_(pagination.paginate);
96
+ assert.function(pagination.transform);
97
+ assert.function(pagination.shouldContinue);
98
+ assert.function(pagination.filter);
99
+ assert.function(pagination.paginate);
100
100
  assert.number(pagination.countLimit);
101
101
  assert.number(pagination.requestLimit);
102
102
  assert.number(pagination.backoff);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import type { Buffer } from 'node:buffer';
3
2
  import type { Spread } from 'type-fest';
4
3
  import type { CancelableRequest } from './as-promise/types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "14.4.0",
3
+ "version": "14.4.2",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",
@@ -48,17 +48,17 @@
48
48
  "ky"
49
49
  ],
50
50
  "dependencies": {
51
- "@sindresorhus/is": "^6.3.1",
51
+ "@sindresorhus/is": "^7.0.0",
52
52
  "@szmarczak/http-timer": "^5.0.1",
53
53
  "cacheable-lookup": "^7.0.0",
54
54
  "cacheable-request": "^12.0.1",
55
55
  "decompress-response": "^6.0.0",
56
56
  "form-data-encoder": "^4.0.2",
57
- "get-stream": "^8.0.1",
58
57
  "http2-wrapper": "^2.2.1",
59
58
  "lowercase-keys": "^3.0.0",
60
59
  "p-cancelable": "^4.0.1",
61
- "responselike": "^3.0.0"
60
+ "responselike": "^3.0.0",
61
+ "type-fest": "^4.19.0"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@hapi/bourne": "^3.0.0",
@@ -85,6 +85,7 @@
85
85
  "express": "^4.19.2",
86
86
  "form-data": "^4.0.0",
87
87
  "formdata-node": "^6.0.3",
88
+ "get-stream": "^9.0.1",
88
89
  "nock": "^13.5.4",
89
90
  "node-fetch": "^3.3.2",
90
91
  "np": "^10.0.5",
@@ -100,7 +101,6 @@
100
101
  "then-busboy": "^5.2.1",
101
102
  "tough-cookie": "^4.1.4",
102
103
  "tsx": "^4.10.4",
103
- "type-fest": "^4.8.2",
104
104
  "typescript": "^5.4.5",
105
105
  "xo": "^0.56.0"
106
106
  },
package/readme.md CHANGED
@@ -321,11 +321,11 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
321
321
  [s7]: https://www.npmjs.com/package/visionmedia?activeTab=dependents
322
322
 
323
323
  <!-- INSTALL SIZE -->
324
- [gis]: https://badgen.net/packagephobia/install/got?color=blue&label
325
- [kis]: https://badgen.net/packagephobia/install/ky?color=blue&label
326
- [nis]: https://badgen.net/packagephobia/install/node-fetch?color=blue&label
327
- [ais]: https://badgen.net/packagephobia/install/axios?color=blue&label
328
- [sis]: https://badgen.net/packagephobia/install/superagent?color=blue&label
324
+ [gis]: https://packagephobia.com/badge?p=got
325
+ [kis]: https://packagephobia.com/badge?p=ky
326
+ [nis]: https://packagephobia.com/badge?p=node-fetch
327
+ [ais]: https://packagephobia.com/badge?p=axios
328
+ [sis]: https://packagephobia.com/badge?p=superagent
329
329
 
330
330
  [g8]: https://packagephobia.com/result?p=got
331
331
  [k8]: https://packagephobia.com/result?p=ky
@@ -374,7 +374,7 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
374
374
 
375
375
  [Click here][InstallSizeOfTheDependencies] to see the install size of the Got dependencies.
376
376
 
377
- [InstallSizeOfTheDependencies]: https://packagephobia.com/result?p=@sindresorhus/is@4.0.1,@szmarczak/http-timer@4.0.5,@types/cacheable-request@6.0.1,@types/responselike@1.0.0,cacheable-lookup@6.0.0,cacheable-request@7.0.2,decompress-response@6.0.0,get-stream@6.0.1,http2-wrapper@2.0.5,lowercase-keys@2.0.0,p-cancelable@2.1.1,responselike@2.0.0
377
+ [InstallSizeOfTheDependencies]: https://packagephobia.com/result?p=@sindresorhus/is@7.0.0,@szmarczak/http-timer@5.0.1,cacheable-lookup@7.0.0,cacheable-request@12.0.1,decompress-response@6.0.0,form-data-encoder@4.0.2,http2-wrapper@2.2.1,lowercase-keys@3.0.0,p-cancelable@4.0.1,responselike@3.0.0,type-fest@4.19.0
378
378
 
379
379
  ## Maintainers
380
380
 
@@ -412,12 +412,12 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
412
412
  <tr>
413
413
  <td align="center">
414
414
  <a href="http://karaokes.moe">
415
- <img width="140" valign="middle" src="https://camo.githubusercontent.com/6860e5fa4684c14d8e1aa65df0aba4e6808ea1a9/687474703a2f2f6b6172616f6b65732e6d6f652f6173736574732f696d616765732f696e6465782e706e67">
415
+ <img width="140" valign="middle" src="https://karaokes.moe/assets/images/index.png">
416
416
  </a>
417
417
  </td>
418
418
  <td align="center">
419
419
  <a href="https://github.com/renovatebot/renovate">
420
- <img width="150" valign="middle" src="https://camo.githubusercontent.com/7c2dc41a8407d4cfa700f762a1abf46b232858ae7e3a2bf5aee7d9f36416127c/68747470733a2f2f6170702e72656e6f76617465626f742e636f6d2f696d616765732f72656e6f766174655f3636305f3232302e6a7067">
420
+ <img width="150" valign="middle" src="https://avatars.githubusercontent.com/u/38656520?s=200&v=4">
421
421
  </a>
422
422
  </td>
423
423
  <td align="center">
@@ -442,11 +442,6 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
442
442
  <img width="150" valign="middle" src="https://user-images.githubusercontent.com/29518613/91814036-97fb9500-ec44-11ea-8c6c-d198cc23ca29.png">
443
443
  </a>
444
444
  </td>
445
- <td align="center">
446
- <a href="https://apify.com">
447
- <img width="150" valign="middle" src="https://user-images.githubusercontent.com/23726914/128673143-958b5930-b677-40ef-8087-5698a0c29c45.png">
448
- </a>
449
- </td>
450
445
  </tr>
451
446
  </tbody>
452
447
  </table>
@@ -496,7 +491,3 @@ By default, Got will retry on failure. To disable this option, set [`options.ret
496
491
  > We’re using Got at Radity. Thanks for such an amazing work!
497
492
  >
498
493
  > — <a href="https://github.com/MirzayevFarid">Mirzayev Farid</a>
499
-
500
- > Got has been a crucial component of Apify's scraping for years. We use it to extract data from billions of web pages every month, and we really appreciate the powerful API and extensibility, which allowed us to build our own specialized HTTP client on top of Got. The support has always been stellar too.
501
- >
502
- > — <a href="https://github.com/mnmkng">Ondra Urban</a>