@oh-my-pi/pi-utils 15.0.1 → 15.0.2
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/package.json +3 -3
- package/src/fetch-retry.ts +8 -1
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-utils",
|
|
4
|
-
"version": "15.0.
|
|
4
|
+
"version": "15.0.2",
|
|
5
5
|
"description": "Shared utilities for pi packages",
|
|
6
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://omp.sh",
|
|
7
7
|
"author": "Can Boluk",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/bun": "^1.3.14",
|
|
41
|
-
"@oh-my-pi/pi-natives": "15.0.
|
|
41
|
+
"@oh-my-pi/pi-natives": "15.0.2"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"bun": ">=1.3.14"
|
package/src/fetch-retry.ts
CHANGED
|
@@ -96,6 +96,12 @@ export interface FetchWithRetryOptions extends RequestInit {
|
|
|
96
96
|
* token refresh or user-agent rotation.
|
|
97
97
|
*/
|
|
98
98
|
prepareInit?: (attempt: number) => RequestInit | Promise<RequestInit>;
|
|
99
|
+
/**
|
|
100
|
+
* Optional `fetch` implementation override. Defaults to `globalThis.fetch`.
|
|
101
|
+
* Useful for routing requests through a proxy, instrumented transport, or
|
|
102
|
+
* mock during tests.
|
|
103
|
+
*/
|
|
104
|
+
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
const DEFAULT_MAX_DELAY_MS = 60_000;
|
|
@@ -119,6 +125,7 @@ export async function fetchWithRetry(
|
|
|
119
125
|
maxDelayMs = DEFAULT_MAX_DELAY_MS,
|
|
120
126
|
defaultDelayMs,
|
|
121
127
|
prepareInit,
|
|
128
|
+
fetch: fetchImpl = fetch,
|
|
122
129
|
...baseInit
|
|
123
130
|
} = options;
|
|
124
131
|
const signal = baseInit.signal as AbortSignal | undefined;
|
|
@@ -130,7 +137,7 @@ export async function fetchWithRetry(
|
|
|
130
137
|
|
|
131
138
|
let response: Response;
|
|
132
139
|
try {
|
|
133
|
-
response = await
|
|
140
|
+
response = await fetchImpl(requestUrl, init);
|
|
134
141
|
} catch (error) {
|
|
135
142
|
if (signal?.aborted) throw new Error("Request was aborted");
|
|
136
143
|
const wrapped = wrapNetworkError(error);
|