@journeyapps/https-proxy-socket 0.0.0-dev.017897d

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.
Files changed (51) hide show
  1. package/LICENSE.txt +7 -0
  2. package/README.md +101 -0
  3. package/lib/cjs/HttpsProxySocket.d.ts +42 -0
  4. package/lib/cjs/HttpsProxySocket.d.ts.map +1 -0
  5. package/lib/cjs/HttpsProxySocket.js +205 -0
  6. package/lib/cjs/HttpsProxySocket.js.map +1 -0
  7. package/lib/cjs/bin/mongoReplicas.d.ts +3 -0
  8. package/lib/cjs/bin/mongoReplicas.d.ts.map +1 -0
  9. package/lib/cjs/bin/mongoReplicas.js +26 -0
  10. package/lib/cjs/bin/mongoReplicas.js.map +1 -0
  11. package/lib/cjs/index.d.ts +4 -0
  12. package/lib/cjs/index.d.ts.map +1 -0
  13. package/lib/cjs/index.js +20 -0
  14. package/lib/cjs/index.js.map +1 -0
  15. package/lib/cjs/mongoPatch.d.ts +16 -0
  16. package/lib/cjs/mongoPatch.d.ts.map +1 -0
  17. package/lib/cjs/mongoPatch.js +58 -0
  18. package/lib/cjs/mongoPatch.js.map +1 -0
  19. package/lib/cjs/proxyAgent.d.ts +11 -0
  20. package/lib/cjs/proxyAgent.d.ts.map +1 -0
  21. package/lib/cjs/proxyAgent.js +71 -0
  22. package/lib/cjs/proxyAgent.js.map +1 -0
  23. package/lib/cjs/tediousPatch.d.ts +9 -0
  24. package/lib/cjs/tediousPatch.d.ts.map +1 -0
  25. package/lib/cjs/tediousPatch.js +24 -0
  26. package/lib/cjs/tediousPatch.js.map +1 -0
  27. package/lib/esm/HttpsProxySocket.d.ts +42 -0
  28. package/lib/esm/HttpsProxySocket.d.ts.map +1 -0
  29. package/lib/esm/HttpsProxySocket.js +168 -0
  30. package/lib/esm/HttpsProxySocket.js.map +1 -0
  31. package/lib/esm/bin/mongoReplicas.d.ts +3 -0
  32. package/lib/esm/bin/mongoReplicas.d.ts.map +1 -0
  33. package/lib/esm/bin/mongoReplicas.js +24 -0
  34. package/lib/esm/bin/mongoReplicas.js.map +1 -0
  35. package/lib/esm/index.d.ts +4 -0
  36. package/lib/esm/index.d.ts.map +1 -0
  37. package/lib/esm/index.js +4 -0
  38. package/lib/esm/index.js.map +1 -0
  39. package/lib/esm/mongoPatch.d.ts +16 -0
  40. package/lib/esm/mongoPatch.d.ts.map +1 -0
  41. package/lib/esm/mongoPatch.js +22 -0
  42. package/lib/esm/mongoPatch.js.map +1 -0
  43. package/lib/esm/proxyAgent.d.ts +11 -0
  44. package/lib/esm/proxyAgent.d.ts.map +1 -0
  45. package/lib/esm/proxyAgent.js +32 -0
  46. package/lib/esm/proxyAgent.js.map +1 -0
  47. package/lib/esm/tediousPatch.d.ts +9 -0
  48. package/lib/esm/tediousPatch.d.ts.map +1 -0
  49. package/lib/esm/tediousPatch.js +21 -0
  50. package/lib/esm/tediousPatch.js.map +1 -0
  51. package/package.json +53 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Journey Mobile, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # https-proxy-socket
2
+
3
+ Node library to enable opening Socket connections via an HTTPS proxy.
4
+
5
+ Based on the implementation in https://github.com/TooTallNate/node-https-proxy-agent,
6
+ but adapted to expose raw Sockets, instead of just http/https requests.
7
+
8
+ ## Installation
9
+
10
+ yarn add @journeyapps/https-proxy-socket
11
+
12
+ ## Usage - node-fetch
13
+
14
+ const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
15
+ const fetch = require('node-fetch');
16
+
17
+ // Proxy connection options
18
+ const proxy = new HttpsProxySocket('https://my-proxy.test', {
19
+ // Proxy auth and headers may be set here, for example:
20
+ auth: 'myuser:mypassword' // Basic auth
21
+ });
22
+
23
+ const agent = proxy.agent({
24
+ // Additional TLS options for the host may be set here, for example:
25
+ // rejectUnauthorized: false, // Disable TLS checks completely (dangerous)
26
+ // ca: fs.readFileSync('my-ca-cert.pem') // Use a custom CA cert
27
+
28
+ // Documentation of the available options is available here:
29
+ // https://nodejs.org/api/tls.html#tls_new_tls_tlssocket_socket_options
30
+ // https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
31
+ });
32
+
33
+ const response = await fetch('https://myhost.test', { agent: agent });
34
+
35
+ ## Usage - Direct socket
36
+
37
+ const { HttpsProxySocket } = require('@journeyapps/https-proxy-socket');
38
+ const proxy = new HttpsProxySocket('https://my-proxy.test');
39
+
40
+ const socket = await proxy.connect({host: 'myhost.test', port: 1234});
41
+
42
+ ## Usage - mssql
43
+
44
+ const sql = require('mssql')
45
+ const { HttpsProxySocket, useProxyForTedious } = require('@journeyapps/https-proxy-socket');
46
+
47
+ const proxy = new HttpsProxySocket({
48
+ // Same as above
49
+ });
50
+
51
+ // Register the proxy globally for tedious/mssql
52
+ useProxyForTedious(proxy);
53
+
54
+ async function run() {
55
+ // Connect using the proxy
56
+ await sql.connect('mssql://username:pwd@myserver.database.windows.net/mydb?encrypt=true')
57
+ try {
58
+ const result = await sql.query`Select TOP(1) * from mytable`
59
+ console.dir(result);
60
+ } finally {
61
+ await sql.close();
62
+ }
63
+ }
64
+
65
+ run().catch(console.error);
66
+
67
+
68
+ ## Usage - MongoDB
69
+ The socks package needs to be added to your package.json dependencies for this to work.
70
+ See the MongoDB documentation for details: https://www.mongodb.com/docs/drivers/node/current/security/socks/
71
+
72
+ import * as mongo from 'mongodb';
73
+ import { useProxyForMongo } from '@journeyapps/https-proxy-socket';
74
+
75
+ const SRV_URI = 'mongodb+srv://<username>:<password>@cluster0.jzuewet.mongodb.net';
76
+ const PROXY = 'us-cc-proxy.journeyapps.com'; // Or za-cc-proxy.journeyapps.com
77
+ const PROXY_PORT = 443
78
+
79
+ // Register the proxy globally for MongoDB
80
+ useProxyForMongo({
81
+ proxy: PROXY,
82
+ auth: <egress_token>
83
+ });
84
+
85
+ async function run() {
86
+ const client = new mongo.MongoClient(SRV_URI, {
87
+ proxyPort: PROXY_PORT,
88
+ proxyHost: PROXY,
89
+ });
90
+ try {
91
+ const database = client.db('poc');
92
+ const data = database.collection('data');
93
+
94
+ const results = await data.find({ index: { $lt: 5 } }).toArray();
95
+ console.log(results);
96
+ } finally {
97
+ await client.close();
98
+ }
99
+ }
100
+
101
+ run().catch(console.error);
@@ -0,0 +1,42 @@
1
+ import * as tls from 'tls';
2
+ export interface HttpsProxyConfig extends tls.ConnectionOptions {
3
+ headers?: {
4
+ [key: string]: string;
5
+ };
6
+ auth?: string;
7
+ }
8
+ export interface ConnectionOptions {
9
+ host: string;
10
+ port: number;
11
+ }
12
+ /**
13
+ * The HttpsProxySocket class allows creating Socket connections via an HTTPS proxy.
14
+ * HTTP proxies are not supported.
15
+ * For http(s) requests, use HttpsProxyAgent as a wrapper around this.
16
+ */
17
+ export declare class HttpsProxySocket {
18
+ proxy: tls.ConnectionOptions;
19
+ proxyConfig: HttpsProxyConfig;
20
+ /**
21
+ *
22
+ * @param opts - The connection options to the proxy. At least host and port are required.
23
+ * Use {rejectUnauthorized: true} to ignore certificates for the proxy (not the endpoint).
24
+ * @param proxyConfig - { auth: 'username:password' } for basic auth.
25
+ * { headers: {key: 'value'} } for custom headers.
26
+ */
27
+ constructor(opts: tls.ConnectionOptions | string, proxyConfig?: HttpsProxyConfig);
28
+ /**
29
+ * Create a new Socket connection.
30
+ *
31
+ * @param opts - host and port
32
+ */
33
+ connect(opts: ConnectionOptions): Promise<tls.TLSSocket>;
34
+ /**
35
+ * Construct an agent for http(s) requests.
36
+ *
37
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
38
+ */
39
+ agent(options?: tls.ConnectionOptions): import("agent-base").Agent;
40
+ private _connect;
41
+ }
42
+ //# sourceMappingURL=HttpsProxySocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpsProxySocket.d.ts","sourceRoot":"","sources":["../../src/HttpsProxySocket.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAM3B,MAAM,WAAW,gBAAiB,SAAQ,GAAG,CAAC,iBAAiB;IAC7D,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,KAAK,EAAE,GAAG,CAAC,iBAAiB,CAAC;IAC7B,WAAW,EAAE,gBAAgB,CAAC;IAE9B;;;;;;OAMG;gBACS,IAAI,EAAE,GAAG,CAAC,iBAAiB,GAAG,MAAM,EAAE,WAAW,CAAC,EAAE,gBAAgB;IAqBhF;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAexD;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,iBAAiB;IAIrC,OAAO,CAAC,QAAQ;CAwHjB"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ // Based on https://github.com/TooTallNate/node-https-proxy-agent
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.HttpsProxySocket = void 0;
38
+ const tls = __importStar(require("tls"));
39
+ const url = __importStar(require("url"));
40
+ const proxyAgent_1 = require("./proxyAgent");
41
+ const util_1 = require("util");
42
+ const debug = (0, util_1.debug)('https-proxy');
43
+ /**
44
+ * The HttpsProxySocket class allows creating Socket connections via an HTTPS proxy.
45
+ * HTTP proxies are not supported.
46
+ * For http(s) requests, use HttpsProxyAgent as a wrapper around this.
47
+ */
48
+ class HttpsProxySocket {
49
+ /**
50
+ *
51
+ * @param opts - The connection options to the proxy. At least host and port are required.
52
+ * Use {rejectUnauthorized: true} to ignore certificates for the proxy (not the endpoint).
53
+ * @param proxyConfig - { auth: 'username:password' } for basic auth.
54
+ * { headers: {key: 'value'} } for custom headers.
55
+ */
56
+ constructor(opts, proxyConfig) {
57
+ let sanitizedOptions;
58
+ if (typeof opts == 'string') {
59
+ let parsedOptions = url.parse(opts);
60
+ sanitizedOptions = {
61
+ host: parsedOptions.hostname || parsedOptions.host,
62
+ port: parseInt(parsedOptions.port || '443'),
63
+ };
64
+ }
65
+ else {
66
+ sanitizedOptions = Object.assign({}, opts);
67
+ }
68
+ if (!opts) {
69
+ throw new Error('an HTTP(S) proxy server `host` and `port` must be specified!');
70
+ }
71
+ debug('creating new HttpsProxyAgent instance: %o', sanitizedOptions);
72
+ this.proxyConfig = proxyConfig || {};
73
+ this.proxy = sanitizedOptions;
74
+ }
75
+ /**
76
+ * Create a new Socket connection.
77
+ *
78
+ * @param opts - host and port
79
+ */
80
+ connect(opts) {
81
+ return new Promise((resolve, reject) => {
82
+ this._connect(opts, (error, socket) => {
83
+ if (error) {
84
+ reject(error);
85
+ }
86
+ else {
87
+ if (!socket) {
88
+ return reject(new Error('No socket returned from proxy'));
89
+ }
90
+ resolve(socket);
91
+ }
92
+ });
93
+ });
94
+ }
95
+ /**
96
+ * Construct an agent for http(s) requests.
97
+ *
98
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
99
+ */
100
+ agent(options) {
101
+ return (0, proxyAgent_1.proxyAgent)(this, options);
102
+ }
103
+ _connect(opts, cb) {
104
+ const proxy = this.proxy;
105
+ // create a socket connection to the proxy server
106
+ const socket = tls.connect(proxy);
107
+ // we need to buffer any HTTP traffic that happens with the proxy before we get
108
+ // the CONNECT response, so that if the response is anything other than an "200"
109
+ // response code, then we can re-play the "data" events on the socket once the
110
+ // HTTP parser is hooked up...
111
+ let buffers = [];
112
+ let buffersLength = 0;
113
+ function read() {
114
+ var b = socket.read();
115
+ if (b) {
116
+ ondata(b);
117
+ }
118
+ else {
119
+ socket.once('readable', read);
120
+ }
121
+ }
122
+ function cleanup() {
123
+ socket.removeListener('data', ondata);
124
+ socket.removeListener('end', onend);
125
+ socket.removeListener('error', onerror);
126
+ socket.removeListener('close', onclose);
127
+ socket.removeListener('readable', read);
128
+ }
129
+ function onclose(err) {
130
+ debug('onclose had error %o', err);
131
+ }
132
+ function onend() {
133
+ debug('onend');
134
+ }
135
+ function onerror(err) {
136
+ cleanup();
137
+ cb(err, null);
138
+ }
139
+ const END_OF_HEADERS = '\r\n\r\n';
140
+ function ondata(b) {
141
+ buffers.push(b);
142
+ buffersLength += b.length;
143
+ // Headers (including URLs) are generally ISO-8859-1 or ASCII.
144
+ // The subset used by an HTTPS proxy should always be safe as ASCII.
145
+ const buffered = Buffer.concat(buffers, buffersLength);
146
+ const str = buffered.toString('ascii');
147
+ if (str.indexOf(END_OF_HEADERS) < 0) {
148
+ // keep buffering
149
+ debug('have not received end of HTTP headers yet...');
150
+ if (socket.readable) {
151
+ read();
152
+ }
153
+ else {
154
+ socket.once('data', ondata);
155
+ }
156
+ return;
157
+ }
158
+ const firstLine = str.substring(0, str.indexOf('\r\n'));
159
+ const statusCode = parseInt(firstLine.split(' ')[1], 10);
160
+ debug('got proxy server response: %o', firstLine);
161
+ if (200 == statusCode) {
162
+ // 200 Connected status code!
163
+ const sock = socket;
164
+ // nullify the buffered data since we won't be needing it
165
+ buffers = [];
166
+ cleanup();
167
+ cb(null, sock);
168
+ }
169
+ else {
170
+ // some other status code that's not 200... need to re-play the HTTP header
171
+ // "data" events onto the socket once the HTTP machinery is attached so that
172
+ // the user can parse and handle the error status code
173
+ cleanup();
174
+ // nullify the buffered data since we won't be needing it
175
+ buffers = [];
176
+ cleanup();
177
+ socket.end();
178
+ cb(new Error('Proxy connection failed: ' + firstLine), null);
179
+ }
180
+ }
181
+ socket.on('error', onerror);
182
+ socket.on('close', onclose);
183
+ socket.on('end', onend);
184
+ if (socket.readable) {
185
+ read();
186
+ }
187
+ else {
188
+ socket.once('data', ondata);
189
+ }
190
+ const host = `${opts.host}:${opts.port}`;
191
+ var msg = 'CONNECT ' + host + ' HTTP/1.1\r\n';
192
+ var headers = Object.assign({}, this.proxyConfig.headers);
193
+ if (this.proxyConfig.auth) {
194
+ headers['Proxy-Authorization'] = 'Basic ' + Buffer.from(this.proxyConfig.auth).toString('base64');
195
+ }
196
+ headers['Host'] = host;
197
+ headers['Connection'] = 'close';
198
+ Object.keys(headers).forEach(function (name) {
199
+ msg += name + ': ' + headers[name] + '\r\n';
200
+ });
201
+ socket.write(msg + '\r\n');
202
+ }
203
+ }
204
+ exports.HttpsProxySocket = HttpsProxySocket;
205
+ //# sourceMappingURL=HttpsProxySocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpsProxySocket.js","sourceRoot":"","sources":["../../src/HttpsProxySocket.ts"],"names":[],"mappings":";AAAA,iEAAiE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEjE,yCAA2B;AAC3B,yCAA2B;AAC3B,6CAA0C;AAC1C,+BAA0C;AAC1C,MAAM,KAAK,GAAG,IAAA,YAAS,EAAC,aAAa,CAAC,CAAC;AAYvC;;;;GAIG;AACH,MAAa,gBAAgB;IAI3B;;;;;;OAMG;IACH,YAAY,IAAoC,EAAE,WAA8B;QAC9E,IAAI,gBAAgB,CAAC;QACrB,IAAI,OAAO,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC5B,IAAI,aAAa,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpC,gBAAgB,GAAG;gBACjB,IAAI,EAAE,aAAa,CAAC,QAAQ,IAAI,aAAa,CAAC,IAAI;gBAClD,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,IAAI,IAAI,KAAK,CAAC;aAC5C,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,gBAAgB,G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"mappings":""}
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const promises_1 = require("dns/promises");
5
+ /**
6
+ * NPX script to resolve MongoDB SRV records.
7
+ * @example npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://<username>:<password>@cluster1.vlnzcbp.mongodb.net
8
+ * @example npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://cluster1.vlnzcbp.mongodb.net
9
+ *
10
+ * @returns An object with a `replicas` property containing the resolved host:port pairs.
11
+ */
12
+ async function mongoReplicas() {
13
+ const srvUrl = process.argv[3];
14
+ const url = new URL(srvUrl);
15
+ if (url.protocol !== 'mongodb+srv:') {
16
+ throw new Error('URL must start with mongodb+srv://');
17
+ }
18
+ const hostname = url.hostname;
19
+ const srvRecords = await (0, promises_1.resolveSrv)(`_mongodb._tcp.${hostname}`);
20
+ const targets = srvRecords.map((r) => `${r.name}:${r.port}`);
21
+ return { replicas: targets.join(',') };
22
+ }
23
+ mongoReplicas()
24
+ .then((result) => console.log(result))
25
+ .catch((error) => console.error(error));
26
+ //# sourceMappingURL=mongoReplicas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoReplicas.js","sourceRoot":"","sources":["../../../src/bin/mongoReplicas.ts"],"names":[],"mappings":";;;AACA,2CAA0C;AAE1C;;;;;;GAMG;AACH,KAAK,UAAU,aAAa;IAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,GAAG,CAAC,QAAQ,KAAK,cAAc,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC9B,MAAM,UAAU,GAAG,MAAM,IAAA,qBAAU,EAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACzC,CAAC;AAED,aAAa,EAAE;KACZ,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KACrC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './HttpsProxySocket';
2
+ export * from './tediousPatch';
3
+ export * from './mongoPatch';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./HttpsProxySocket"), exports);
18
+ __exportStar(require("./tediousPatch"), exports);
19
+ __exportStar(require("./mongoPatch"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,iDAA+B;AAC/B,+CAA6B"}
@@ -0,0 +1,16 @@
1
+ import * as tls from 'tls';
2
+ interface Config {
3
+ /** The journey apps cc egress token */
4
+ auth: string;
5
+ /** The journey apps cc egress proxy domain */
6
+ proxy: string;
7
+ }
8
+ /**
9
+ * The patch should be called before instantiating the MongoClient
10
+ * @param config - The configuration for the proxy
11
+ */
12
+ export declare function useProxyForMongo(config: Config): {
13
+ close: () => tls.TLSSocket;
14
+ };
15
+ export {};
16
+ //# sourceMappingURL=mongoPatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoPatch.d.ts","sourceRoot":"","sources":["../../src/mongoPatch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAG3B,UAAU,MAAM;IACd,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;CACf;AACD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM;;EAc9C"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useProxyForMongo = useProxyForMongo;
37
+ const socks = __importStar(require("socks"));
38
+ const HttpsProxySocket_1 = require("./HttpsProxySocket");
39
+ /**
40
+ * The patch should be called before instantiating the MongoClient
41
+ * @param config - The configuration for the proxy
42
+ */
43
+ function useProxyForMongo(config) {
44
+ let socket;
45
+ socks.SocksClient.createConnection = async (options, callback) => {
46
+ const proxy = new HttpsProxySocket_1.HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth });
47
+ return new Promise(async (resolve, reject) => {
48
+ socket = await proxy.connect({ host: options.destination.host, port: options.destination.port });
49
+ resolve({
50
+ socket,
51
+ });
52
+ });
53
+ };
54
+ return {
55
+ close: () => socket?.end()
56
+ };
57
+ }
58
+ //# sourceMappingURL=mongoPatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoPatch.js","sourceRoot":"","sources":["../../src/mongoPatch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,4CAcC;AA5BD,6CAA+B;AAE/B,yDAAsD;AAQtD;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,IAAI,MAAqB,CAAA;IACzB,KAAK,CAAC,WAAW,CAAC,gBAAgB,GAAG,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;QAC/D,MAAM,KAAK,GAAG,IAAI,mCAAgB,CAAC,WAAW,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACrF,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;YACjG,OAAO,CAAC;gBACN,MAAM;aACP,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;KAC3B,CAAA;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { HttpsProxySocket } from './HttpsProxySocket';
2
+ import agentBase from 'agent-base';
3
+ import * as tls from 'tls';
4
+ /**
5
+ * Construct an agent for http(s) requests. Mostly for testing purposes.
6
+ *
7
+ * @param proxy - the proxy to use
8
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
9
+ */
10
+ export declare function proxyAgent(proxy: HttpsProxySocket, options?: tls.ConnectionOptions): agentBase.Agent;
11
+ //# sourceMappingURL=proxyAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxyAgent.d.ts","sourceRoot":"","sources":["../../src/proxyAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,iBAAiB,mBAsBlF"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.proxyAgent = proxyAgent;
40
+ const agent_base_1 = __importDefault(require("agent-base"));
41
+ const tls = __importStar(require("tls"));
42
+ /**
43
+ * Construct an agent for http(s) requests. Mostly for testing purposes.
44
+ *
45
+ * @param proxy - the proxy to use
46
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
47
+ */
48
+ function proxyAgent(proxy, options) {
49
+ return (0, agent_base_1.default)(async (req, opts) => {
50
+ const socket = await proxy.connect(opts);
51
+ if (opts.secureEndpoint) {
52
+ // Upgrade to TLS
53
+ let tlsOptions = {
54
+ socket: socket,
55
+ servername: opts.servername || opts.host
56
+ };
57
+ if (typeof opts.rejectUnauthorized != 'undefined') {
58
+ // There's a difference between 'undefined' (equivalent of false) and "not set" (equivalent of true)
59
+ tlsOptions.rejectUnauthorized = opts.rejectUnauthorized;
60
+ }
61
+ Object.assign(tlsOptions, options);
62
+ const tlsSocket = tls.connect(tlsOptions);
63
+ return tlsSocket;
64
+ }
65
+ else {
66
+ socket.resume();
67
+ return socket;
68
+ }
69
+ });
70
+ }
71
+ //# sourceMappingURL=proxyAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxyAgent.js","sourceRoot":"","sources":["../../src/proxyAgent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,gCAsBC;AA/BD,4DAAmC;AACnC,yCAA2B;AAE3B;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAuB,EAAE,OAA+B;IACjF,OAAO,IAAA,oBAAS,EAAC,KAAK,EAAE,GAA4B,EAAE,IAAS,EAAE,EAAE;QACjE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,iBAAiB;YACjB,IAAI,UAAU,GAA0B;gBACtC,MAAM,EAAE,MAAM;gBACd,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI;aACzC,CAAC;YACF,IAAI,OAAO,IAAI,CAAC,kBAAkB,IAAI,WAAW,EAAE,CAAC;gBAClD,oGAAoG;gBACpG,UAAU,CAAC,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;YAC1D,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACnC,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC1C,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { HttpsProxySocket } from './HttpsProxySocket';
2
+ /**
3
+ * Replace the connection method on the tedious library (used by mssql)
4
+ * to connect via a proxy.
5
+ *
6
+ * @param proxy - the proxy to use
7
+ */
8
+ export declare function useProxyForTedious(proxy: HttpsProxySocket): void;
9
+ //# sourceMappingURL=tediousPatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tediousPatch.d.ts","sourceRoot":"","sources":["../../src/tediousPatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,QAWzD"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useProxyForTedious = useProxyForTedious;
4
+ const debug = require('debug')('https-proxy');
5
+ /**
6
+ * Replace the connection method on the tedious library (used by mssql)
7
+ * to connect via a proxy.
8
+ *
9
+ * @param proxy - the proxy to use
10
+ */
11
+ function useProxyForTedious(proxy) {
12
+ const { Connector } = require('tedious/lib/connector');
13
+ Connector.prototype.execute = async function (cb) {
14
+ debug(`opening sql connection to ${this.options.host}:${this.options.port}`);
15
+ try {
16
+ const socket = await proxy.connect(this.options);
17
+ cb(null, socket);
18
+ }
19
+ catch (error) {
20
+ cb(error);
21
+ }
22
+ };
23
+ }
24
+ //# sourceMappingURL=tediousPatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tediousPatch.js","sourceRoot":"","sources":["../../src/tediousPatch.ts"],"names":[],"mappings":";;AASA,gDAWC;AAnBD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC;AAE9C;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,KAAuB;IACxD,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACvD,SAAS,CAAC,SAAS,CAAC,OAAO,GAAG,KAAK,WAAW,EAAO;QACnD,KAAK,CAAC,6BAA6B,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACjD,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,EAAE,CAAC,KAAK,CAAC,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,42 @@
1
+ import * as tls from 'tls';
2
+ export interface HttpsProxyConfig extends tls.ConnectionOptions {
3
+ headers?: {
4
+ [key: string]: string;
5
+ };
6
+ auth?: string;
7
+ }
8
+ export interface ConnectionOptions {
9
+ host: string;
10
+ port: number;
11
+ }
12
+ /**
13
+ * The HttpsProxySocket class allows creating Socket connections via an HTTPS proxy.
14
+ * HTTP proxies are not supported.
15
+ * For http(s) requests, use HttpsProxyAgent as a wrapper around this.
16
+ */
17
+ export declare class HttpsProxySocket {
18
+ proxy: tls.ConnectionOptions;
19
+ proxyConfig: HttpsProxyConfig;
20
+ /**
21
+ *
22
+ * @param opts - The connection options to the proxy. At least host and port are required.
23
+ * Use {rejectUnauthorized: true} to ignore certificates for the proxy (not the endpoint).
24
+ * @param proxyConfig - { auth: 'username:password' } for basic auth.
25
+ * { headers: {key: 'value'} } for custom headers.
26
+ */
27
+ constructor(opts: tls.ConnectionOptions | string, proxyConfig?: HttpsProxyConfig);
28
+ /**
29
+ * Create a new Socket connection.
30
+ *
31
+ * @param opts - host and port
32
+ */
33
+ connect(opts: ConnectionOptions): Promise<tls.TLSSocket>;
34
+ /**
35
+ * Construct an agent for http(s) requests.
36
+ *
37
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
38
+ */
39
+ agent(options?: tls.ConnectionOptions): import("agent-base").Agent;
40
+ private _connect;
41
+ }
42
+ //# sourceMappingURL=HttpsProxySocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpsProxySocket.d.ts","sourceRoot":"","sources":["../../src/HttpsProxySocket.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAM3B,MAAM,WAAW,gBAAiB,SAAQ,GAAG,CAAC,iBAAiB;IAC7D,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,KAAK,EAAE,GAAG,CAAC,iBAAiB,CAAC;IAC7B,WAAW,EAAE,gBAAgB,CAAC;IAE9B;;;;;;OAMG;gBACS,IAAI,EAAE,GAAG,CAAC,iBAAiB,GAAG,MAAM,EAAE,WAAW,CAAC,EAAE,gBAAgB;IAqBhF;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAexD;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,iBAAiB;IAIrC,OAAO,CAAC,QAAQ;CAwHjB"}
@@ -0,0 +1,168 @@
1
+ // Based on https://github.com/TooTallNate/node-https-proxy-agent
2
+ import * as tls from 'tls';
3
+ import * as url from 'url';
4
+ import { proxyAgent } from './proxyAgent';
5
+ import { debug as nodeDebug } from 'util';
6
+ const debug = nodeDebug('https-proxy');
7
+ /**
8
+ * The HttpsProxySocket class allows creating Socket connections via an HTTPS proxy.
9
+ * HTTP proxies are not supported.
10
+ * For http(s) requests, use HttpsProxyAgent as a wrapper around this.
11
+ */
12
+ export class HttpsProxySocket {
13
+ /**
14
+ *
15
+ * @param opts - The connection options to the proxy. At least host and port are required.
16
+ * Use {rejectUnauthorized: true} to ignore certificates for the proxy (not the endpoint).
17
+ * @param proxyConfig - { auth: 'username:password' } for basic auth.
18
+ * { headers: {key: 'value'} } for custom headers.
19
+ */
20
+ constructor(opts, proxyConfig) {
21
+ let sanitizedOptions;
22
+ if (typeof opts == 'string') {
23
+ let parsedOptions = url.parse(opts);
24
+ sanitizedOptions = {
25
+ host: parsedOptions.hostname || parsedOptions.host,
26
+ port: parseInt(parsedOptions.port || '443'),
27
+ };
28
+ }
29
+ else {
30
+ sanitizedOptions = Object.assign({}, opts);
31
+ }
32
+ if (!opts) {
33
+ throw new Error('an HTTP(S) proxy server `host` and `port` must be specified!');
34
+ }
35
+ debug('creating new HttpsProxyAgent instance: %o', sanitizedOptions);
36
+ this.proxyConfig = proxyConfig || {};
37
+ this.proxy = sanitizedOptions;
38
+ }
39
+ /**
40
+ * Create a new Socket connection.
41
+ *
42
+ * @param opts - host and port
43
+ */
44
+ connect(opts) {
45
+ return new Promise((resolve, reject) => {
46
+ this._connect(opts, (error, socket) => {
47
+ if (error) {
48
+ reject(error);
49
+ }
50
+ else {
51
+ if (!socket) {
52
+ return reject(new Error('No socket returned from proxy'));
53
+ }
54
+ resolve(socket);
55
+ }
56
+ });
57
+ });
58
+ }
59
+ /**
60
+ * Construct an agent for http(s) requests.
61
+ *
62
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
63
+ */
64
+ agent(options) {
65
+ return proxyAgent(this, options);
66
+ }
67
+ _connect(opts, cb) {
68
+ const proxy = this.proxy;
69
+ // create a socket connection to the proxy server
70
+ const socket = tls.connect(proxy);
71
+ // we need to buffer any HTTP traffic that happens with the proxy before we get
72
+ // the CONNECT response, so that if the response is anything other than an "200"
73
+ // response code, then we can re-play the "data" events on the socket once the
74
+ // HTTP parser is hooked up...
75
+ let buffers = [];
76
+ let buffersLength = 0;
77
+ function read() {
78
+ var b = socket.read();
79
+ if (b) {
80
+ ondata(b);
81
+ }
82
+ else {
83
+ socket.once('readable', read);
84
+ }
85
+ }
86
+ function cleanup() {
87
+ socket.removeListener('data', ondata);
88
+ socket.removeListener('end', onend);
89
+ socket.removeListener('error', onerror);
90
+ socket.removeListener('close', onclose);
91
+ socket.removeListener('readable', read);
92
+ }
93
+ function onclose(err) {
94
+ debug('onclose had error %o', err);
95
+ }
96
+ function onend() {
97
+ debug('onend');
98
+ }
99
+ function onerror(err) {
100
+ cleanup();
101
+ cb(err, null);
102
+ }
103
+ const END_OF_HEADERS = '\r\n\r\n';
104
+ function ondata(b) {
105
+ buffers.push(b);
106
+ buffersLength += b.length;
107
+ // Headers (including URLs) are generally ISO-8859-1 or ASCII.
108
+ // The subset used by an HTTPS proxy should always be safe as ASCII.
109
+ const buffered = Buffer.concat(buffers, buffersLength);
110
+ const str = buffered.toString('ascii');
111
+ if (str.indexOf(END_OF_HEADERS) < 0) {
112
+ // keep buffering
113
+ debug('have not received end of HTTP headers yet...');
114
+ if (socket.readable) {
115
+ read();
116
+ }
117
+ else {
118
+ socket.once('data', ondata);
119
+ }
120
+ return;
121
+ }
122
+ const firstLine = str.substring(0, str.indexOf('\r\n'));
123
+ const statusCode = parseInt(firstLine.split(' ')[1], 10);
124
+ debug('got proxy server response: %o', firstLine);
125
+ if (200 == statusCode) {
126
+ // 200 Connected status code!
127
+ const sock = socket;
128
+ // nullify the buffered data since we won't be needing it
129
+ buffers = [];
130
+ cleanup();
131
+ cb(null, sock);
132
+ }
133
+ else {
134
+ // some other status code that's not 200... need to re-play the HTTP header
135
+ // "data" events onto the socket once the HTTP machinery is attached so that
136
+ // the user can parse and handle the error status code
137
+ cleanup();
138
+ // nullify the buffered data since we won't be needing it
139
+ buffers = [];
140
+ cleanup();
141
+ socket.end();
142
+ cb(new Error('Proxy connection failed: ' + firstLine), null);
143
+ }
144
+ }
145
+ socket.on('error', onerror);
146
+ socket.on('close', onclose);
147
+ socket.on('end', onend);
148
+ if (socket.readable) {
149
+ read();
150
+ }
151
+ else {
152
+ socket.once('data', ondata);
153
+ }
154
+ const host = `${opts.host}:${opts.port}`;
155
+ var msg = 'CONNECT ' + host + ' HTTP/1.1\r\n';
156
+ var headers = Object.assign({}, this.proxyConfig.headers);
157
+ if (this.proxyConfig.auth) {
158
+ headers['Proxy-Authorization'] = 'Basic ' + Buffer.from(this.proxyConfig.auth).toString('base64');
159
+ }
160
+ headers['Host'] = host;
161
+ headers['Connection'] = 'close';
162
+ Object.keys(headers).forEach(function (name) {
163
+ msg += name + ': ' + headers[name] + '\r\n';
164
+ });
165
+ socket.write(msg + '\r\n');
166
+ }
167
+ }
168
+ //# sourceMappingURL=HttpsProxySocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpsProxySocket.js","sourceRoot":"","sources":["../../src/HttpsProxySocket.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAC1C,MAAM,KAAK,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;AAYvC;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAI3B;;;;;;OAMG;IACH,YAAY,IAAoC,EAAE,WAA8B;QAC9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CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=mongoReplicas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoReplicas.d.ts","sourceRoot":"","sources":["../../../src/bin/mongoReplicas.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import { resolveSrv } from 'dns/promises';
3
+ /**
4
+ * NPX script to resolve MongoDB SRV records.
5
+ * @example npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://<username>:<password>@cluster1.vlnzcbp.mongodb.net
6
+ * @example npx @journeyapps/https-proxy-socket mongo-replicas mongodb+srv://cluster1.vlnzcbp.mongodb.net
7
+ *
8
+ * @returns An object with a `replicas` property containing the resolved host:port pairs.
9
+ */
10
+ async function mongoReplicas() {
11
+ const srvUrl = process.argv[3];
12
+ const url = new URL(srvUrl);
13
+ if (url.protocol !== 'mongodb+srv:') {
14
+ throw new Error('URL must start with mongodb+srv://');
15
+ }
16
+ const hostname = url.hostname;
17
+ const srvRecords = await resolveSrv(`_mongodb._tcp.${hostname}`);
18
+ const targets = srvRecords.map((r) => `${r.name}:${r.port}`);
19
+ return { replicas: targets.join(',') };
20
+ }
21
+ mongoReplicas()
22
+ .then((result) => console.log(result))
23
+ .catch((error) => console.error(error));
24
+ //# sourceMappingURL=mongoReplicas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoReplicas.js","sourceRoot":"","sources":["../../../src/bin/mongoReplicas.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;GAMG;AACH,KAAK,UAAU,aAAa;IAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,GAAG,CAAC,QAAQ,KAAK,cAAc,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC9B,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACzC,CAAC;AAED,aAAa,EAAE;KACZ,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KACrC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './HttpsProxySocket';
2
+ export * from './tediousPatch';
3
+ export * from './mongoPatch';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './HttpsProxySocket';
2
+ export * from './tediousPatch';
3
+ export * from './mongoPatch';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,16 @@
1
+ import * as tls from 'tls';
2
+ interface Config {
3
+ /** The journey apps cc egress token */
4
+ auth: string;
5
+ /** The journey apps cc egress proxy domain */
6
+ proxy: string;
7
+ }
8
+ /**
9
+ * The patch should be called before instantiating the MongoClient
10
+ * @param config - The configuration for the proxy
11
+ */
12
+ export declare function useProxyForMongo(config: Config): {
13
+ close: () => tls.TLSSocket;
14
+ };
15
+ export {};
16
+ //# sourceMappingURL=mongoPatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoPatch.d.ts","sourceRoot":"","sources":["../../src/mongoPatch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAG3B,UAAU,MAAM;IACd,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;CACf;AACD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM;;EAc9C"}
@@ -0,0 +1,22 @@
1
+ import * as socks from 'socks';
2
+ import { HttpsProxySocket } from './HttpsProxySocket';
3
+ /**
4
+ * The patch should be called before instantiating the MongoClient
5
+ * @param config - The configuration for the proxy
6
+ */
7
+ export function useProxyForMongo(config) {
8
+ let socket;
9
+ socks.SocksClient.createConnection = async (options, callback) => {
10
+ const proxy = new HttpsProxySocket(`https://${config.proxy}`, { auth: config.auth });
11
+ return new Promise(async (resolve, reject) => {
12
+ socket = await proxy.connect({ host: options.destination.host, port: options.destination.port });
13
+ resolve({
14
+ socket,
15
+ });
16
+ });
17
+ };
18
+ return {
19
+ close: () => socket?.end()
20
+ };
21
+ }
22
+ //# sourceMappingURL=mongoPatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoPatch.js","sourceRoot":"","sources":["../../src/mongoPatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAQtD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAI,MAAqB,CAAA;IACzB,KAAK,CAAC,WAAW,CAAC,gBAAgB,GAAG,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;QAC/D,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,WAAW,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACrF,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;YACjG,OAAO,CAAC;gBACN,MAAM;aACP,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IACF,OAAO;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;KAC3B,CAAA;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { HttpsProxySocket } from './HttpsProxySocket';
2
+ import agentBase from 'agent-base';
3
+ import * as tls from 'tls';
4
+ /**
5
+ * Construct an agent for http(s) requests. Mostly for testing purposes.
6
+ *
7
+ * @param proxy - the proxy to use
8
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
9
+ */
10
+ export declare function proxyAgent(proxy: HttpsProxySocket, options?: tls.ConnectionOptions): agentBase.Agent;
11
+ //# sourceMappingURL=proxyAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxyAgent.d.ts","sourceRoot":"","sources":["../../src/proxyAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,iBAAiB,mBAsBlF"}
@@ -0,0 +1,32 @@
1
+ import agentBase from 'agent-base';
2
+ import * as tls from 'tls';
3
+ /**
4
+ * Construct an agent for http(s) requests. Mostly for testing purposes.
5
+ *
6
+ * @param proxy - the proxy to use
7
+ * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
8
+ */
9
+ export function proxyAgent(proxy, options) {
10
+ return agentBase(async (req, opts) => {
11
+ const socket = await proxy.connect(opts);
12
+ if (opts.secureEndpoint) {
13
+ // Upgrade to TLS
14
+ let tlsOptions = {
15
+ socket: socket,
16
+ servername: opts.servername || opts.host
17
+ };
18
+ if (typeof opts.rejectUnauthorized != 'undefined') {
19
+ // There's a difference between 'undefined' (equivalent of false) and "not set" (equivalent of true)
20
+ tlsOptions.rejectUnauthorized = opts.rejectUnauthorized;
21
+ }
22
+ Object.assign(tlsOptions, options);
23
+ const tlsSocket = tls.connect(tlsOptions);
24
+ return tlsSocket;
25
+ }
26
+ else {
27
+ socket.resume();
28
+ return socket;
29
+ }
30
+ });
31
+ }
32
+ //# sourceMappingURL=proxyAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxyAgent.js","sourceRoot":"","sources":["../../src/proxyAgent.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAuB,EAAE,OAA+B;IACjF,OAAO,SAAS,CAAC,KAAK,EAAE,GAA4B,EAAE,IAAS,EAAE,EAAE;QACjE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEzC,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,iBAAiB;YACjB,IAAI,UAAU,GAA0B;gBACtC,MAAM,EAAE,MAAM;gBACd,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI;aACzC,CAAC;YACF,IAAI,OAAO,IAAI,CAAC,kBAAkB,IAAI,WAAW,EAAE,CAAC;gBAClD,oGAAoG;gBACpG,UAAU,CAAC,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;YAC1D,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACnC,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC1C,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { HttpsProxySocket } from './HttpsProxySocket';
2
+ /**
3
+ * Replace the connection method on the tedious library (used by mssql)
4
+ * to connect via a proxy.
5
+ *
6
+ * @param proxy - the proxy to use
7
+ */
8
+ export declare function useProxyForTedious(proxy: HttpsProxySocket): void;
9
+ //# sourceMappingURL=tediousPatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tediousPatch.d.ts","sourceRoot":"","sources":["../../src/tediousPatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,QAWzD"}
@@ -0,0 +1,21 @@
1
+ const debug = require('debug')('https-proxy');
2
+ /**
3
+ * Replace the connection method on the tedious library (used by mssql)
4
+ * to connect via a proxy.
5
+ *
6
+ * @param proxy - the proxy to use
7
+ */
8
+ export function useProxyForTedious(proxy) {
9
+ const { Connector } = require('tedious/lib/connector');
10
+ Connector.prototype.execute = async function (cb) {
11
+ debug(`opening sql connection to ${this.options.host}:${this.options.port}`);
12
+ try {
13
+ const socket = await proxy.connect(this.options);
14
+ cb(null, socket);
15
+ }
16
+ catch (error) {
17
+ cb(error);
18
+ }
19
+ };
20
+ }
21
+ //# sourceMappingURL=tediousPatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tediousPatch.js","sourceRoot":"","sources":["../../src/tediousPatch.ts"],"names":[],"mappings":"AACA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAuB;IACxD,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACvD,SAAS,CAAC,SAAS,CAAC,OAAO,GAAG,KAAK,WAAW,EAAO;QACnD,KAAK,CAAC,6BAA6B,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACjD,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,EAAE,CAAC,KAAK,CAAC,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@journeyapps/https-proxy-socket",
3
+ "version": "0.0.0-dev.017897d",
4
+ "author": "JourneyApps",
5
+ "repository": "journeyapps/https-proxy-socket",
6
+ "license": "MIT",
7
+ "main": "./lib/cjs/index.js",
8
+ "module": "./lib/esm/index.js",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "default": "./lib/esm/index.js",
13
+ "types": "./lib/esm/index.d.ts"
14
+ },
15
+ "require": {
16
+ "default": "./lib/cjs/index.js",
17
+ "types": "./lib/cjs/index.d.ts"
18
+ }
19
+ }
20
+ },
21
+ "bin": {
22
+ "mongo-replicas": "lib/esm/bin/mongoReplicas.js"
23
+ },
24
+ "devDependencies": {
25
+ "@types/agent-base": "^4.2.0",
26
+ "@types/node": "^24.7.2",
27
+ "lerna": "^9.0.0",
28
+ "node-fetch": "^3.3.2",
29
+ "prettier": "^3.6.2",
30
+ "proxy": "^2.2.0",
31
+ "tedious": "^18.6.1",
32
+ "typescript": "^5.9.3",
33
+ "vitest": "^3.2.4"
34
+ },
35
+ "dependencies": {
36
+ "agent-base": "^6.0.2",
37
+ "socks": "^2.8.7"
38
+ },
39
+ "files": [
40
+ "/README.md",
41
+ "/lib"
42
+ ],
43
+ "scripts": {
44
+ "ci:publish": "changeset publish && git push --follow-tags",
45
+ "ci:version": "changeset version && pnpm install --no-frozen-lockfile",
46
+ "clean": "rm -rf ./lib && tsc -b --clean",
47
+ "clean:modules": "rm -rf node_modules",
48
+ "build:esm": "tsc -p tsconfig.esm.json",
49
+ "build:cjs": "tsc -p tsconfig.cjs.json",
50
+ "build": "pnpm build:esm && pnpm build:cjs",
51
+ "test": "vitest run"
52
+ }
53
+ }