rekwest 7.1.0 → 7.1.1
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/dist/formdata.cjs +5 -5
- package/dist/mixin.cjs +1 -1
- package/dist/redirects.cjs +3 -3
- package/dist/retries.cjs +2 -2
- package/dist/utils.cjs +2 -2
- package/dist/validation.cjs +3 -3
- package/package.json +1 -1
- package/src/formdata.js +5 -5
- package/src/mixin.js +1 -1
- package/src/redirects.js +3 -3
- package/src/retries.js +2 -2
- package/src/utils.js +2 -2
- package/src/validation.js +3 -3
package/dist/formdata.cjs
CHANGED
|
@@ -70,9 +70,9 @@ class FormData {
|
|
|
70
70
|
if (Object(input) === input) {
|
|
71
71
|
if (Array.isArray(input)) {
|
|
72
72
|
if (!input.every(it => Array.isArray(it))) {
|
|
73
|
-
throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': The provided value cannot be converted to a sequence
|
|
73
|
+
throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': The provided value cannot be converted to a sequence`);
|
|
74
74
|
} else if (!input.every(it => it.length === 2)) {
|
|
75
|
-
throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': Sequence initializer must only contain pair elements
|
|
75
|
+
throw new TypeError(`Failed to construct '${this[Symbol.toStringTag]}': Sequence initializer must only contain pair elements`);
|
|
76
76
|
}
|
|
77
77
|
input = Array.from(input);
|
|
78
78
|
} else if (!Reflect.has(input, Symbol.iterator)) {
|
|
@@ -85,16 +85,16 @@ class FormData {
|
|
|
85
85
|
}
|
|
86
86
|
#ensureArgs(args, expected, method) {
|
|
87
87
|
if (args.length < expected) {
|
|
88
|
-
throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': ${expected} arguments required, but only ${args.length} present
|
|
88
|
+
throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': ${expected} arguments required, but only ${args.length} present`);
|
|
89
89
|
}
|
|
90
90
|
if (['append', 'set'].includes(method)) {
|
|
91
91
|
if (args.length === 3 && !this.constructor.#ensureInstance(args[1])) {
|
|
92
|
-
throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': parameter ${expected} is not of type 'Blob'
|
|
92
|
+
throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': parameter ${expected} is not of type 'Blob'`);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
if (method === 'forEach') {
|
|
96
96
|
if (args[0]?.constructor !== Function) {
|
|
97
|
-
throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': parameter ${expected} is not of type 'Function'
|
|
97
|
+
throw new TypeError(`Failed to execute '${method}' on '${this[Symbol.toStringTag]}': parameter ${expected} is not of type 'Function'`);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
package/dist/mixin.cjs
CHANGED
|
@@ -74,7 +74,7 @@ const mixin = (res, {
|
|
|
74
74
|
value: async function () {
|
|
75
75
|
(0, _utils.brandCheck)(this, res?.constructor);
|
|
76
76
|
if (this.bodyUsed) {
|
|
77
|
-
throw new TypeError('Response stream already read
|
|
77
|
+
throw new TypeError('Response stream already read');
|
|
78
78
|
}
|
|
79
79
|
let body = await (0, _consumers.buffer)((0, _codecs.decode)(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING], {
|
|
80
80
|
decodersOptions
|
package/dist/redirects.cjs
CHANGED
|
@@ -31,12 +31,12 @@ const redirects = (res, options) => {
|
|
|
31
31
|
} = options;
|
|
32
32
|
if (follow && /3\d{2}/.test(res.statusCode) && res.headers[HTTP2_HEADER_LOCATION]) {
|
|
33
33
|
if (redirect === _constants.requestRedirect.error) {
|
|
34
|
-
return res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to
|
|
34
|
+
return res.emit('error', new _errors.RequestError(`Unexpected redirect, redirect mode is set to: ${redirect}`));
|
|
35
35
|
}
|
|
36
36
|
if (redirect === _constants.requestRedirect.follow) {
|
|
37
37
|
const location = new URL(res.headers[HTTP2_HEADER_LOCATION], url);
|
|
38
38
|
if (!/^https?:/i.test(location.protocol)) {
|
|
39
|
-
return res.emit('error', new _errors.RequestError('URL scheme must be "http" or "https"
|
|
39
|
+
return res.emit('error', new _errors.RequestError('URL scheme must be "http" or "https"'));
|
|
40
40
|
}
|
|
41
41
|
if (!(0, _utils.sameOrigin)(location, url)) {
|
|
42
42
|
if (credentials !== _constants.requestCredentials.include) {
|
|
@@ -45,7 +45,7 @@ const redirects = (res, options) => {
|
|
|
45
45
|
options.h2 = false;
|
|
46
46
|
}
|
|
47
47
|
if ([HTTP_STATUS_PERMANENT_REDIRECT, HTTP_STATUS_TEMPORARY_REDIRECT].includes(res.statusCode) && (0, _utils.isPipeStream)(options.body) && !(0, _nodeStream.isReadable)(options.body)) {
|
|
48
|
-
return res.emit('error', new _errors.RequestError(`Unable to ${redirect} redirect with streamable body
|
|
48
|
+
return res.emit('error', new _errors.RequestError(`Unable to ${redirect} redirect with streamable body`));
|
|
49
49
|
}
|
|
50
50
|
if ([HTTP_STATUS_MOVED_PERMANENTLY, HTTP_STATUS_FOUND].includes(res.statusCode) && options.method === HTTP2_METHOD_POST || res.statusCode === HTTP_STATUS_SEE_OTHER && ![HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
|
|
51
51
|
options.body = null;
|
package/dist/retries.cjs
CHANGED
|
@@ -26,7 +26,7 @@ const retries = (err, options) => {
|
|
|
26
26
|
} = options;
|
|
27
27
|
if (retry?.attempts > 0) {
|
|
28
28
|
if (![HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(method) && (0, _utils.isPipeStream)(body) && !(0, _nodeStream.isReadable)(body)) {
|
|
29
|
-
throw new _errors.RequestError('Request stream already read
|
|
29
|
+
throw new _errors.RequestError('Request stream already read', {
|
|
30
30
|
cause: err
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -38,7 +38,7 @@ const retries = (err, options) => {
|
|
|
38
38
|
interval = err.headers[HTTP2_HEADER_RETRY_AFTER];
|
|
39
39
|
interval = Math.abs(Number(interval) * 1e3 || new Date(interval) - Date.now()) || 0;
|
|
40
40
|
if (interval > maxRetryAfter) {
|
|
41
|
-
throw new _errors.RequestError(`Maximum '${HTTP2_HEADER_RETRY_AFTER}' limit exceeded: ${interval} ms
|
|
41
|
+
throw new _errors.RequestError(`Maximum '${HTTP2_HEADER_RETRY_AFTER}' limit exceeded: ${interval} ms`, {
|
|
42
42
|
cause: err
|
|
43
43
|
});
|
|
44
44
|
}
|
package/dist/utils.cjs
CHANGED
|
@@ -60,7 +60,7 @@ const augment = (res, headers, options) => {
|
|
|
60
60
|
exports.augment = augment;
|
|
61
61
|
const brandCheck = (val, ctor) => {
|
|
62
62
|
if (!(val instanceof ctor)) {
|
|
63
|
-
throw new TypeError('Illegal invocation
|
|
63
|
+
throw new TypeError('Illegal invocation');
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
exports.brandCheck = brandCheck;
|
|
@@ -149,7 +149,7 @@ exports.sameOrigin = sameOrigin;
|
|
|
149
149
|
const snoop = (client, req, options) => {
|
|
150
150
|
req.once('close', () => client?.close());
|
|
151
151
|
req.once('end', () => client?.close());
|
|
152
|
-
req.once('timeout', () => req.destroy(new _errors.TimeoutError(`Timed out after ${options.timeout} ms
|
|
152
|
+
req.once('timeout', () => req.destroy(new _errors.TimeoutError(`Timed out after ${options.timeout} ms`)));
|
|
153
153
|
req.once('trailers', trailers => {
|
|
154
154
|
Reflect.defineProperty(req, 'trailers', {
|
|
155
155
|
enumerable: true,
|
package/dist/validation.cjs
CHANGED
|
@@ -13,13 +13,13 @@ const {
|
|
|
13
13
|
} = _nodeHttp.default.constants;
|
|
14
14
|
const validation = (options = {}) => {
|
|
15
15
|
if (options.body && [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
|
|
16
|
-
throw new TypeError(`Request with ${HTTP2_METHOD_GET}/${HTTP2_METHOD_HEAD} method cannot have body
|
|
16
|
+
throw new TypeError(`Request with ${HTTP2_METHOD_GET}/${HTTP2_METHOD_HEAD} method cannot have body`);
|
|
17
17
|
}
|
|
18
18
|
if (!Object.values(_constants.requestCredentials).includes(options.credentials)) {
|
|
19
|
-
throw new TypeError(`Failed to read the 'credentials' property from 'options': The provided value '${options.credentials}' is not a valid enum value
|
|
19
|
+
throw new TypeError(`Failed to read the 'credentials' property from 'options': The provided value '${options.credentials}' is not a valid enum value`);
|
|
20
20
|
}
|
|
21
21
|
if (!Reflect.has(_constants.requestRedirect, options.redirect)) {
|
|
22
|
-
throw new TypeError(`Failed to read the 'redirect' property from 'options': The provided value '${options.redirect}' is not a valid enum value
|
|
22
|
+
throw new TypeError(`Failed to read the 'redirect' property from 'options': The provided value '${options.redirect}' is not a valid enum value`);
|
|
23
23
|
}
|
|
24
24
|
return options;
|
|
25
25
|
};
|
package/package.json
CHANGED
package/src/formdata.js
CHANGED
|
@@ -98,11 +98,11 @@ export class FormData {
|
|
|
98
98
|
if (!input.every((it) => Array.isArray(it))) {
|
|
99
99
|
throw new TypeError(`Failed to construct '${
|
|
100
100
|
this[Symbol.toStringTag]
|
|
101
|
-
}': The provided value cannot be converted to a sequence
|
|
101
|
+
}': The provided value cannot be converted to a sequence`);
|
|
102
102
|
} else if (!input.every((it) => it.length === 2)) {
|
|
103
103
|
throw new TypeError(`Failed to construct '${
|
|
104
104
|
this[Symbol.toStringTag]
|
|
105
|
-
}': Sequence initializer must only contain pair elements
|
|
105
|
+
}': Sequence initializer must only contain pair elements`);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
input = Array.from(input);
|
|
@@ -120,7 +120,7 @@ export class FormData {
|
|
|
120
120
|
if (args.length < expected) {
|
|
121
121
|
throw new TypeError(`Failed to execute '${ method }' on '${
|
|
122
122
|
this[Symbol.toStringTag]
|
|
123
|
-
}': ${ expected } arguments required, but only ${ args.length } present
|
|
123
|
+
}': ${ expected } arguments required, but only ${ args.length } present`);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
if ([
|
|
@@ -130,7 +130,7 @@ export class FormData {
|
|
|
130
130
|
if (args.length === 3 && !this.constructor.#ensureInstance(args[1])) {
|
|
131
131
|
throw new TypeError(`Failed to execute '${ method }' on '${
|
|
132
132
|
this[Symbol.toStringTag]
|
|
133
|
-
}': parameter ${ expected } is not of type 'Blob'
|
|
133
|
+
}': parameter ${ expected } is not of type 'Blob'`);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -138,7 +138,7 @@ export class FormData {
|
|
|
138
138
|
if (args[0]?.constructor !== Function) {
|
|
139
139
|
throw new TypeError(`Failed to execute '${ method }' on '${
|
|
140
140
|
this[Symbol.toStringTag]
|
|
141
|
-
}': parameter ${ expected } is not of type 'Function'
|
|
141
|
+
}': parameter ${ expected } is not of type 'Function'`);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
}
|
package/src/mixin.js
CHANGED
|
@@ -71,7 +71,7 @@ export const mixin = (res, { decodersOptions, digest = false, parse = false } =
|
|
|
71
71
|
brandCheck(this, res?.constructor);
|
|
72
72
|
|
|
73
73
|
if (this.bodyUsed) {
|
|
74
|
-
throw new TypeError('Response stream already read
|
|
74
|
+
throw new TypeError('Response stream already read');
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
let body = await buffer(decode(this, this.headers[HTTP2_HEADER_CONTENT_ENCODING], { decodersOptions }));
|
package/src/redirects.js
CHANGED
|
@@ -28,14 +28,14 @@ export const redirects = (res, options) => {
|
|
|
28
28
|
|
|
29
29
|
if (follow && /3\d{2}/.test(res.statusCode) && res.headers[HTTP2_HEADER_LOCATION]) {
|
|
30
30
|
if (redirect === requestRedirect.error) {
|
|
31
|
-
return res.emit('error', new RequestError(`Unexpected redirect, redirect mode is set to
|
|
31
|
+
return res.emit('error', new RequestError(`Unexpected redirect, redirect mode is set to: ${ redirect }`));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (redirect === requestRedirect.follow) {
|
|
35
35
|
const location = new URL(res.headers[HTTP2_HEADER_LOCATION], url);
|
|
36
36
|
|
|
37
37
|
if (!/^https?:/i.test(location.protocol)) {
|
|
38
|
-
return res.emit('error', new RequestError('URL scheme must be "http" or "https"
|
|
38
|
+
return res.emit('error', new RequestError('URL scheme must be "http" or "https"'));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if (!sameOrigin(location, url)) {
|
|
@@ -50,7 +50,7 @@ export const redirects = (res, options) => {
|
|
|
50
50
|
HTTP_STATUS_PERMANENT_REDIRECT,
|
|
51
51
|
HTTP_STATUS_TEMPORARY_REDIRECT,
|
|
52
52
|
].includes(res.statusCode) && isPipeStream(options.body) && !isReadable(options.body)) {
|
|
53
|
-
return res.emit('error', new RequestError(`Unable to ${ redirect } redirect with streamable body
|
|
53
|
+
return res.emit('error', new RequestError(`Unable to ${ redirect } redirect with streamable body`));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
if (([
|
package/src/retries.js
CHANGED
|
@@ -19,7 +19,7 @@ export const retries = (err, options) => {
|
|
|
19
19
|
HTTP2_METHOD_GET,
|
|
20
20
|
HTTP2_METHOD_HEAD,
|
|
21
21
|
].includes(method) && isPipeStream(body) && !isReadable(body)) {
|
|
22
|
-
throw new RequestError('Request stream already read
|
|
22
|
+
throw new RequestError('Request stream already read', { cause: err });
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
if (retry.errorCodes?.includes(err.code) || retry.statusCodes?.includes(err.statusCode)) {
|
|
@@ -30,7 +30,7 @@ export const retries = (err, options) => {
|
|
|
30
30
|
interval = Math.abs(Number(interval) * 1e3 || new Date(interval) - Date.now()) || 0;
|
|
31
31
|
if (interval > maxRetryAfter) {
|
|
32
32
|
throw new RequestError(
|
|
33
|
-
`Maximum '${ HTTP2_HEADER_RETRY_AFTER }' limit exceeded: ${ interval } ms
|
|
33
|
+
`Maximum '${ HTTP2_HEADER_RETRY_AFTER }' limit exceeded: ${ interval } ms`,
|
|
34
34
|
{ cause: err },
|
|
35
35
|
);
|
|
36
36
|
}
|
package/src/utils.js
CHANGED
|
@@ -62,7 +62,7 @@ export const augment = (res, headers, options) => {
|
|
|
62
62
|
|
|
63
63
|
export const brandCheck = (val, ctor) => {
|
|
64
64
|
if (!(val instanceof ctor)) {
|
|
65
|
-
throw new TypeError('Illegal invocation
|
|
65
|
+
throw new TypeError('Illegal invocation');
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
|
|
@@ -164,7 +164,7 @@ export const sameOrigin = (a, b) => a.protocol === b.protocol && a.hostname ===
|
|
|
164
164
|
export const snoop = (client, req, options) => {
|
|
165
165
|
req.once('close', () => client?.close());
|
|
166
166
|
req.once('end', () => client?.close());
|
|
167
|
-
req.once('timeout', () => req.destroy(new TimeoutError(`Timed out after ${ options.timeout } ms
|
|
167
|
+
req.once('timeout', () => req.destroy(new TimeoutError(`Timed out after ${ options.timeout } ms`)));
|
|
168
168
|
req.once('trailers', (trailers) => {
|
|
169
169
|
Reflect.defineProperty(req, 'trailers', {
|
|
170
170
|
enumerable: true,
|
package/src/validation.js
CHANGED
|
@@ -14,19 +14,19 @@ export const validation = (options = {}) => {
|
|
|
14
14
|
HTTP2_METHOD_GET,
|
|
15
15
|
HTTP2_METHOD_HEAD,
|
|
16
16
|
].includes(options.method)) {
|
|
17
|
-
throw new TypeError(`Request with ${ HTTP2_METHOD_GET }/${ HTTP2_METHOD_HEAD } method cannot have body
|
|
17
|
+
throw new TypeError(`Request with ${ HTTP2_METHOD_GET }/${ HTTP2_METHOD_HEAD } method cannot have body`);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
if (!Object.values(requestCredentials).includes(options.credentials)) {
|
|
21
21
|
throw new TypeError(`Failed to read the 'credentials' property from 'options': The provided value '${
|
|
22
22
|
options.credentials
|
|
23
|
-
}' is not a valid enum value
|
|
23
|
+
}' is not a valid enum value`);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
if (!Reflect.has(requestRedirect, options.redirect)) {
|
|
27
27
|
throw new TypeError(`Failed to read the 'redirect' property from 'options': The provided value '${
|
|
28
28
|
options.redirect
|
|
29
|
-
}' is not a valid enum value
|
|
29
|
+
}' is not a valid enum value`);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
return options;
|