@nomicfoundation/hardhat-utils 4.1.9 → 4.2.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @nomicfoundation/hardhat-utils
|
|
2
2
|
|
|
3
|
+
## 4.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#8583](https://github.com/NomicFoundation/hardhat/pull/8583) [`2c98fa5`](https://github.com/NomicFoundation/hardhat/commit/2c98fa5b05c3f2b8d06b44aae4ebea88b82ae132) Thanks [@schaable](https://github.com/schaable)! - Updated undici to v7.
|
|
8
|
+
|
|
9
|
+
- [#8210](https://github.com/NomicFoundation/hardhat/pull/8210) [`024b422`](https://github.com/NomicFoundation/hardhat/commit/024b422340705f1ff5fc14b9dcc6a1f143487d86) Thanks [@renovate](https://github.com/apps/renovate)! - Update the cryptography dependencies to their latest major versions: `@noble/hashes` and `@noble/ciphers` to 2, `ethereum-cryptography` to 3, and `micro-eth-signer` to 0.19.
|
|
10
|
+
|
|
3
11
|
## 4.1.9
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -7,7 +7,6 @@ export declare function getBaseRequestOptions(requestUrl: string, { extraHeaders
|
|
|
7
7
|
signal?: EventEmitter | AbortSignal | undefined;
|
|
8
8
|
dispatcher: UndiciT.Dispatcher;
|
|
9
9
|
headers: Record<string, string>;
|
|
10
|
-
throwOnError: true;
|
|
11
10
|
}>;
|
|
12
11
|
export declare function getHeaders(requestUrl: string, extraHeaders?: Record<string, string>): Record<string, string>;
|
|
13
12
|
export declare function getAuthHeader(requestUrl: string): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/internal/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,e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,CAAC,OAAO,CAAC,UAAU,CAAC,CAS7B;AAED,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,GAC5B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAOvB;AAED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,GAC7B,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAMxB;AAED,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,MAAwC,EACjD,gBAAgB,GAAE,OAAe,GAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAaxB;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAuB9D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
+
import { STATUS_CODES } from "node:http";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { mkdir } from "../fs.js";
|
|
4
5
|
import { isObject } from "../lang.js";
|
|
@@ -22,13 +23,15 @@ export async function getBaseRequestOptions(requestUrl, { extraHeaders, abortSig
|
|
|
22
23
|
const dispatcher = dispatcherOrDispatcherOptions instanceof undici.Dispatcher
|
|
23
24
|
? dispatcherOrDispatcherOptions
|
|
24
25
|
: await getDispatcher(requestUrl, dispatcherOrDispatcherOptions);
|
|
25
|
-
// We
|
|
26
|
-
//
|
|
27
|
-
//
|
|
26
|
+
// We always build our own dispatcher instead of letting undici fall back to
|
|
27
|
+
// the global one, which is a bare `new Agent()` and would drop our timeouts.
|
|
28
|
+
// Configuring it with `setGlobalDispatcher` would affect the whole process.
|
|
29
|
+
// https://github.com/nodejs/undici/blob/v7.29.0/lib/global.js#L10-L12
|
|
28
30
|
return {
|
|
29
|
-
dispatcher,
|
|
31
|
+
dispatcher: dispatcher.compose(undici.interceptors.redirect({ maxRedirections: DEFAULT_MAX_REDIRECTS }),
|
|
32
|
+
// responseError is what makes 4xx and 5xx responses throw
|
|
33
|
+
undici.interceptors.responseError()),
|
|
30
34
|
headers: getHeaders(requestUrl, extraHeaders),
|
|
31
|
-
throwOnError: true,
|
|
32
35
|
...(abortSignal !== undefined ? { signal: abortSignal } : {}),
|
|
33
36
|
...(queryParams !== undefined ? { query: queryParams } : {}),
|
|
34
37
|
};
|
|
@@ -75,7 +78,7 @@ export async function getBasicDispatcher(options) {
|
|
|
75
78
|
}
|
|
76
79
|
export function getBaseDispatcherOptions(timeout = DEFAULT_TIMEOUT_IN_MILLISECONDS, isTestDispatcher = false) {
|
|
77
80
|
// These have good defaults for production, but need to be tweaked to avoid hanging tests.
|
|
78
|
-
// https://github.com/nodejs/undici/blob/
|
|
81
|
+
// https://github.com/nodejs/undici/blob/v7.29.0/docs/docs/best-practices/writing-tests.md
|
|
79
82
|
const keepAliveTimeouts = isTestDispatcher
|
|
80
83
|
? { keepAliveTimeout: 10, keepAliveMaxTimeout: 10 }
|
|
81
84
|
: {};
|
|
@@ -83,7 +86,6 @@ export function getBaseDispatcherOptions(timeout = DEFAULT_TIMEOUT_IN_MILLISECON
|
|
|
83
86
|
headersTimeout: timeout,
|
|
84
87
|
bodyTimeout: timeout,
|
|
85
88
|
connectTimeout: timeout,
|
|
86
|
-
maxRedirections: DEFAULT_MAX_REDIRECTS,
|
|
87
89
|
...keepAliveTimeouts,
|
|
88
90
|
};
|
|
89
91
|
}
|
|
@@ -106,8 +108,29 @@ export function handleError(e, requestUrl) {
|
|
|
106
108
|
errorCode === "UND_ERR_BODY_TIMEOUT") {
|
|
107
109
|
throw new RequestTimeoutError(requestUrl, e);
|
|
108
110
|
}
|
|
109
|
-
if (errorCode === "
|
|
111
|
+
if (errorCode === "UND_ERR_RESPONSE") {
|
|
112
|
+
describeResponseError(e);
|
|
110
113
|
throw new ResponseStatusCodeError(requestUrl, e);
|
|
111
114
|
}
|
|
112
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Restores the message that undici used to produce for status code errors.
|
|
118
|
+
*
|
|
119
|
+
* Until v7, undici's `throwOnError` described the failure as
|
|
120
|
+
* `Response status code <code>: <reason>`. The `responseError` interceptor that
|
|
121
|
+
* replaced it always uses the generic "Response Error" instead, dropping the
|
|
122
|
+
* only actionable part of the message. Consumers surface this message to users,
|
|
123
|
+
* so we describe the error again.
|
|
124
|
+
*/
|
|
125
|
+
function describeResponseError(e) {
|
|
126
|
+
if (e.message !== "Response Error") {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const statusCode = "statusCode" in e ? e.statusCode : undefined;
|
|
130
|
+
if (typeof statusCode !== "number") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const reason = STATUS_CODES[statusCode];
|
|
134
|
+
e.message = `Response status code ${statusCode}${reason !== undefined ? `: ${reason}` : ""}`;
|
|
135
|
+
}
|
|
113
136
|
//# sourceMappingURL=request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/internal/request.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,+BAA+B,EAC/B,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAEvB,gFAAgF;AAChF,sEAAsE;AACtE,IAAI,MAAkC,CAAC;AAEvC,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,QAAgB;IACzD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ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C;QACrC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,IAAI,uBAAuB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,CAAQ;IACrC,IAAI,CAAC,CAAC,OAAO,KAAK,gBAAgB,EAAE,CAAC;QACnC,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,YAAY,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IAChE,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IAExC,CAAC,CAAC,OAAO,GAAG,wBAAwB,UAAU,GAC5C,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EACzC,EAAE,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/hardhat-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Utilities for Hardhat and its plugins",
|
|
5
5
|
"homepage": "https://github.com/NomicFoundation/hardhat/tree/main/packages/hardhat-utils",
|
|
6
6
|
"repository": {
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@streamparser/json-node": "^0.0.22",
|
|
72
72
|
"env-paths": "^4.0.0",
|
|
73
|
-
"ethereum-cryptography": "^
|
|
73
|
+
"ethereum-cryptography": "^3.0.0",
|
|
74
74
|
"fast-equals": "^6.0.0",
|
|
75
75
|
"json-stream-stringify": "^3.1.7",
|
|
76
76
|
"rfdc": "^1.3.1",
|
|
77
|
-
"undici": "^
|
|
77
|
+
"undici": "^7.29.0"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"lint": "pnpm eslint && pnpm prettier --check",
|
package/src/internal/request.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type EventEmitter from "node:events";
|
|
|
3
3
|
import type * as UndiciT from "undici";
|
|
4
4
|
|
|
5
5
|
import crypto from "node:crypto";
|
|
6
|
+
import { STATUS_CODES } from "node:http";
|
|
6
7
|
import path from "node:path";
|
|
7
8
|
|
|
8
9
|
import { mkdir } from "../fs.js";
|
|
@@ -42,7 +43,6 @@ export async function getBaseRequestOptions(
|
|
|
42
43
|
signal?: EventEmitter | AbortSignal | undefined;
|
|
43
44
|
dispatcher: UndiciT.Dispatcher;
|
|
44
45
|
headers: Record<string, string>;
|
|
45
|
-
throwOnError: true;
|
|
46
46
|
}> {
|
|
47
47
|
if (undici === undefined) {
|
|
48
48
|
undici = await import("undici");
|
|
@@ -53,13 +53,17 @@ export async function getBaseRequestOptions(
|
|
|
53
53
|
? dispatcherOrDispatcherOptions
|
|
54
54
|
: await getDispatcher(requestUrl, dispatcherOrDispatcherOptions);
|
|
55
55
|
|
|
56
|
-
// We
|
|
57
|
-
//
|
|
58
|
-
//
|
|
56
|
+
// We always build our own dispatcher instead of letting undici fall back to
|
|
57
|
+
// the global one, which is a bare `new Agent()` and would drop our timeouts.
|
|
58
|
+
// Configuring it with `setGlobalDispatcher` would affect the whole process.
|
|
59
|
+
// https://github.com/nodejs/undici/blob/v7.29.0/lib/global.js#L10-L12
|
|
59
60
|
return {
|
|
60
|
-
dispatcher
|
|
61
|
+
dispatcher: dispatcher.compose(
|
|
62
|
+
undici.interceptors.redirect({ maxRedirections: DEFAULT_MAX_REDIRECTS }),
|
|
63
|
+
// responseError is what makes 4xx and 5xx responses throw
|
|
64
|
+
undici.interceptors.responseError(),
|
|
65
|
+
),
|
|
61
66
|
headers: getHeaders(requestUrl, extraHeaders),
|
|
62
|
-
throwOnError: true,
|
|
63
67
|
...(abortSignal !== undefined ? { signal: abortSignal } : {}),
|
|
64
68
|
...(queryParams !== undefined ? { query: queryParams } : {}),
|
|
65
69
|
};
|
|
@@ -134,7 +138,7 @@ export function getBaseDispatcherOptions(
|
|
|
134
138
|
isTestDispatcher: boolean = false,
|
|
135
139
|
): UndiciT.Client.Options {
|
|
136
140
|
// These have good defaults for production, but need to be tweaked to avoid hanging tests.
|
|
137
|
-
// https://github.com/nodejs/undici/blob/
|
|
141
|
+
// https://github.com/nodejs/undici/blob/v7.29.0/docs/docs/best-practices/writing-tests.md
|
|
138
142
|
const keepAliveTimeouts = isTestDispatcher
|
|
139
143
|
? { keepAliveTimeout: 10, keepAliveMaxTimeout: 10 }
|
|
140
144
|
: {};
|
|
@@ -143,7 +147,6 @@ export function getBaseDispatcherOptions(
|
|
|
143
147
|
headersTimeout: timeout,
|
|
144
148
|
bodyTimeout: timeout,
|
|
145
149
|
connectTimeout: timeout,
|
|
146
|
-
maxRedirections: DEFAULT_MAX_REDIRECTS,
|
|
147
150
|
...keepAliveTimeouts,
|
|
148
151
|
};
|
|
149
152
|
}
|
|
@@ -173,7 +176,34 @@ export function handleError(e: Error, requestUrl: string): void {
|
|
|
173
176
|
throw new RequestTimeoutError(requestUrl, e);
|
|
174
177
|
}
|
|
175
178
|
|
|
176
|
-
if (errorCode === "
|
|
179
|
+
if (errorCode === "UND_ERR_RESPONSE") {
|
|
180
|
+
describeResponseError(e);
|
|
177
181
|
throw new ResponseStatusCodeError(requestUrl, e);
|
|
178
182
|
}
|
|
179
183
|
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Restores the message that undici used to produce for status code errors.
|
|
187
|
+
*
|
|
188
|
+
* Until v7, undici's `throwOnError` described the failure as
|
|
189
|
+
* `Response status code <code>: <reason>`. The `responseError` interceptor that
|
|
190
|
+
* replaced it always uses the generic "Response Error" instead, dropping the
|
|
191
|
+
* only actionable part of the message. Consumers surface this message to users,
|
|
192
|
+
* so we describe the error again.
|
|
193
|
+
*/
|
|
194
|
+
function describeResponseError(e: Error): void {
|
|
195
|
+
if (e.message !== "Response Error") {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const statusCode = "statusCode" in e ? e.statusCode : undefined;
|
|
200
|
+
if (typeof statusCode !== "number") {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const reason = STATUS_CODES[statusCode];
|
|
205
|
+
|
|
206
|
+
e.message = `Response status code ${statusCode}${
|
|
207
|
+
reason !== undefined ? `: ${reason}` : ""
|
|
208
|
+
}`;
|
|
209
|
+
}
|