Skip to content

Commit 2355c12

Browse files
committed
fix(sdk-api): fix proxy-agent usage
We removed the superagent-proxy earlier to use proxy-agent. The change missed some old usage. Change the proxy-agent version to 5.0. This is the version that was used under the hood. The new version requires setting proxy url in the environment variable. It does not quite fit how we use the proxy-agent currently. Ticket: WP-1185
1 parent 1de6f16 commit 2355c12

File tree

3 files changed

+121
-103
lines changed

3 files changed

+121
-103
lines changed

modules/sdk-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"debug": "3.1.0",
6363
"eol": "^0.5.0",
6464
"lodash": "^4.17.15",
65-
"proxy-agent": "6.3.1",
65+
"proxy-agent": "5.0.0",
6666
"sanitize-html": "^2.11",
6767
"secp256k1": "^4.0.2",
6868
"secrets.js-grempe": "^1.1.0",

modules/sdk-api/src/bitgoAPI.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const TransactionBuilder = require('./v1/transactionBuilder');
9898
let proxyAgent: any;
9999
if (!isBrowser && !isWebWorker) {
100100
debug('enabling proxy-agent');
101-
proxyAgent = require('proxy-agent').ProxyAgent;
101+
proxyAgent = require('proxy-agent');
102102
}
103103

104104
const patchedRequestMethods = ['get', 'post', 'put', 'del', 'patch'] as const;
@@ -574,7 +574,13 @@ export class BitGoAPI implements BitGoBase {
574574
// Proxy settings must still be respected however
575575
const resultPromise = this.getAgentRequest('get', this.url('/client/constants'));
576576
resultPromise.set('BitGo-SDK-Version', this._version);
577-
const result = await (this._proxy ? resultPromise.proxy(this._proxy) : resultPromise);
577+
if (this._proxy) {
578+
const agent = new proxyAgent(this._proxy);
579+
if (agent) {
580+
resultPromise.agent(agent);
581+
}
582+
}
583+
const result = await resultPromise;
578584
BitGoAPI._constants[env] = result.body.constants;
579585

580586
if (result.body?.ttl && typeof result.body?.ttl === 'number') {

0 commit comments

Comments
 (0)