got 12.0.0-beta.4 → 12.0.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,12 +1,15 @@
1
- import { promisify, inspect } from 'util';
2
- import { URL, URLSearchParams } from 'url';
3
- import { checkServerIdentity } from 'tls';
4
- import { request as httpRequest } from 'http';
5
- import { request as httpsRequest } from 'https';
1
+ import process from 'node:process';
2
+ import { promisify, inspect } from 'node:util';
3
+ import { URL, URLSearchParams } from 'node:url';
4
+ import { checkServerIdentity } from 'node:tls';
5
+ // DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`.
6
+ import http from 'node:http';
7
+ import https from 'node:https';
6
8
  import is, { assert } from '@sindresorhus/is';
7
9
  import lowercaseKeys from 'lowercase-keys';
8
10
  import CacheableLookup from 'cacheable-lookup';
9
11
  import http2wrapper from 'http2-wrapper';
12
+ import { isFormDataLike } from 'form-data-encoder';
10
13
  import parseLinkHeader from './parse-link-header.js';
11
14
  const [major, minor] = process.versions.node.split('.').map(v => Number(v));
12
15
  function validateSearchParameters(searchParameters) {
@@ -148,13 +151,13 @@ const defaultInternals = {
148
151
  responseType: 'text',
149
152
  url: undefined,
150
153
  pagination: {
151
- transform: (response) => {
154
+ transform(response) {
152
155
  if (response.request.options.responseType === 'json') {
153
156
  return response.body;
154
157
  }
155
158
  return JSON.parse(response.body);
156
159
  },
157
- paginate: ({ response }) => {
160
+ paginate({ response }) {
158
161
  const rawLinkHeader = response.headers.link;
159
162
  if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') {
160
163
  return false;
@@ -213,62 +216,64 @@ const cloneInternals = (internals) => {
213
216
  const cloneRaw = (raw) => {
214
217
  const { hooks, retry } = raw;
215
218
  const result = { ...raw };
216
- if (raw.context) {
219
+ if (is.object(raw.context)) {
217
220
  result.context = { ...raw.context };
218
221
  }
219
- if (raw.cacheOptions) {
222
+ if (is.object(raw.cacheOptions)) {
220
223
  result.cacheOptions = { ...raw.cacheOptions };
221
224
  }
222
- if (raw.https) {
225
+ if (is.object(raw.https)) {
223
226
  result.https = { ...raw.https };
224
227
  }
225
- if (raw.cacheOptions) {
228
+ if (is.object(raw.cacheOptions)) {
226
229
  result.cacheOptions = { ...result.cacheOptions };
227
230
  }
228
- if (raw.agent) {
231
+ if (is.object(raw.agent)) {
229
232
  result.agent = { ...raw.agent };
230
233
  }
231
- if (raw.headers) {
234
+ if (is.object(raw.headers)) {
232
235
  result.headers = { ...raw.headers };
233
236
  }
234
- if (retry) {
237
+ if (is.object(retry)) {
235
238
  result.retry = { ...retry };
236
- if (retry.errorCodes) {
239
+ if (is.array(retry.errorCodes)) {
237
240
  result.retry.errorCodes = [...retry.errorCodes];
238
241
  }
239
- if (retry.methods) {
242
+ if (is.array(retry.methods)) {
240
243
  result.retry.methods = [...retry.methods];
241
244
  }
242
- if (retry.statusCodes) {
245
+ if (is.array(retry.statusCodes)) {
243
246
  result.retry.statusCodes = [...retry.statusCodes];
244
247
  }
245
248
  }
246
- if (raw.timeout) {
249
+ if (is.object(raw.timeout)) {
247
250
  result.timeout = { ...raw.timeout };
248
251
  }
249
- if (hooks) {
250
- result.hooks = {};
251
- if (hooks.init) {
252
+ if (is.object(hooks)) {
253
+ result.hooks = {
254
+ ...hooks,
255
+ };
256
+ if (is.array(hooks.init)) {
252
257
  result.hooks.init = [...hooks.init];
253
258
  }
254
- if (hooks.beforeRequest) {
259
+ if (is.array(hooks.beforeRequest)) {
255
260
  result.hooks.beforeRequest = [...hooks.beforeRequest];
256
261
  }
257
- if (hooks.beforeError) {
262
+ if (is.array(hooks.beforeError)) {
258
263
  result.hooks.beforeError = [...hooks.beforeError];
259
264
  }
260
- if (hooks.beforeRedirect) {
265
+ if (is.array(hooks.beforeRedirect)) {
261
266
  result.hooks.beforeRedirect = [...hooks.beforeRedirect];
262
267
  }
263
- if (hooks.beforeRetry) {
268
+ if (is.array(hooks.beforeRetry)) {
264
269
  result.hooks.beforeRetry = [...hooks.beforeRetry];
265
270
  }
266
- if (hooks.afterResponse) {
271
+ if (is.array(hooks.afterResponse)) {
267
272
  result.hooks.afterResponse = [...hooks.afterResponse];
268
273
  }
269
274
  }
270
275
  // TODO: raw.searchParams
271
- if (raw.pagination) {
276
+ if (is.object(raw.pagination)) {
272
277
  result.pagination = { ...raw.pagination };
273
278
  }
274
279
  return result;
@@ -594,7 +599,7 @@ export default class Options {
594
599
 
595
600
  __Note #4__: This option is not enumerable and will not be merged with the instance defaults.
596
601
 
597
- The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
602
+ The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
598
603
 
599
604
  Since Got 12, the `content-length` is not automatically set when `body` is a `fs.createReadStream`.
600
605
  */
@@ -602,7 +607,7 @@ export default class Options {
602
607
  return this._internals.body;
603
608
  }
604
609
  set body(value) {
605
- assert.any([is.string, is.buffer, is.nodeStream, is.generator, is.asyncGenerator, is.undefined], value);
610
+ assert.any([is.string, is.buffer, is.nodeStream, is.generator, is.asyncGenerator, isFormDataLike, is.undefined], value);
606
611
  if (is.nodeStream(value)) {
607
612
  assert.truthy(value.readable);
608
613
  }
@@ -1494,6 +1499,7 @@ export default class Options {
1494
1499
  assert.any([is.number, is.undefined], value);
1495
1500
  this._internals.maxHeaderSize = value;
1496
1501
  }
1502
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1497
1503
  toJSON() {
1498
1504
  return { ...this._internals };
1499
1505
  }
@@ -1522,6 +1528,7 @@ export default class Options {
1522
1528
  ...internals.cacheOptions,
1523
1529
  ...this._unixOptions,
1524
1530
  // HTTPS options
1531
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1525
1532
  ALPNProtocols: https.alpnProtocols,
1526
1533
  ca: https.certificateAuthority,
1527
1534
  cert: https.certificate,
@@ -1576,9 +1583,9 @@ export default class Options {
1576
1583
  }
1577
1584
  return http2wrapper.auto;
1578
1585
  }
1579
- return httpsRequest;
1586
+ return https.request;
1580
1587
  }
1581
- return httpRequest;
1588
+ return http.request;
1582
1589
  }
1583
1590
  freeze() {
1584
1591
  const options = this._internals;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import type { URL } from 'url';
2
+ import type { Buffer } from 'node:buffer';
3
+ import type { URL } from 'node:url';
3
4
  import type { IncomingMessageWithTimings, Timings } from '@szmarczak/http-timer';
4
5
  import { RequestError } from './errors.js';
5
6
  import type { ParseJsonFunction, ResponseType } from './options.js';
@@ -23,17 +23,17 @@ export const parseBody = (response, responseType, parseJson, encoding) => {
23
23
  return rawBody.toString(encoding);
24
24
  }
25
25
  if (responseType === 'json') {
26
- return rawBody.length === 0 ? '' : parseJson(rawBody.toString());
26
+ return rawBody.length === 0 ? '' : parseJson(rawBody.toString(encoding));
27
27
  }
28
28
  if (responseType === 'buffer') {
29
29
  return rawBody;
30
30
  }
31
- throw new ParseError({
32
- message: `Unknown body type '${responseType}'`,
33
- name: 'Error',
34
- }, response);
35
31
  }
36
32
  catch (error) {
37
33
  throw new ParseError(error, response);
38
34
  }
35
+ throw new ParseError({
36
+ message: `Unknown body type '${responseType}'`,
37
+ name: 'Error',
38
+ }, response);
39
39
  };
@@ -1,4 +1,4 @@
1
- import { ClientRequest } from 'http';
1
+ import { ClientRequest } from 'node:http';
2
2
  declare const reentry: unique symbol;
3
3
  interface TimedOutOptions {
4
4
  host?: string;
@@ -1,4 +1,4 @@
1
- import net from 'net';
1
+ import net from 'node:net';
2
2
  import unhandler from './utils/unhandle.js';
3
3
  const reentry = Symbol('reentry');
4
4
  const noop = () => { };
@@ -1,3 +1,3 @@
1
1
  /// <reference types="node" />
2
- import { ClientRequestArgs } from 'http';
2
+ import { ClientRequestArgs } from 'node:http';
3
3
  export default function getBodySize(body: unknown, headers: ClientRequestArgs['headers']): Promise<number | undefined>;
@@ -1,4 +1,5 @@
1
- import { promisify } from 'util';
1
+ import { Buffer } from 'node:buffer';
2
+ import { promisify } from 'node:util';
2
3
  import is from '@sindresorhus/is';
3
4
  import isFormData from './is-form-data.js';
4
5
  export default async function getBodySize(body, headers) {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { Writable, Readable } from 'stream';
3
- import type { ClientRequest } from 'http';
2
+ import type { Writable, Readable } from 'node:stream';
3
+ import type { ClientRequest } from 'node:http';
4
4
  declare function isClientRequest(clientRequest: Writable | Readable): clientRequest is ClientRequest;
5
5
  export default isClientRequest;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Readable } from 'stream';
2
+ import { Readable } from 'node:stream';
3
3
  interface FormData extends Readable {
4
4
  getBoundary: () => string;
5
5
  getLength: (callback: (error: Error | null, length: number) => void) => void;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { URL } from 'url';
2
+ import { URL } from 'node:url';
3
3
  export interface URLOptions {
4
4
  href?: string;
5
5
  protocol?: string;
@@ -1,5 +1,5 @@
1
1
  /* istanbul ignore file: deprecated */
2
- import { URL } from 'url';
2
+ import { URL } from 'node:url';
3
3
  const keys = [
4
4
  'protocol',
5
5
  'host',
@@ -1,3 +1,3 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from 'events';
2
+ import { EventEmitter } from 'node:events';
3
3
  export default function proxyEvents(from: EventEmitter, to: EventEmitter, events: Readonly<string[]>): () => void;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from 'events';
2
+ import { EventEmitter } from 'node:events';
3
3
  declare type Origin = EventEmitter;
4
4
  declare type Event = string | symbol;
5
5
  declare type Fn = (...args: any[]) => void;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { URL, UrlWithStringQuery } from 'url';
2
+ import { URL, UrlWithStringQuery } from 'node:url';
3
3
  export interface LegacyUrlOptions {
4
4
  protocol: string;
5
5
  hostname: string;
@@ -4,6 +4,7 @@ export { got };
4
4
  export { default as Options } from './core/options.js';
5
5
  export * from './core/options.js';
6
6
  export * from './core/response.js';
7
+ export type { default as Request } from './core/index.js';
7
8
  export * from './core/index.js';
8
9
  export * from './core/errors.js';
9
10
  export { Delays } from './core/timed-out.js';
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import type { URL } from 'url';
2
+ import type { Buffer } from 'node:buffer';
3
+ import type { URL } from 'node:url';
3
4
  import type { CancelableRequest } from './as-promise/types.js';
4
5
  import type { Response } from './core/response.js';
5
6
  import type Options from './core/options.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "12.0.0-beta.4",
3
+ "version": "12.0.2",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",
@@ -44,60 +44,64 @@
44
44
  "ky"
45
45
  ],
46
46
  "dependencies": {
47
- "@sindresorhus/is": "^4.0.1",
48
- "@szmarczak/http-timer": "^4.0.6",
47
+ "@sindresorhus/is": "^4.6.0",
48
+ "@szmarczak/http-timer": "^5.0.1",
49
49
  "@types/cacheable-request": "^6.0.2",
50
50
  "@types/responselike": "^1.0.0",
51
- "cacheable-lookup": "^6.0.0",
51
+ "cacheable-lookup": "^6.0.4",
52
52
  "cacheable-request": "^7.0.2",
53
53
  "decompress-response": "^6.0.0",
54
+ "form-data-encoder": "1.7.1",
54
55
  "get-stream": "^6.0.1",
55
- "http2-wrapper": "^2.0.7",
56
- "lowercase-keys": "^2.0.0",
57
- "p-cancelable": "^2.1.1",
56
+ "http2-wrapper": "^2.1.10",
57
+ "lowercase-keys": "^3.0.0",
58
+ "p-cancelable": "^3.0.0",
58
59
  "responselike": "^2.0.0"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@hapi/bourne": "^2.0.0",
62
- "@sindresorhus/tsconfig": "^1.0.2",
63
- "@sinonjs/fake-timers": "^6.0.1",
63
+ "@sindresorhus/tsconfig": "^2.0.0",
64
+ "@sinonjs/fake-timers": "^9.1.1",
64
65
  "@types/benchmark": "^2.1.1",
65
66
  "@types/express": "^4.17.13",
66
- "@types/node": "^14.14.45",
67
- "@types/node-fetch": "^2.5.11",
67
+ "@types/node": "^17.0.21",
68
68
  "@types/pem": "^1.9.6",
69
69
  "@types/pify": "^5.0.1",
70
- "@types/readable-stream": "^2.3.11",
71
- "@types/request": "^2.48.6",
72
- "@types/sinon": "^9.0.9",
70
+ "@types/readable-stream": "^2.3.13",
71
+ "@types/request": "^2.48.8",
72
+ "@types/sinon": "^10.0.11",
73
+ "@types/sinonjs__fake-timers": "^8.1.1",
73
74
  "@types/tough-cookie": "^4.0.1",
74
75
  "ava": "^3.15.0",
75
- "axios": "^0.21.1",
76
+ "axios": "^0.26.1",
76
77
  "benchmark": "^2.1.4",
77
- "body-parser": "^1.19.0",
78
+ "bluebird": "^3.7.2",
79
+ "body-parser": "^1.19.2",
78
80
  "create-cert": "^1.0.6",
79
81
  "create-test-server": "^3.0.1",
80
- "del-cli": "^3.0.1",
82
+ "del-cli": "^4.0.1",
81
83
  "delay": "^5.0.0",
82
- "express": "^4.17.1",
84
+ "express": "^4.17.3",
83
85
  "form-data": "^4.0.0",
84
- "nock": "^13.1.1",
85
- "node-fetch": "^2.6.1",
86
- "np": "^7.5.0",
86
+ "formdata-node": "^4.3.2",
87
+ "nock": "^13.2.4",
88
+ "node-fetch": "^3.2.3",
89
+ "np": "^7.6.0",
87
90
  "nyc": "^15.1.0",
88
- "p-event": "^4.2.0",
89
- "pem": "^1.14.4",
91
+ "p-event": "^5.0.1",
92
+ "pem": "^1.14.6",
90
93
  "pify": "^5.0.0",
91
94
  "readable-stream": "^3.6.0",
92
95
  "request": "^2.88.2",
93
- "sinon": "^10.0.0",
96
+ "sinon": "^13.0.1",
94
97
  "slow-stream": "0.0.4",
95
- "tempy": "^1.0.1",
98
+ "tempy": "^2.0.0",
99
+ "then-busboy": "^5.1.1",
96
100
  "to-readable-stream": "^3.0.0",
97
101
  "tough-cookie": "^4.0.0",
98
- "ts-node": "^10.1.0",
99
- "typescript": "4.3.5",
100
- "xo": "^0.41.0"
102
+ "ts-node": "^10.7.0",
103
+ "typescript": "4.6.2",
104
+ "xo": "^0.48.0"
101
105
  },
102
106
  "types": "dist/source",
103
107
  "sideEffects": false,
@@ -146,7 +150,9 @@
146
150
  "@typescript-eslint/no-unsafe-return": "off",
147
151
  "@typescript-eslint/no-unsafe-assignment": "off",
148
152
  "@typescript-eslint/no-unsafe-call": "off",
149
- "@typescript-eslint/await-thenable": "off"
153
+ "@typescript-eslint/await-thenable": "off",
154
+ "no-lone-blocks": "off",
155
+ "unicorn/no-await-expression-member": "off"
150
156
  }
151
157
  },
152
158
  "runkitExampleFilename": "./documentation/examples/runkit-example.js"