@mongodb-js/devtools-proxy-support
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -8,3 +8,3 @@ import type { Agent } from 'https'; | ||
import type { ProxyLogEmitter } from './logging'; | ||
import type { EventEmitter } from 'events'; | ||
import { EventEmitter } from 'events'; | ||
export type AgentWithInitialize = Agent & { | ||
@@ -11,0 +11,0 @@ initialize?(): Promise<void>; |
@@ -8,6 +8,11 @@ "use strict"; | ||
const ssh_1 = require("./ssh"); | ||
const events_1 = require("events"); | ||
const agent_base_1 = require("agent-base"); | ||
const system_ca_1 = require("./system-ca"); | ||
class DevtoolsProxyAgent extends proxy_agent_1.ProxyAgent { | ||
constructor(proxyOptions) { | ||
constructor(proxyOptions, logger) { | ||
const { ca, ...proxyOptionsWithoutCA } = proxyOptions; | ||
void ca; | ||
super({ | ||
...proxyOptions, | ||
...proxyOptionsWithoutCA, | ||
getProxyForUrl: (url) => this._getProxyForUrl(url), | ||
@@ -26,5 +31,6 @@ }); | ||
}; | ||
this.logger = logger; | ||
this.proxyOptions = proxyOptions; | ||
if (proxyOptions.proxy && new URL(proxyOptions.proxy).protocol === 'ssh:') { | ||
this.sshAgent = new ssh_1.SSHAgent(proxyOptions); | ||
this.sshAgent = new ssh_1.SSHAgent(proxyOptions, logger); | ||
} | ||
@@ -36,2 +42,3 @@ } | ||
async connect(req, opts) { | ||
opts.ca = (0, system_ca_1.mergeCA)(this.proxyOptions.ca, opts.ca); | ||
if (this.sshAgent) | ||
@@ -51,4 +58,27 @@ return this.sshAgent; | ||
} | ||
class DevtoolsProxyAgentWithSystemCA extends agent_base_1.Agent { | ||
constructor(proxyOptions) { | ||
super(); | ||
this.logger = new events_1.EventEmitter(); | ||
this.proxyOptions = proxyOptions; | ||
this.agent = (async () => { | ||
const { ca } = await (0, system_ca_1.systemCA)({ ca: proxyOptions.ca }); | ||
return new DevtoolsProxyAgent({ ...proxyOptions, ca }, this.logger); | ||
})(); | ||
this.agent.catch(() => { | ||
}); | ||
} | ||
async initialize() { | ||
const agent = await this.agent; | ||
await agent.initialize?.(); | ||
} | ||
async connect() { | ||
return await this.agent; | ||
} | ||
async destroy() { | ||
(await this.agent).destroy(); | ||
} | ||
} | ||
function createAgent(proxyOptions) { | ||
return new DevtoolsProxyAgent(proxyOptions); | ||
return new DevtoolsProxyAgentWithSystemCA(proxyOptions); | ||
} | ||
@@ -55,0 +85,0 @@ function useOrCreateAgent(proxyOptions, target) { |
@@ -6,2 +6,3 @@ export { DevtoolsProxyOptions, DevtoolsProxyOptionsSecrets, translateToElectronProxyConfig, extractProxySecrets, mergeProxySecrets, } from './proxy-options'; | ||
export { ProxyEventMap, ProxyLogEmitter, hookLogger } from './logging'; | ||
export { systemCA, resetSystemCACache } from './system-ca'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hookLogger = exports.createFetch = exports.useOrCreateAgent = exports.createAgent = exports.createSocks5Tunnel = exports.mergeProxySecrets = exports.extractProxySecrets = exports.translateToElectronProxyConfig = void 0; | ||
exports.resetSystemCACache = exports.systemCA = exports.hookLogger = exports.createFetch = exports.useOrCreateAgent = exports.createAgent = exports.createSocks5Tunnel = exports.mergeProxySecrets = exports.extractProxySecrets = exports.translateToElectronProxyConfig = void 0; | ||
var proxy_options_1 = require("./proxy-options"); | ||
@@ -17,2 +17,5 @@ Object.defineProperty(exports, "translateToElectronProxyConfig", { enumerable: true, get: function () { return proxy_options_1.translateToElectronProxyConfig; } }); | ||
Object.defineProperty(exports, "hookLogger", { enumerable: true, get: function () { return logging_1.hookLogger; } }); | ||
var system_ca_1 = require("./system-ca"); | ||
Object.defineProperty(exports, "systemCA", { enumerable: true, get: function () { return system_ca_1.systemCA; } }); | ||
Object.defineProperty(exports, "resetSystemCACache", { enumerable: true, get: function () { return system_ca_1.resetSystemCACache; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -179,3 +179,3 @@ "use strict"; | ||
function mergeProxySecrets({ proxyOptions, secrets, }) { | ||
const parsedSecrets = JSON.parse(secrets); | ||
const parsedSecrets = JSON.parse(secrets || '{}'); | ||
if ((parsedSecrets.username || parsedSecrets.password) && | ||
@@ -182,0 +182,0 @@ proxyOptions.proxy) { |
@@ -16,3 +16,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/devtools-shared", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"repository": { | ||
@@ -54,3 +54,4 @@ "type": "git", | ||
"socksv5": "^0.0.6", | ||
"ssh2": "^1.15.0" | ||
"ssh2": "^1.15.0", | ||
"system-ca": "^2.0.0" | ||
}, | ||
@@ -79,3 +80,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "cb955eba7effce5aabd90f41119484f253fb1755" | ||
"gitHead": "64b898106d63c9da98f49fe4d9748caad465bad6" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
96006
35
1097
6
2
5
+ Addedsystem-ca@^2.0.0
+ Addedbindings@1.5.0(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedmacos-export-certificate-and-key@1.2.4(transitive)
+ Addednode-addon-api@3.2.14.3.0(transitive)
+ Addedsystem-ca@2.0.1(transitive)
+ Addedwin-export-certificate-and-key@2.1.0(transitive)