got 12.0.0 → 12.0.3

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.
@@ -410,7 +410,7 @@ export default class Request extends Duplex {
410
410
  }
411
411
  let data;
412
412
  while ((data = response.read()) !== null) {
413
- this._downloadedSize += data.length;
413
+ this._downloadedSize += data.length; // eslint-disable-line @typescript-eslint/restrict-plus-operands
414
414
  const progress = this.downloadProgress;
415
415
  if (progress.percent < 1) {
416
416
  this.emit('downloadProgress', progress);
@@ -1117,7 +1117,6 @@ export default class Request extends Duplex {
1117
1117
  return this._isFromCache;
1118
1118
  }
1119
1119
  get reusedSocket() {
1120
- // @ts-expect-error `@types/node` has incomplete types
1121
1120
  return this._request?.reusedSocket;
1122
1121
  }
1123
1122
  }
@@ -2,7 +2,8 @@
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { URL, URLSearchParams } from 'node:url';
4
4
  import { checkServerIdentity } from 'node:tls';
5
- import { request as httpsRequest } from 'node:https';
5
+ import http from 'node:http';
6
+ import https from 'node:https';
6
7
  import type { Readable } from 'node:stream';
7
8
  import type { Socket } from 'node:net';
8
9
  import type { SecureContextOptions, DetailedPeerCertificate } from 'node:tls';
@@ -700,8 +701,8 @@ export default class Options {
700
701
 
701
702
  __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
702
703
  */
703
- get json(): Record<string, any> | undefined;
704
- set json(value: Record<string, any> | undefined);
704
+ get json(): unknown;
705
+ set json(value: unknown);
705
706
  /**
706
707
  The URL to request, as a string, a [`https.request` options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
707
708
 
@@ -1101,7 +1102,7 @@ export default class Options {
1101
1102
  request: RequestFunction | undefined;
1102
1103
  username: string;
1103
1104
  password: string;
1104
- json: Record<string, any> | undefined;
1105
+ json: unknown;
1105
1106
  retry: Partial<RetryOptions>;
1106
1107
  agent: Agents;
1107
1108
  h2session: http2wrapper.ClientHttp2Session | undefined;
@@ -1151,7 +1152,7 @@ export default class Options {
1151
1152
  ALPNProtocols: string[] | undefined;
1152
1153
  ca: string | Buffer | (string | Buffer)[] | undefined;
1153
1154
  cert: string | Buffer | (string | Buffer)[] | undefined;
1154
- key: string | Buffer | (Buffer | import("tls").KeyObject)[] | undefined;
1155
+ key: string | Buffer | (string | Buffer | import("tls").KeyObject)[] | undefined;
1155
1156
  passphrase: string | undefined;
1156
1157
  pfx: PfxType;
1157
1158
  rejectUnauthorized: boolean | undefined;
@@ -1174,7 +1175,7 @@ export default class Options {
1174
1175
  (hostname: string, options: import("cacheable-lookup").LookupOptions, callback: (error: NodeJS.ErrnoException | null, address: string, family: import("cacheable-lookup").IPFamily) => void): void;
1175
1176
  } | undefined;
1176
1177
  family: DnsLookupIpVersion;
1177
- agent: false | Agents | HttpAgent | undefined;
1178
+ agent: false | Agents | http.Agent | undefined;
1178
1179
  setHost: boolean;
1179
1180
  method: Method;
1180
1181
  maxHeaderSize: number | undefined;
@@ -1192,7 +1193,7 @@ export default class Options {
1192
1193
  socketPath?: string | undefined;
1193
1194
  path?: string | null | undefined;
1194
1195
  auth?: string | null | undefined;
1195
- _defaultAgent?: HttpAgent | undefined;
1196
+ _defaultAgent?: http.Agent | undefined;
1196
1197
  clientCertEngine?: string | undefined;
1197
1198
  privateKeyEngine?: string | undefined;
1198
1199
  privateKeyIdentifier?: string | undefined;
@@ -1206,8 +1207,8 @@ export default class Options {
1206
1207
  immutableMinTimeToLive?: number | undefined;
1207
1208
  ignoreCargoCult?: boolean | undefined;
1208
1209
  };
1209
- getRequestFunction(): RequestFunction | typeof httpsRequest | undefined;
1210
- getFallbackRequestFunction(): RequestFunction | typeof httpsRequest | undefined;
1210
+ getRequestFunction(): RequestFunction | typeof https.request | undefined;
1211
+ getFallbackRequestFunction(): RequestFunction | typeof https.request | undefined;
1211
1212
  freeze(): void;
1212
1213
  }
1213
1214
  export {};
@@ -2,8 +2,9 @@ import process from 'node:process';
2
2
  import { promisify, inspect } from 'node:util';
3
3
  import { URL, URLSearchParams } from 'node:url';
4
4
  import { checkServerIdentity } from 'node:tls';
5
- import { request as httpRequest } from 'node:http';
6
- import { request as httpsRequest } from 'node:https';
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';
7
8
  import is, { assert } from '@sindresorhus/is';
8
9
  import lowercaseKeys from 'lowercase-keys';
9
10
  import CacheableLookup from 'cacheable-lookup';
@@ -150,13 +151,13 @@ const defaultInternals = {
150
151
  responseType: 'text',
151
152
  url: undefined,
152
153
  pagination: {
153
- transform: (response) => {
154
+ transform(response) {
154
155
  if (response.request.options.responseType === 'json') {
155
156
  return response.body;
156
157
  }
157
158
  return JSON.parse(response.body);
158
159
  },
159
- paginate: ({ response }) => {
160
+ paginate({ response }) {
160
161
  const rawLinkHeader = response.headers.link;
161
162
  if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') {
162
163
  return false;
@@ -647,7 +648,6 @@ export default class Options {
647
648
  return this._internals.json;
648
649
  }
649
650
  set json(value) {
650
- assert.any([is.object, is.undefined], value);
651
651
  if (value !== undefined) {
652
652
  assert.undefined(this._internals.body);
653
653
  assert.undefined(this._internals.form);
@@ -1582,9 +1582,9 @@ export default class Options {
1582
1582
  }
1583
1583
  return http2wrapper.auto;
1584
1584
  }
1585
- return httpsRequest;
1585
+ return https.request;
1586
1586
  }
1587
- return httpRequest;
1587
+ return http.request;
1588
1588
  }
1589
1589
  freeze() {
1590
1590
  const options = this._internals;
@@ -23,7 +23,7 @@ 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;
@@ -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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "12.0.0",
3
+ "version": "12.0.3",
4
4
  "description": "Human-friendly and powerful HTTP request library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/got",
@@ -44,7 +44,7 @@
44
44
  "ky"
45
45
  ],
46
46
  "dependencies": {
47
- "@sindresorhus/is": "^4.2.0",
47
+ "@sindresorhus/is": "^4.6.0",
48
48
  "@szmarczak/http-timer": "^5.0.1",
49
49
  "@types/cacheable-request": "^6.0.2",
50
50
  "@types/responselike": "^1.0.0",
@@ -53,7 +53,7 @@
53
53
  "decompress-response": "^6.0.0",
54
54
  "form-data-encoder": "1.7.1",
55
55
  "get-stream": "^6.0.1",
56
- "http2-wrapper": "^2.1.9",
56
+ "http2-wrapper": "^2.1.10",
57
57
  "lowercase-keys": "^3.0.0",
58
58
  "p-cancelable": "^3.0.0",
59
59
  "responselike": "^2.0.0"
@@ -61,47 +61,47 @@
61
61
  "devDependencies": {
62
62
  "@hapi/bourne": "^2.0.0",
63
63
  "@sindresorhus/tsconfig": "^2.0.0",
64
- "@sinonjs/fake-timers": "^8.1.0",
64
+ "@sinonjs/fake-timers": "^9.1.1",
65
65
  "@types/benchmark": "^2.1.1",
66
66
  "@types/express": "^4.17.13",
67
- "@types/node": "^16.11.12",
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.12",
71
- "@types/request": "^2.48.7",
72
- "@types/sinon": "^10.0.6",
70
+ "@types/readable-stream": "^2.3.13",
71
+ "@types/request": "^2.48.8",
72
+ "@types/sinon": "^10.0.11",
73
73
  "@types/sinonjs__fake-timers": "^8.1.1",
74
74
  "@types/tough-cookie": "^4.0.1",
75
75
  "ava": "^3.15.0",
76
- "axios": "^0.24.0",
76
+ "axios": "^0.26.1",
77
77
  "benchmark": "^2.1.4",
78
78
  "bluebird": "^3.7.2",
79
- "body-parser": "^1.19.0",
79
+ "body-parser": "^1.19.2",
80
80
  "create-cert": "^1.0.6",
81
81
  "create-test-server": "^3.0.1",
82
82
  "del-cli": "^4.0.1",
83
83
  "delay": "^5.0.0",
84
- "express": "^4.17.1",
84
+ "express": "^4.17.3",
85
85
  "form-data": "^4.0.0",
86
- "formdata-node": "^4.3.1",
87
- "nock": "^13.2.1",
88
- "node-fetch": "^3.1.0",
86
+ "formdata-node": "^4.3.2",
87
+ "nock": "^13.2.4",
88
+ "node-fetch": "^3.2.3",
89
89
  "np": "^7.6.0",
90
90
  "nyc": "^15.1.0",
91
91
  "p-event": "^5.0.1",
92
- "pem": "^1.14.4",
92
+ "pem": "^1.14.6",
93
93
  "pify": "^5.0.0",
94
94
  "readable-stream": "^3.6.0",
95
95
  "request": "^2.88.2",
96
- "sinon": "^12.0.1",
96
+ "sinon": "^13.0.1",
97
97
  "slow-stream": "0.0.4",
98
98
  "tempy": "^2.0.0",
99
99
  "then-busboy": "^5.1.1",
100
100
  "to-readable-stream": "^3.0.0",
101
101
  "tough-cookie": "^4.0.0",
102
- "ts-node": "^10.4.0",
103
- "typescript": "4.5.3",
104
- "xo": "^0.47.0"
102
+ "ts-node": "^10.7.0",
103
+ "typescript": "4.6.2",
104
+ "xo": "^0.48.0"
105
105
  },
106
106
  "types": "dist/source",
107
107
  "sideEffects": false,
package/readme.md CHANGED
@@ -70,9 +70,11 @@ For browser usage, we recommend [Ky](https://github.com/sindresorhus/ky) by the
70
70
 
71
71
  ## Install
72
72
 
73
+ ```sh
74
+ npm install got
73
75
  ```
74
- $ npm install got
75
- ```
76
+
77
+ **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.
76
78
 
77
79
  ## Take a peek
78
80