Skip to content

Commit cecb877

Browse files
authored
Merge pull request #17 from proxymesh/dependabot/npm_and_yarn/wretch-3.0.7
chore(deps-dev): Bump wretch from 2.11.1 to 3.0.7
2 parents 568f26f + 99fff13 commit cecb877

5 files changed

Lines changed: 28 additions & 22 deletions

File tree

lib/wretch-proxy.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* wretch extension for proxy header support.
33
*
4-
* Registers a custom `fetch` (node-fetch + ProxyHeadersAgent) as wretch's fetch polyfill.
5-
* wretch stores polyfills on a module singleton; avoid mixing different proxy configs
6-
* in the same process without coordinating polyfills.
4+
* Wraps the wretch factory so each request chain uses a custom `fetch`
5+
* (node-fetch + ProxyHeadersAgent). wretch v3 uses per-chain `.fetchPolyfill()`
6+
* instead of the old module-level `.polyfills()`.
77
*
88
* @example
99
* const wretch = await createProxyWretch({ proxy: 'http://proxy:8080' });
@@ -20,7 +20,7 @@ import { createProxyFetch } from './node-fetch-proxy.js';
2020
* @param {string} options.proxy - Proxy URL
2121
* @param {Object} [options.proxyHeaders] - Headers to send on CONNECT
2222
* @param {Function} [options.onProxyConnect] - CONNECT callback
23-
* @returns {Promise<import('wretch').Wretch>} Default wretch export after polyfills are set
23+
* @returns {Promise<typeof import('wretch').default>} Wretch factory wired to proxy-header fetch
2424
*/
2525
export async function createProxyWretch(options) {
2626
const { proxy, proxyHeaders = {}, onProxyConnect } = options;
@@ -29,15 +29,20 @@ export async function createProxyWretch(options) {
2929
throw new Error('proxy option is required');
3030
}
3131

32-
let wretch;
32+
let rawWretch;
3333
try {
34-
wretch = (await import('wretch')).default;
34+
rawWretch = (await import('wretch')).default;
3535
} catch {
3636
throw new Error('wretch is required. Install it with: npm install wretch');
3737
}
3838

39-
const fetch = createProxyFetch({ proxy, proxyHeaders, onProxyConnect });
40-
wretch.polyfills({ fetch });
39+
const fetchImpl = createProxyFetch({ proxy, proxyHeaders, onProxyConnect });
4140

42-
return wretch;
41+
function proxyWretch(url, opts) {
42+
return rawWretch(url, opts).fetchPolyfill(fetchImpl);
43+
}
44+
proxyWretch.default = proxyWretch;
45+
proxyWretch.WretchError = rawWretch.WretchError;
46+
47+
return proxyWretch;
4348
}

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"superagent": "^8.0.0 || ^9.0.0 || ^10.0.0",
117117
"undici": "^5.0.0 || ^6.0.0 || ^7.0.0",
118118
"ky": "^1.0.0",
119-
"wretch": "^2.0.0",
119+
"wretch": "^2.0.0 || ^3.0.0",
120120
"make-fetch-happen": "^14.0.0",
121121
"needle": "^3.0.0",
122122
"typed-rest-client": "^2.0.0"
@@ -163,7 +163,7 @@
163163
"typescript": "^6.0.2",
164164
"undici": "^8.0.2",
165165
"ky": "^1.7.0",
166-
"wretch": "^2.11.0",
166+
"wretch": "^3.0.7",
167167
"make-fetch-happen": "^15.0.5",
168168
"needle": "^3.3.0",
169169
"typed-rest-client": "^2.2.0"

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"ignoreDeprecations": "6.0",
34
"target": "ES2020",
45
"module": "ESNext",
56
"moduleResolution": "Bundler",

types/wretch.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Wretch } from 'wretch';
2-
31
export interface CreateProxyWretchOptions {
42
proxy: string;
53
proxyHeaders?: Record<string, string>;
64
onProxyConnect?: (headers: Map<string, string>) => void;
75
}
86

9-
export function createProxyWretch(options: CreateProxyWretchOptions): Promise<Wretch>;
7+
export function createProxyWretch(
8+
options: CreateProxyWretchOptions
9+
): Promise<typeof import('wretch').default>;

0 commit comments

Comments
 (0)