got 12.0.1 → 12.0.4

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.
@@ -121,8 +121,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
121
121
  end?: boolean;
122
122
  }): T;
123
123
  unpipe<T extends NodeJS.WritableStream>(destination: T): this;
124
- private _lockWrite;
125
- private _unlockWrite;
126
124
  private _finalizeBody;
127
125
  private _onResponseBase;
128
126
  private _setRawBody;
@@ -201,24 +201,6 @@ export default class Request extends Duplex {
201
201
  this.redirectUrls = [];
202
202
  this.retryCount = 0;
203
203
  this._stopRetry = noop;
204
- const unlockWrite = () => {
205
- this._unlockWrite();
206
- };
207
- const lockWrite = () => {
208
- this._lockWrite();
209
- };
210
- this.on('pipe', (source) => {
211
- source.prependListener('data', unlockWrite);
212
- source.on('data', lockWrite);
213
- source.prependListener('end', unlockWrite);
214
- source.on('end', lockWrite);
215
- });
216
- this.on('unpipe', (source) => {
217
- source.off('data', unlockWrite);
218
- source.off('data', lockWrite);
219
- source.off('end', unlockWrite);
220
- source.off('end', lockWrite);
221
- });
222
204
  this.on('pipe', source => {
223
205
  if (source.headers) {
224
206
  Object.assign(this.options.headers, source.headers);
@@ -250,12 +232,9 @@ export default class Request extends Duplex {
250
232
  };
251
233
  return;
252
234
  }
253
- const { json, body, form } = this.options;
254
- if (json || body || form) {
255
- this._lockWrite();
256
- }
257
235
  // Important! If you replace `body` in a handler with another stream, make sure it's readable first.
258
236
  // The below is run only once.
237
+ const { body } = this.options;
259
238
  if (is.nodeStream(body)) {
260
239
  body.once('error', error => {
261
240
  if (this._flushed) {
@@ -410,7 +389,7 @@ export default class Request extends Duplex {
410
389
  }
411
390
  let data;
412
391
  while ((data = response.read()) !== null) {
413
- this._downloadedSize += data.length;
392
+ this._downloadedSize += data.length; // eslint-disable-line @typescript-eslint/restrict-plus-operands
414
393
  const progress = this.downloadProgress;
415
394
  if (progress.percent < 1) {
416
395
  this.emit('downloadProgress', progress);
@@ -492,17 +471,6 @@ export default class Request extends Duplex {
492
471
  super.unpipe(destination);
493
472
  return this;
494
473
  }
495
- _lockWrite() {
496
- const onLockedWrite = () => {
497
- throw new TypeError('The payload has been already provided');
498
- };
499
- this.write = onLockedWrite;
500
- this.end = onLockedWrite;
501
- }
502
- _unlockWrite() {
503
- this.write = super.write;
504
- this.end = super.end;
505
- }
506
474
  async _finalizeBody() {
507
475
  const { options } = this;
508
476
  const { headers } = options;
@@ -563,12 +531,6 @@ export default class Request extends Duplex {
563
531
  headers['content-length'] = String(uploadBodySize);
564
532
  }
565
533
  }
566
- else if (cannotHaveBody) {
567
- this._lockWrite();
568
- }
569
- else {
570
- this._unlockWrite();
571
- }
572
534
  if (options.responseType === 'json' && !('accept' in options.headers)) {
573
535
  options.headers.accept = 'application/json';
574
536
  }
@@ -829,17 +791,12 @@ export default class Request extends Duplex {
829
791
  }
830
792
  })();
831
793
  }
832
- else {
833
- this._unlockWrite();
834
- if (!is.undefined(body)) {
835
- this._writeRequest(body, undefined, () => { });
836
- currentRequest.end();
837
- this._lockWrite();
838
- }
839
- else if (this._cannotHaveBody || this._noPipe) {
840
- currentRequest.end();
841
- this._lockWrite();
842
- }
794
+ else if (!is.undefined(body)) {
795
+ this._writeRequest(body, undefined, () => { });
796
+ currentRequest.end();
797
+ }
798
+ else if (this._cannotHaveBody || this._noPipe) {
799
+ currentRequest.end();
843
800
  }
844
801
  }
845
802
  _prepareCache(cache) {
@@ -1117,7 +1074,6 @@ export default class Request extends Duplex {
1117
1074
  return this._isFromCache;
1118
1075
  }
1119
1076
  get reusedSocket() {
1120
- // @ts-expect-error `@types/node` has incomplete types
1121
1077
  return this._request?.reusedSocket;
1122
1078
  }
1123
1079
  }
@@ -701,8 +701,8 @@ export default class Options {
701
701
 
702
702
  __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
703
703
  */
704
- get json(): Record<string, any> | undefined;
705
- set json(value: Record<string, any> | undefined);
704
+ get json(): unknown;
705
+ set json(value: unknown);
706
706
  /**
707
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).
708
708
 
@@ -1102,7 +1102,7 @@ export default class Options {
1102
1102
  request: RequestFunction | undefined;
1103
1103
  username: string;
1104
1104
  password: string;
1105
- json: Record<string, any> | undefined;
1105
+ json: unknown;
1106
1106
  retry: Partial<RetryOptions>;
1107
1107
  agent: Agents;
1108
1108
  h2session: http2wrapper.ClientHttp2Session | undefined;
@@ -1152,7 +1152,7 @@ export default class Options {
1152
1152
  ALPNProtocols: string[] | undefined;
1153
1153
  ca: string | Buffer | (string | Buffer)[] | undefined;
1154
1154
  cert: string | Buffer | (string | Buffer)[] | undefined;
1155
- key: string | Buffer | (Buffer | import("tls").KeyObject)[] | undefined;
1155
+ key: string | Buffer | (string | Buffer | import("tls").KeyObject)[] | undefined;
1156
1156
  passphrase: string | undefined;
1157
1157
  pfx: PfxType;
1158
1158
  rejectUnauthorized: boolean | undefined;
@@ -151,13 +151,13 @@ const defaultInternals = {
151
151
  responseType: 'text',
152
152
  url: undefined,
153
153
  pagination: {
154
- transform: (response) => {
154
+ transform(response) {
155
155
  if (response.request.options.responseType === 'json') {
156
156
  return response.body;
157
157
  }
158
158
  return JSON.parse(response.body);
159
159
  },
160
- paginate: ({ response }) => {
160
+ paginate({ response }) {
161
161
  const rawLinkHeader = response.headers.link;
162
162
  if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') {
163
163
  return false;
@@ -648,7 +648,6 @@ export default class Options {
648
648
  return this._internals.json;
649
649
  }
650
650
  set json(value) {
651
- assert.any([is.object, is.undefined], value);
652
651
  if (value !== undefined) {
653
652
  assert.undefined(this._internals.body);
654
653
  assert.undefined(this._internals.form);
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "got",
3
- "version": "12.0.1",
3
+ "version": "12.0.4",
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