@journeyapps/https-proxy-socket 0.2.1 → 1.0.0

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 (72) hide show
  1. package/README.md +105 -51
  2. package/lib/{HttpsProxySocket.d.ts → cjs/HttpsProxySocket.d.ts} +6 -6
  3. package/lib/cjs/HttpsProxySocket.d.ts.map +1 -0
  4. package/lib/{HttpsProxySocket.js → cjs/HttpsProxySocket.js} +64 -33
  5. package/lib/cjs/HttpsProxySocket.js.map +1 -0
  6. package/lib/cjs/ProxyAgent.d.ts +11 -0
  7. package/lib/cjs/ProxyAgent.d.ts.map +1 -0
  8. package/lib/cjs/ProxyAgent.js +67 -0
  9. package/lib/cjs/ProxyAgent.js.map +1 -0
  10. package/lib/cjs/bin/mongoReplicas.d.ts +3 -0
  11. package/lib/cjs/bin/mongoReplicas.d.ts.map +1 -0
  12. package/lib/cjs/bin/mongoReplicas.js +26 -0
  13. package/lib/cjs/bin/mongoReplicas.js.map +1 -0
  14. package/lib/cjs/createProxyAgent.d.ts +11 -0
  15. package/lib/cjs/createProxyAgent.d.ts.map +1 -0
  16. package/lib/cjs/createProxyAgent.js +14 -0
  17. package/lib/cjs/createProxyAgent.js.map +1 -0
  18. package/lib/cjs/index.d.ts +3 -0
  19. package/lib/cjs/index.d.ts.map +1 -0
  20. package/lib/cjs/index.js +19 -0
  21. package/lib/cjs/index.js.map +1 -0
  22. package/lib/cjs/mongoPatch.d.ts +16 -0
  23. package/lib/cjs/mongoPatch.d.ts.map +1 -0
  24. package/lib/cjs/mongoPatch.js +58 -0
  25. package/lib/cjs/mongoPatch.js.map +1 -0
  26. package/lib/cjs/utils/parseOptions.d.ts +3 -0
  27. package/lib/cjs/utils/parseOptions.d.ts.map +1 -0
  28. package/lib/cjs/utils/parseOptions.js +16 -0
  29. package/lib/cjs/utils/parseOptions.js.map +1 -0
  30. package/lib/cjs/utils/setServername.d.ts +3 -0
  31. package/lib/cjs/utils/setServername.d.ts.map +1 -0
  32. package/lib/cjs/utils/setServername.js +47 -0
  33. package/lib/cjs/utils/setServername.js.map +1 -0
  34. package/lib/esm/HttpsProxySocket.d.ts +42 -0
  35. package/lib/esm/HttpsProxySocket.d.ts.map +1 -0
  36. package/lib/esm/HttpsProxySocket.js +197 -0
  37. package/lib/esm/HttpsProxySocket.js.map +1 -0
  38. package/lib/esm/ProxyAgent.d.ts +11 -0
  39. package/lib/esm/ProxyAgent.d.ts.map +1 -0
  40. package/lib/esm/ProxyAgent.js +67 -0
  41. package/lib/esm/ProxyAgent.js.map +1 -0
  42. package/lib/esm/bin/mongoReplicas.d.ts +3 -0
  43. package/lib/esm/bin/mongoReplicas.d.ts.map +1 -0
  44. package/lib/esm/bin/mongoReplicas.js +26 -0
  45. package/lib/esm/bin/mongoReplicas.js.map +1 -0
  46. package/lib/esm/createProxyAgent.d.ts +11 -0
  47. package/lib/esm/createProxyAgent.d.ts.map +1 -0
  48. package/lib/esm/createProxyAgent.js +14 -0
  49. package/lib/esm/createProxyAgent.js.map +1 -0
  50. package/lib/esm/index.d.ts +3 -0
  51. package/lib/esm/index.d.ts.map +1 -0
  52. package/lib/esm/index.js +19 -0
  53. package/lib/esm/index.js.map +1 -0
  54. package/lib/esm/mongoPatch.d.ts +16 -0
  55. package/lib/esm/mongoPatch.d.ts.map +1 -0
  56. package/lib/esm/mongoPatch.js +58 -0
  57. package/lib/esm/mongoPatch.js.map +1 -0
  58. package/lib/esm/utils/parseOptions.d.ts +3 -0
  59. package/lib/esm/utils/parseOptions.d.ts.map +1 -0
  60. package/lib/esm/utils/parseOptions.js +16 -0
  61. package/lib/esm/utils/parseOptions.js.map +1 -0
  62. package/lib/esm/utils/setServername.d.ts +3 -0
  63. package/lib/esm/utils/setServername.d.ts.map +1 -0
  64. package/lib/esm/utils/setServername.js +47 -0
  65. package/lib/esm/utils/setServername.js.map +1 -0
  66. package/package.json +41 -22
  67. package/lib/index.d.ts +0 -2
  68. package/lib/index.js +0 -7
  69. package/lib/proxyAgent.d.ts +0 -11
  70. package/lib/proxyAgent.js +0 -43
  71. package/lib/tediousPatch.d.ts +0 -8
  72. package/lib/tediousPatch.js +0 -34
@@ -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_js_1 = require("./HttpsProxySocket.js");
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_js_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,+DAAyD;AAQzD;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,IAAI,MAAqB,CAAC;IAC1B,KAAK,CAAC,WAAW,CAAC,gBAAgB,GAAG,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;QAC/D,MAAM,KAAK,GAAG,IAAI,sCAAgB,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,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import tls from 'tls';
2
+ export declare function parseOptions(options: tls.ConnectionOptions | string): tls.ConnectionOptions;
3
+ //# sourceMappingURL=parseOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseOptions.d.ts","sourceRoot":"","sources":["../../../src/utils/parseOptions.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,wBAAgB,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,iBAAiB,GAAG,MAAM,yBAUnE"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseOptions = parseOptions;
4
+ function parseOptions(options) {
5
+ if (typeof options != 'string') {
6
+ return options;
7
+ }
8
+ else {
9
+ const parsedOptions = new URL(options);
10
+ return {
11
+ host: parsedOptions.hostname || parsedOptions.host,
12
+ port: parseInt(parsedOptions.port || '443'),
13
+ };
14
+ }
15
+ }
16
+ //# sourceMappingURL=parseOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseOptions.js","sourceRoot":"","sources":["../../../src/utils/parseOptions.ts"],"names":[],"mappings":";;AAEA,oCAUC;AAVD,SAAgB,YAAY,CAAC,OAAuC;IAClE,IAAI,OAAO,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,OAAO,OAAO,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO;YACL,IAAI,EAAE,aAAa,CAAC,QAAQ,IAAI,aAAa,CAAC,IAAI;YAClD,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,IAAI,IAAI,KAAK,CAAC;SAC5C,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import * as tls from 'tls';
2
+ export declare function setServername(options: tls.ConnectionOptions): tls.ConnectionOptions;
3
+ //# sourceMappingURL=setServername.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setServername.d.ts","sourceRoot":"","sources":["../../../src/utils/setServername.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAE3B,wBAAgB,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,iBAAiB,yBAQ3D"}
@@ -0,0 +1,47 @@
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.setServername = setServername;
37
+ const net = __importStar(require("net"));
38
+ function setServername(options) {
39
+ if (options.servername === undefined && options.host && !net.isIP(options.host)) {
40
+ return {
41
+ ...options,
42
+ servername: options.host,
43
+ };
44
+ }
45
+ return options;
46
+ }
47
+ //# sourceMappingURL=setServername.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setServername.js","sourceRoot":"","sources":["../../../src/utils/setServername.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAQC;AAXD,yCAA2B;AAG3B,SAAgB,aAAa,CAAC,OAA8B;IAC1D,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChF,OAAO;YACL,GAAG,OAAO;YACV,UAAU,EAAE,OAAO,CAAC,IAAI;SACzB,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,35 +1,54 @@
1
1
  {
2
2
  "name": "@journeyapps/https-proxy-socket",
3
- "version": "0.2.1",
3
+ "version": "1.0.0",
4
4
  "author": "JourneyApps",
5
5
  "repository": "journeyapps/https-proxy-socket",
6
6
  "license": "MIT",
7
- "scripts": {
8
- "build": "tsc",
9
- "test": "mocha src/*.spec.ts",
10
- "format": "journey-formatter format",
11
- "deploy": "journey-deploy trigger"
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"
12
23
  },
13
24
  "devDependencies": {
14
- "@journeyapps/deploy-cli": "2.6.2",
15
- "@journeyapps/formatter-cli": "^2.6.2",
25
+ "@changesets/cli": "^2.29.7",
16
26
  "@types/agent-base": "^4.2.0",
17
- "@types/mocha": "^5.2.6",
18
- "@types/node": "^11.9.4",
19
- "@types/node-fetch": "^2.1.6",
20
- "agent-base": "^6.0.0",
21
- "assert": "^1.4.1",
22
- "mocha": "^6.0.2",
23
- "mssql": "^4.3.2",
24
- "node-fetch": "^2.3.0",
25
- "proxy": "^1.0.1",
26
- "ts-node": "^8.0.2",
27
- "typescript": "^3.7.5"
27
+ "@types/node": "^24.7.2",
28
+ "async-listen": "^3.1.0",
29
+ "lerna": "^9.0.0",
30
+ "node-fetch": "^3.3.2",
31
+ "prettier": "^3.6.2",
32
+ "proxy": "^2.2.0",
33
+ "typescript": "^5.9.3",
34
+ "vitest": "^3.2.4"
35
+ },
36
+ "dependencies": {
37
+ "agent-base": "^7.1.4",
38
+ "socks": "^2.8.7"
28
39
  },
29
- "main": "./lib/index.js",
30
- "dependencies": {},
31
40
  "files": [
32
41
  "/README.md",
33
42
  "/lib"
34
- ]
43
+ ],
44
+ "scripts": {
45
+ "ci:publish": "changeset publish && git push --follow-tags",
46
+ "ci:version": "changeset version && pnpm install --no-frozen-lockfile",
47
+ "clean": "rm -rf ./lib && tsc -b --clean",
48
+ "clean:modules": "rm -rf node_modules",
49
+ "build:esm": "tsc -p tsconfig.esm.json",
50
+ "build:cjs": "tsc -p tsconfig.cjs.json",
51
+ "build": "pnpm build:esm && pnpm build:cjs",
52
+ "test": "vitest run"
53
+ }
35
54
  }
package/lib/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './HttpsProxySocket';
2
- export * from './tediousPatch';
package/lib/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- __export(require("./HttpsProxySocket"));
7
- __export(require("./tediousPatch"));
@@ -1,11 +0,0 @@
1
- /// <reference types="node" />
2
- import { HttpsProxySocket } from './HttpsProxySocket';
3
- import * as agentBase from 'agent-base';
4
- import * as tls from 'tls';
5
- /**
6
- * Construct an agent for http(s) requests. Mostly for testing purposes.
7
- *
8
- * @param proxy - the proxy to use
9
- * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
10
- */
11
- export declare function proxyAgent(proxy: HttpsProxySocket, options?: tls.ConnectionOptions): agentBase.Agent;
package/lib/proxyAgent.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const agentBase = require("agent-base");
13
- const tls = require("tls");
14
- /**
15
- * Construct an agent for http(s) requests. Mostly for testing purposes.
16
- *
17
- * @param proxy - the proxy to use
18
- * @param options - to set additional TLS options for https requests, e.g. rejectUnauthorized
19
- */
20
- function proxyAgent(proxy, options) {
21
- return agentBase((req, opts) => __awaiter(this, void 0, void 0, function* () {
22
- const socket = yield proxy.connect(opts);
23
- if (opts.secureEndpoint) {
24
- // Upgrade to TLS
25
- let tlsOptions = {
26
- socket: socket,
27
- servername: opts.servername || opts.host
28
- };
29
- if (typeof opts.rejectUnauthorized != 'undefined') {
30
- // There's a difference between 'undefined' (equivalent of false) and "not set" (equivalent of true)
31
- tlsOptions.rejectUnauthorized = opts.rejectUnauthorized;
32
- }
33
- Object.assign(tlsOptions, options);
34
- const tlsSocket = tls.connect(tlsOptions);
35
- return tlsSocket;
36
- }
37
- else {
38
- socket.resume();
39
- return socket;
40
- }
41
- }));
42
- }
43
- exports.proxyAgent = proxyAgent;
@@ -1,8 +0,0 @@
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;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const debug = require('debug')('https-proxy');
13
- /**
14
- * Replace the connection method on the tedious library (used by mssql)
15
- * to connect via a proxy.
16
- *
17
- * @param proxy - the proxy to use
18
- */
19
- function useProxyForTedious(proxy) {
20
- const { Connector } = require('tedious/lib/connector');
21
- Connector.prototype.execute = function (cb) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- debug(`opening sql connection to ${this.options.host}:${this.options.port}`);
24
- try {
25
- const socket = yield proxy.connect(this.options);
26
- cb(null, socket);
27
- }
28
- catch (error) {
29
- cb(error);
30
- }
31
- });
32
- };
33
- }
34
- exports.useProxyForTedious = useProxyForTedious;