rekwest 3.3.4 → 4.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.
package/README.md CHANGED
@@ -21,7 +21,7 @@ and [http2.request](https://nodejs.org/api/http2.html#http2_clienthttp2session_r
21
21
 
22
22
  ## Prerequisites
23
23
 
24
- * Node.js `>= 16.5.x`
24
+ * Node.js `>= 16.7.x`
25
25
 
26
26
  ## Installation
27
27
 
@@ -122,7 +122,8 @@ console.log(res.body);
122
122
  and [tls.ConnectionOptions](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback)
123
123
  for HTTP/2 attunes
124
124
  * `body` **{string | Array | ArrayBuffer | ArrayBufferView | AsyncIterator | Blob | Buffer | DataView | File |
125
- FormData | Iterator | Object | Readable | SharedArrayBuffer | URLSearchParams}** The body to send with the request
125
+ FormData | Iterator | Object | Readable | ReadableStream | SharedArrayBuffer | URLSearchParams}** The body to send
126
+ with the request
126
127
  * `cookies` **{boolean | Array<[k, v]> | Cookies | Object | URLSearchParams}** `Default: true` The cookies to add to
127
128
  the request
128
129
  * `digest` **{boolean}** `Default: true` Controls whether to read the response stream or simply add a mixin
@@ -179,7 +180,7 @@ The method with limited functionality to use with streams and/or pipes
179
180
  * No automata
180
181
  * No redirects
181
182
  * Pass `h2: true` in options to use HTTP/2 protocol
182
- * Or use `ackn({ url: URL })` method in advance to probe the available protocols
183
+ * Use `ackn({ url: URL })` method beforehand to check the available protocols
183
184
 
184
185
  ---
185
186
 
package/dist/ackn.js CHANGED
@@ -2,14 +2,13 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.ackn = void 0;
5
-
6
5
  var _nodeTls = require("node:tls");
7
-
8
6
  const ackn = options => new Promise((resolve, reject) => {
9
7
  const {
10
8
  url
11
9
  } = options;
12
- const socket = (0, _nodeTls.connect)({ ...options,
10
+ const socket = (0, _nodeTls.connect)({
11
+ ...options,
13
12
  ALPNProtocols: ['h2', 'http/1.1'],
14
13
  host: url.hostname,
15
14
  port: parseInt(url.port) || 443,
@@ -20,13 +19,12 @@ const ackn = options => new Promise((resolve, reject) => {
20
19
  const {
21
20
  alpnProtocol
22
21
  } = socket;
23
- resolve({ ...options,
22
+ resolve({
23
+ ...options,
24
24
  alpnProtocol,
25
-
26
25
  createConnection() {
27
26
  return socket;
28
27
  },
29
-
30
28
  h2: /h2c?/.test(alpnProtocol),
31
29
  protocol: url.protocol
32
30
  });
@@ -34,5 +32,4 @@ const ackn = options => new Promise((resolve, reject) => {
34
32
  socket.on('error', reject);
35
33
  socket.on('timeout', reject);
36
34
  });
37
-
38
35
  exports.ackn = ackn;
package/dist/cookies.js CHANGED
@@ -2,29 +2,21 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.Cookies = void 0;
5
-
6
- var _utils = require("./utils.js");
7
-
5
+ var _utils = require("./utils");
8
6
  class Cookies extends URLSearchParams {
9
7
  static jar = new Map();
10
-
11
8
  get [Symbol.toStringTag]() {
12
9
  return this.constructor.name;
13
10
  }
14
-
15
11
  constructor(input) {
16
12
  if (Array.isArray(input) && input.every(it => !Array.isArray(it))) {
17
- input = input.join(';').split(';').filter(it => !/\b(Domain|Expires|HttpOnly|Max-Age|Path|SameParty|SameSite|Secure)\b/i.test(it)).map(it => it.trim()).join('&');
13
+ input = input.join(';').split(';').filter(it => !/\b(?:Domain|Expires|HttpOnly|Max-Age|Path|SameParty|SameSite|Secure)\b/i.test(it)).map(it => it.trim()).join('&');
18
14
  }
19
-
20
15
  super(input);
21
16
  }
22
-
23
17
  toString() {
24
18
  (0, _utils.collate)(this, Cookies);
25
19
  return super.toString().split('&').join('; ').trim();
26
20
  }
27
-
28
21
  }
29
-
30
22
  exports.Cookies = Cookies;
package/dist/errors.js CHANGED
@@ -2,25 +2,18 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.TimeoutError = exports.RequestError = void 0;
5
-
6
5
  class RequestError extends Error {
7
6
  get [Symbol.toStringTag]() {
8
7
  return this.constructor.name;
9
8
  }
10
-
11
9
  get name() {
12
10
  return this[Symbol.toStringTag];
13
11
  }
14
-
15
12
  constructor(...args) {
16
13
  super(...args);
17
14
  Error.captureStackTrace(this, this.constructor);
18
15
  }
19
-
20
16
  }
21
-
22
17
  exports.RequestError = RequestError;
23
-
24
18
  class TimeoutError extends RequestError {}
25
-
26
19
  exports.TimeoutError = TimeoutError;
package/dist/file.js CHANGED
@@ -2,41 +2,36 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.File = void 0;
5
-
6
5
  var _nodeBuffer = require("node:buffer");
7
-
8
6
  exports.Blob = _nodeBuffer.Blob;
9
-
7
+ var _nodeUtil = require("node:util");
10
8
  class File extends _nodeBuffer.Blob {
11
9
  static alike(instance) {
12
10
  return [_nodeBuffer.Blob.name, File.name].includes(instance?.constructor.name);
13
11
  }
14
-
15
12
  #lastModified;
16
13
  #name;
17
-
18
14
  get [Symbol.toStringTag]() {
19
15
  return this.constructor.name;
20
16
  }
21
-
22
17
  get lastModified() {
23
18
  return this.#lastModified;
24
19
  }
25
-
26
20
  get name() {
27
21
  return this.#name;
28
22
  }
29
-
30
- constructor(bits, name = 'blob', options = {}) {
23
+ constructor(...args) {
24
+ const len = args.length;
25
+ if (len < 2) {
26
+ throw new TypeError(`Failed to construct '${File.name}': 2 arguments required, but only ${len} present.`);
27
+ }
28
+ const [bits, name, options = {}] = args;
31
29
  const {
32
- name: filename,
33
30
  lastModified = Date.now()
34
31
  } = options;
35
32
  super(bits, options);
36
- this.#lastModified = lastModified;
37
- this.#name = filename || name;
33
+ this.#lastModified = +lastModified ? lastModified : 0;
34
+ this.#name = (0, _nodeUtil.toUSVString)(name);
38
35
  }
39
-
40
36
  }
41
-
42
37
  exports.File = File;
package/dist/formdata.js CHANGED
@@ -2,43 +2,29 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.FormData = void 0;
5
-
6
5
  var _nodeCrypto = require("node:crypto");
7
-
8
6
  var _nodeHttp = _interopRequireDefault(require("node:http2"));
9
-
10
7
  var _nodeUtil = require("node:util");
11
-
12
- var _file = require("./file.js");
13
-
14
- var _mediatypes = require("./mediatypes.js");
15
-
16
- var _utils = require("./utils.js");
17
-
8
+ var _file = require("./file");
9
+ var _mediatypes = require("./mediatypes");
10
+ var _utils = require("./utils");
18
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
12
  const CRLF = '\r\n';
21
13
  const {
22
14
  HTTP2_HEADER_CONTENT_DISPOSITION,
23
15
  HTTP2_HEADER_CONTENT_TYPE
24
16
  } = _nodeHttp.default.constants;
25
-
26
17
  class FormData {
27
18
  static actuate(fd) {
28
19
  const boundary = (0, _nodeCrypto.randomBytes)(24).toString('hex');
29
20
  const contentType = `${_mediatypes.MULTIPART_FORM_DATA}; boundary=${boundary}`;
30
21
  const prefix = `--${boundary}${CRLF}${HTTP2_HEADER_CONTENT_DISPOSITION}: form-data`;
31
-
32
22
  const escape = str => str.replace(/\n/g, '%0A').replace(/\r/g, '%0D').replace(/"/g, '%22');
33
-
34
23
  const normalize = value => value.replace(/\r?\n|\r/g, CRLF);
35
-
36
24
  return {
37
25
  contentType,
38
-
39
26
  async *[Symbol.asyncIterator]() {
40
27
  const encoder = new TextEncoder();
41
-
42
28
  for (const [name, value] of fd) {
43
29
  if (value.constructor === String) {
44
30
  yield encoder.encode(`${prefix}; name="${escape(normalize(name))}"${CRLF.repeat(2)}${normalize(value)}${CRLF}`);
@@ -48,51 +34,41 @@ class FormData {
48
34
  yield encoder.encode(CRLF);
49
35
  }
50
36
  }
51
-
52
37
  yield encoder.encode(`--${boundary}--`);
53
38
  }
54
-
55
39
  };
56
40
  }
57
-
58
41
  static alike(instance) {
59
42
  return instance?.constructor.name === FormData.name;
60
43
  }
61
-
62
44
  static #enfoldEntry(name, value, filename) {
63
45
  name = (0, _nodeUtil.toUSVString)(name);
64
46
  filename &&= (0, _nodeUtil.toUSVString)(filename);
65
-
66
47
  if (_file.File.alike(value)) {
48
+ filename ??= value.name || 'blob';
67
49
  value = new _file.File([value], filename, value);
68
50
  } else if (this.#ensureInstance(value)) {
69
- value.name = filename || value.name;
51
+ value.name = filename;
70
52
  } else {
71
53
  value = (0, _nodeUtil.toUSVString)(value);
72
54
  }
73
-
74
55
  return {
75
56
  name,
76
57
  value
77
58
  };
78
59
  }
79
-
80
60
  static #ensureInstance(value) {
81
61
  return _file.File.alike(value) || value === Object(value) && Reflect.has(value, Symbol.asyncIterator);
82
62
  }
83
-
84
63
  #entries = [];
85
-
86
64
  get [Symbol.toStringTag]() {
87
65
  return this.constructor.name;
88
66
  }
89
-
90
67
  constructor(input) {
91
68
  if (input === Object(input) && (input?.constructor === Object || Reflect.has(input, Symbol.iterator))) {
92
69
  if (input.constructor !== Object) {
93
70
  input = Array.from(input);
94
71
  }
95
-
96
72
  if (Array.isArray(input)) {
97
73
  if (!input.every(it => Array.isArray(it))) {
98
74
  throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': The provided value cannot be converted to a sequence.`);
@@ -100,93 +76,77 @@ class FormData {
100
76
  throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': Sequence initializer must only contain pair elements.`);
101
77
  }
102
78
  }
103
-
104
79
  if (input.constructor === Object) {
105
80
  input = Object.entries(input);
106
81
  }
107
-
108
82
  input.forEach(([key, value]) => this.append(key, value));
109
83
  }
110
84
  }
111
-
112
85
  #ensureArgs(args, expected, method) {
113
86
  if (args.length < expected) {
114
87
  throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': ${expected} arguments required, but only ${args.length} present.`);
115
88
  }
116
-
117
89
  if (['append', 'set'].includes(method)) {
118
90
  if (args.length === 3 && !this.constructor.#ensureInstance(args[1])) {
119
- throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': parameter ${expected} is not of type 'Blob', 'File' or async iterable.`);
91
+ throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': parameter ${expected} is not of type 'Blob'.`);
120
92
  }
121
93
  }
122
-
123
94
  if (method === 'forEach') {
124
95
  if (args[0]?.constructor !== Function) {
125
96
  throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': parameter ${expected} is not of type 'Function'.`);
126
97
  }
127
98
  }
128
99
  }
129
-
130
100
  append(...args) {
131
101
  (0, _utils.collate)(this, FormData);
132
102
  this.#ensureArgs(args, 2, 'append');
133
103
  this.#entries.push(this.constructor.#enfoldEntry(...args));
134
104
  }
135
-
136
105
  delete(...args) {
137
106
  (0, _utils.collate)(this, FormData);
138
107
  this.#ensureArgs(args, 1, 'delete');
139
108
  const name = (0, _nodeUtil.toUSVString)(args[0]);
140
109
  this.#entries = this.#entries.filter(it => it.name !== name);
141
110
  }
142
-
143
111
  forEach(...args) {
144
112
  (0, _utils.collate)(this, FormData);
145
113
  this.#ensureArgs(args, 1, 'forEach');
146
114
  const [callback, thisArg] = args;
147
-
148
115
  for (const entry of this) {
149
116
  Reflect.apply(callback, thisArg, [...entry.reverse(), this]);
150
117
  }
151
118
  }
152
-
153
119
  get(...args) {
154
120
  (0, _utils.collate)(this, FormData);
155
121
  this.#ensureArgs(args, 1, 'get');
156
122
  const name = (0, _nodeUtil.toUSVString)(args[0]);
157
123
  return (this.#entries.find(it => it.name === name) ?? {}).value ?? null;
158
124
  }
159
-
160
125
  getAll(...args) {
161
126
  (0, _utils.collate)(this, FormData);
162
127
  this.#ensureArgs(args, 1, 'getAll');
163
128
  const name = (0, _nodeUtil.toUSVString)(args[0]);
164
129
  return this.#entries.filter(it => it.name === name).map(it => it.value);
165
130
  }
166
-
167
131
  has(...args) {
168
132
  (0, _utils.collate)(this, FormData);
169
133
  this.#ensureArgs(args, 1, 'has');
170
134
  const name = (0, _nodeUtil.toUSVString)(args[0]);
171
135
  return !!this.#entries.find(it => it.name === name);
172
136
  }
173
-
174
137
  set(...args) {
175
138
  (0, _utils.collate)(this, FormData);
176
139
  this.#ensureArgs(args, 2, 'set');
177
140
  const entry = this.constructor.#enfoldEntry(...args);
178
141
  const idx = this.#entries.findIndex(it => it.name === entry.name);
179
-
180
142
  if (idx !== -1) {
181
143
  this.#entries.splice(idx, 1, entry);
182
144
  } else {
183
145
  this.#entries.push(entry);
184
146
  }
185
147
  }
186
-
187
148
  *entries() {
188
149
  (0, _utils.collate)(this, FormData);
189
-
190
150
  for (const {
191
151
  name,
192
152
  value
@@ -194,28 +154,21 @@ class FormData {
194
154
  yield [name, value];
195
155
  }
196
156
  }
197
-
198
157
  *keys() {
199
158
  (0, _utils.collate)(this, FormData);
200
-
201
159
  for (const [name] of this) {
202
160
  yield name;
203
161
  }
204
162
  }
205
-
206
163
  *values() {
207
164
  (0, _utils.collate)(this, FormData);
208
-
209
165
  for (const [, value] of this) {
210
166
  yield value;
211
167
  }
212
168
  }
213
-
214
169
  [Symbol.iterator]() {
215
170
  (0, _utils.collate)(this, FormData);
216
171
  return this.entries();
217
172
  }
218
-
219
173
  }
220
-
221
174
  exports.FormData = FormData;