@ffflorian/https-proxy 1.7.1 → 1.8.1

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.
package/README.md CHANGED
@@ -2,8 +2,15 @@
2
2
 
3
3
  A simple HTTPS proxy for Node.js with authentication support.
4
4
 
5
+ ## Prerequisites
6
+
7
+ - [Node.js](https://nodejs.org) >= 14
8
+ - npm (preinstalled) or [yarn](https://classic.yarnpkg.com) < 2
9
+
5
10
  ## Installation
6
11
 
12
+ ℹ️ This is a hybrid [CommonJS](https://nodejs.org/docs/latest/api/modules.html#modules-commonjs-modules) / [ESM](https://nodejs.org/api/esm.html#introduction) module.
13
+
7
14
  Run `yarn global add @ffflorian/https-proxy` or `npm install -g @ffflorian/https-proxy`.
8
15
 
9
16
  ## Usage
@@ -1,33 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpsProxy = void 0;
4
- const basicAuth = require("basic-auth");
5
- const http = require("http");
6
- const logdown = require("logdown");
7
- const net = require("net");
8
- const compare = require("tsscmp");
9
- const url = require("url");
10
- const http_status_codes_1 = require("http-status-codes");
1
+ import basicAuth from 'basic-auth';
2
+ import http from 'node:http';
3
+ import logdown from 'logdown';
4
+ import net from 'node:net';
5
+ import compare from 'tsscmp';
6
+ import url from 'node:url';
7
+ import { StatusCodes as HTTP_STATUS } from 'http-status-codes';
11
8
  const defaultOptions = {
12
9
  password: '',
13
10
  port: 8080,
14
11
  target: '',
15
12
  username: '',
16
13
  };
17
- class HttpsProxy {
14
+ export class HttpsProxy {
18
15
  constructor(options) {
19
16
  this.onConnect = (req, clientSocket) => {
20
17
  this.logger.info(clientSocket.remoteAddress, clientSocket.remotePort, req.method, req.url);
21
18
  const authorizationHeader = req.headers['proxy-authorization'];
22
19
  if (this.authenticationEnabled) {
23
20
  if (!authorizationHeader) {
24
- clientSocket.write(this.getClosingProxyMessage(http_status_codes_1.StatusCodes.PROXY_AUTHENTICATION_REQUIRED, 'Proxy Authentication Required'));
21
+ clientSocket.write(this.getClosingProxyMessage(HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED, 'Proxy Authentication Required'));
25
22
  clientSocket.end('\r\n\r\n');
26
23
  this.logger.warn(`Responded to proxy request from "${clientSocket.remoteAddress}" with authorization request`);
27
24
  return;
28
25
  }
29
26
  if (!this.validateAuthorization(authorizationHeader)) {
30
- clientSocket.write(this.getClosingProxyMessage(http_status_codes_1.StatusCodes.UNAUTHORIZED, 'Unauthorized'));
27
+ clientSocket.write(this.getClosingProxyMessage(HTTP_STATUS.UNAUTHORIZED, 'Unauthorized'));
31
28
  clientSocket.end('\r\n\r\n');
32
29
  this.logger.warn(`Rejected proxy request with invalid authorization from "${clientSocket.remoteAddress}".`);
33
30
  return;
@@ -77,7 +74,7 @@ class HttpsProxy {
77
74
  };
78
75
  this.onCreate = (req, res) => {
79
76
  // discard all request to proxy server except HTTP/1.1 CONNECT method
80
- res.writeHead(http_status_codes_1.StatusCodes.BAD_REQUEST, { 'Content-Type': 'text/plain' });
77
+ res.writeHead(HTTP_STATUS.BAD_REQUEST, { 'Content-Type': 'text/plain' });
81
78
  res.end('Bad Request');
82
79
  this.logger.warn(`Rejected "${req.method}" request from "${req.socket.remoteAddress}"`);
83
80
  };
@@ -113,5 +110,4 @@ class HttpsProxy {
113
110
  compare(credentials.pass, this.options.password));
114
111
  }
115
112
  }
116
- exports.HttpsProxy = HttpsProxy;
117
113
  //# sourceMappingURL=HttpsProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpsProxy.js","sourceRoot":"","sources":["../../src/HttpsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,OAAO,MAAM,QAAQ,CAAC;AAC7B,OAAO,GAAG,MA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AC,CAAC;QAC1C,OAAO,CACL,CAAC,CAAC,WAAW;YACb,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YAChD,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CACjD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import { program as commander } from 'commander';
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
5
+ import { HttpsProxy } from './HttpsProxy.js';
6
+ const { description, name, version } = require('../package.json');
7
+ commander
8
+ .name(name.replace(/^@[^/]+\//, ''))
9
+ .description(`${description}\nIf password and username are not set, no authentication will be required.`)
10
+ .option('-p, --password <password>', 'set the password')
11
+ .option('-P, --port <port>', 'set the port', '8080')
12
+ .option('-t, --target <url>', 'set the target URL to forward users to')
13
+ .option('-u, --username <username>', 'set the username')
14
+ .version(version, '-v, --version')
15
+ .parse(process.argv);
16
+ const commanderOptions = commander.opts();
17
+ if ((commanderOptions.password && !commanderOptions.username) ||
18
+ (!commanderOptions.password && commanderOptions.username)) {
19
+ console.error('Password and username are both required for authentication.');
20
+ commander.outputHelp();
21
+ process.exit(1);
22
+ }
23
+ new HttpsProxy(Object.assign(Object.assign(Object.assign(Object.assign({}, (commanderOptions.password && { password: commanderOptions.password })), (commanderOptions.port && { port: commanderOptions.port })), (commanderOptions.target && { target: commanderOptions.target })), (commanderOptions.username && { username: commanderOptions.username }))).start();
24
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,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,GAC9D,CAAC,gBAAgB,CAAC,QAAQ,IAAI,EAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EAAC,CAAC,EACvE,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './HttpsProxy.js';
@@ -0,0 +1,2 @@
1
+ export * from './HttpsProxy.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,28 @@
1
+ export interface Options {
2
+ /** Default is `8080`. */
3
+ port?: number;
4
+ /** If not set, the requested URL will be used. */
5
+ target?: string;
6
+ }
7
+ export interface AuthenticationOptions extends Options {
8
+ /** If not set, no authentication will be required. */
9
+ password: string;
10
+ /** Default is `8080`. */
11
+ port?: number;
12
+ /** If not set, the requested URL will be used. */
13
+ target?: string;
14
+ /** If not set, no authentication will be required. */
15
+ username: string;
16
+ }
17
+ export declare class HttpsProxy {
18
+ private readonly authenticationEnabled;
19
+ private readonly logger;
20
+ private readonly options;
21
+ private readonly server;
22
+ constructor(options?: Options | AuthenticationOptions);
23
+ start(): void;
24
+ private getClosingProxyMessage;
25
+ private readonly onConnect;
26
+ private readonly onCreate;
27
+ private validateAuthorization;
28
+ }
@@ -0,0 +1,113 @@
1
+ import basicAuth from 'basic-auth';
2
+ import http from 'node:http';
3
+ import logdown from 'logdown';
4
+ import net from 'node:net';
5
+ import compare from 'tsscmp';
6
+ import url from 'node:url';
7
+ import { StatusCodes as HTTP_STATUS } from 'http-status-codes';
8
+ const defaultOptions = {
9
+ password: '',
10
+ port: 8080,
11
+ target: '',
12
+ username: '',
13
+ };
14
+ export class HttpsProxy {
15
+ constructor(options) {
16
+ this.onConnect = (req, clientSocket) => {
17
+ this.logger.info(clientSocket.remoteAddress, clientSocket.remotePort, req.method, req.url);
18
+ const authorizationHeader = req.headers['proxy-authorization'];
19
+ if (this.authenticationEnabled) {
20
+ if (!authorizationHeader) {
21
+ clientSocket.write(this.getClosingProxyMessage(HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED, 'Proxy Authentication Required'));
22
+ clientSocket.end('\r\n\r\n');
23
+ this.logger.warn(`Responded to proxy request from "${clientSocket.remoteAddress}" with authorization request`);
24
+ return;
25
+ }
26
+ if (!this.validateAuthorization(authorizationHeader)) {
27
+ clientSocket.write(this.getClosingProxyMessage(HTTP_STATUS.UNAUTHORIZED, 'Unauthorized'));
28
+ clientSocket.end('\r\n\r\n');
29
+ this.logger.warn(`Rejected proxy request with invalid authorization from "${clientSocket.remoteAddress}".`);
30
+ return;
31
+ }
32
+ }
33
+ const { port, hostname } = url.parse(this.options.target || `//${req.url}`, false, true);
34
+ const parsedPort = parseInt(port || '443', 10);
35
+ if (!hostname) {
36
+ clientSocket.end('HTTP/1.1 400 Bad Request\r\n');
37
+ clientSocket.destroy();
38
+ this.logger.warn(`Rejected proxy request without hostname from "${clientSocket.remoteAddress}".`);
39
+ return;
40
+ }
41
+ const serverSocket = net.connect({ host: hostname, port: parsedPort });
42
+ clientSocket
43
+ .on('end', () => {
44
+ if (serverSocket) {
45
+ serverSocket.end();
46
+ }
47
+ })
48
+ .on('error', (err) => {
49
+ this.logger.error(`ClientSocket error: "${err.message}"`);
50
+ if (serverSocket) {
51
+ serverSocket.end();
52
+ }
53
+ });
54
+ serverSocket
55
+ .on('connect', () => {
56
+ clientSocket.write(['HTTP/1.1 200 Connection Established', 'Proxy-agent: Node-Proxy'].join('\r\n'));
57
+ clientSocket.write('\r\n\r\n');
58
+ serverSocket.pipe(clientSocket, { end: false });
59
+ clientSocket.pipe(serverSocket, { end: false });
60
+ this.logger.info(`Proxying data between "${clientSocket.remoteAddress}" and "${req.headers.host}".`);
61
+ })
62
+ .on('end', () => {
63
+ if (clientSocket) {
64
+ clientSocket.end(`HTTP/1.1 500 External Server End\r\n`);
65
+ }
66
+ this.logger.info(`Ended proxy between "${clientSocket.remoteAddress}" and "${req.headers.host}".`);
67
+ })
68
+ .on('error', (err) => {
69
+ this.logger.error(`ServerSocket error: "${err.message}"`);
70
+ if (clientSocket) {
71
+ clientSocket.end(`HTTP/1.1 500 ${err.message}\r\n`);
72
+ }
73
+ });
74
+ };
75
+ this.onCreate = (req, res) => {
76
+ // discard all request to proxy server except HTTP/1.1 CONNECT method
77
+ res.writeHead(HTTP_STATUS.BAD_REQUEST, { 'Content-Type': 'text/plain' });
78
+ res.end('Bad Request');
79
+ this.logger.warn(`Rejected "${req.method}" request from "${req.socket.remoteAddress}"`);
80
+ };
81
+ this.options = Object.assign(Object.assign({}, defaultOptions), options);
82
+ this.logger = logdown('https-proxy', {
83
+ logger: console,
84
+ markdown: false,
85
+ });
86
+ this.logger.state.isEnabled = true;
87
+ this.authenticationEnabled = Boolean(this.options.username && this.options.password);
88
+ this.server = http
89
+ .createServer(this.onCreate)
90
+ .on('connect', this.onConnect)
91
+ .on('error', error => this.logger.error(`Server error: "${error.message}"`));
92
+ }
93
+ start() {
94
+ const authenticationStatus = this.authenticationEnabled ? 'ON' : 'OFF';
95
+ this.server.listen(this.options.port);
96
+ this.logger.info(`Proxy server is listening on port ${this.options.port} (authentication: ${authenticationStatus}).`);
97
+ }
98
+ getClosingProxyMessage(code, httpMessage) {
99
+ return [
100
+ `HTTP/1.1 ${code} ${httpMessage}`,
101
+ `Date: ${new Date().toUTCString()}`,
102
+ 'Proxy-Authenticate: Basic realm="proxy"',
103
+ 'Proxy-Connection: close',
104
+ ].join('\r\n');
105
+ }
106
+ validateAuthorization(auth) {
107
+ const credentials = basicAuth.parse(auth);
108
+ return (!!credentials &&
109
+ compare(credentials.name, this.options.username) &&
110
+ compare(credentials.pass, this.options.password));
111
+ }
112
+ }
113
+ //# sourceMappingURL=HttpsProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpsProxy.js","sourceRoot":"","sources":["../../src/HttpsPro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EAAE;YACjC,SAAS,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE;YACnC,yCAAyC;YACzC,yBAAyB;SAC1B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjB,CAAC;IAiFO,qBAAqB,CAAC,IAAY;QACxC,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,CACL,CAAC,CAAC,WAAW;YACb,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YAChD,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CACjD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ import { program as commander } from 'commander';
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
5
+ import { HttpsProxy } from './HttpsProxy.js';
6
+ const { description, name, version } = require('../package.json');
7
+ commander
8
+ .name(name.replace(/^@[^/]+\//, ''))
9
+ .description(`${description}\nIf password and username are not set, no authentication will be required.`)
10
+ .option('-p, --password <password>', 'set the password')
11
+ .option('-P, --port <port>', 'set the port', '8080')
12
+ .option('-t, --target <url>', 'set the target URL to forward users to')
13
+ .option('-u, --username <username>', 'set the username')
14
+ .version(version, '-v, --version')
15
+ .parse(process.argv);
16
+ const commanderOptions = commander.opts();
17
+ if ((commanderOptions.password && !commanderOptions.username) ||
18
+ (!commanderOptions.password && commanderOptions.username)) {
19
+ console.error('Password and username are both required for authentication.');
20
+ commander.outputHelp();
21
+ process.exit(1);
22
+ }
23
+ new HttpsProxy(Object.assign(Object.assign(Object.assign(Object.assign({}, (commanderOptions.password && { password: commanderOptions.password })), (commanderOptions.port && { port: commanderOptions.port })), (commanderOptions.target && { target: commanderOptions.target })), (commanderOptions.username && { username: commanderOptions.username }))).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,UAAU,6DACT,CAAC,gBAAgB,CAAC,QAAQ,IAAI,EAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EAAC,CAAC,GACpE,CAAC,gBAAgB,CAAC,IAAI,IAAI,EAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAC,CAAC,GACxD,CAAC,gBAAgB,CAAC,MAAM,IAAI,EAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAC,CAAC,GAC9D,CAAC,gBAAgB,CAAC,QAAQ,IAAI,EAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EAAC,CAAC,EACvE,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './HttpsProxy.js';
@@ -0,0 +1,2 @@
1
+ export * from './HttpsProxy.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "author": "Florian Imdahl <git@ffflorian.de>",
3
3
  "bin": {
4
- "https-proxy": "cli.js"
4
+ "https-proxy": "dist/cjs/cli.js"
5
5
  },
6
6
  "dependencies": {
7
7
  "basic-auth": "2.0.1",
8
- "commander": "10.0.0",
8
+ "commander": "10.0.1",
9
9
  "http-status-codes": "2.2.0",
10
10
  "logdown": "3.3.1",
11
11
  "tsscmp": "1.0.6"
@@ -18,38 +18,37 @@
18
18
  "typescript": "5.0.4"
19
19
  },
20
20
  "engines": {
21
- "node": ">= 10.9"
21
+ "node": ">= 14.16"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "import": "./dist/mjs/index.js",
26
+ "require": "./dist/cjs/index.js"
27
+ }
22
28
  },
23
29
  "files": [
24
- "HttpsProxy.d.ts",
25
- "HttpsProxy.js",
26
- "HttpsProxy.js.map",
27
- "cli.d.ts",
28
- "cli.js",
29
- "cli.js.map",
30
- "index.d.ts",
31
- "index.js",
32
- "index.js.map"
30
+ "dist"
33
31
  ],
34
32
  "keywords": [
35
33
  "cli",
36
34
  "typescript"
37
35
  ],
38
36
  "license": "GPL-3.0",
39
- "main": "index.js",
37
+ "main": "dist/cjs/index.js",
38
+ "module": "dist/mjs/index.js",
40
39
  "name": "@ffflorian/https-proxy",
41
- "publishConfig": {
42
- "directory": "flattened"
43
- },
44
40
  "repository": "https://github.com/ffflorian/node-packages/tree/main/packages/https-proxy",
45
41
  "scripts": {
46
- "build": "tsc",
42
+ "build": "yarn build:cjs && yarn build:mjs && yarn generate:packagejson",
43
+ "build:cjs": "tsc -p tsconfig.cjs.json",
44
+ "build:mjs": "tsc -p tsconfig.json",
47
45
  "clean": "rimraf dist",
48
46
  "dist": "yarn clean && yarn build",
49
- "flatten": "node ../publish-flat/dist/cli.js -o flattened",
50
- "postversion": "node ../publish-flat/dist/cli-copy.js -o flattened/package.json version",
51
- "start": "ts-node src/cli.ts",
52
- "test": "ts-node -P tsconfig.jasmine.json ../../node_modules/.bin/jasmine"
47
+ "generate:packagejson": "../../bin/generate-hybrid-package-json.sh",
48
+ "start": "ts-node-esm src/cli.ts",
49
+ "test": "ts-node-esm -P tsconfig.jasmine.json ../../node_modules/.bin/jasmine"
53
50
  },
54
- "version": "1.7.1"
51
+ "type": "module",
52
+ "version": "1.8.1",
53
+ "gitHead": "fee6dde4396255259028c1c723a95b9f6ec5b281"
55
54
  }
package/HttpsProxy.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"HttpsProxy.js","sourceRoot":"","sources":["../src/HttpsProxy.ts"],"names":[],"mappings":";;;AAAA,wCAAwC;AACxC,6BAA6B;AAC7B,mCAAmC;AACnC,2BAA2B;AAC3B,kCAAmC;AACnC,2BAA2B;AAC3B,yDAA6D;AAoB7D,MAAM,cAAc,GAAoC;IACtD,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE,I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IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CACjD,CAAC;IACJ,CAAC;CACF;AA9HD,gCA8HC"}
package/cli.js DELETED
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const commander_1 = require("commander");
5
- const fs = require("fs");
6
- const path = require("path");
7
- const HttpsProxy_1 = require("./HttpsProxy");
8
- const defaultPackageJsonPath = path.join(__dirname, 'package.json');
9
- const packageJsonPath = fs.existsSync(defaultPackageJsonPath)
10
- ? defaultPackageJsonPath
11
- : path.join(__dirname, '../package.json');
12
- const packageJson = fs.readFileSync(packageJsonPath, 'utf-8');
13
- const { description, name, version } = JSON.parse(packageJson);
14
- commander_1.program
15
- .name(name.replace(/^@[^/]+\//, ''))
16
- .description(`${description}\nIf password and username are not set, no authentication will be required.`)
17
- .option('-p, --password <password>', 'set the password')
18
- .option('-P, --port <port>', 'set the port', '8080')
19
- .option('-t, --target <url>', 'set the target URL to forward users to')
20
- .option('-u, --username <username>', 'set the username')
21
- .version(version, '-v, --version')
22
- .parse(process.argv);
23
- const commanderOptions = commander_1.program.opts();
24
- if ((commanderOptions.password && !commanderOptions.username) ||
25
- (!commanderOptions.password && commanderOptions.username)) {
26
- console.error('Password and username are both required for authentication.');
27
- commander_1.program.outputHelp();
28
- process.exit(1);
29
- }
30
- new HttpsProxy_1.HttpsProxy(Object.assign(Object.assign(Object.assign(Object.assign({}, (commanderOptions.password && { password: commanderOptions.password })), (commanderOptions.port && { port: commanderOptions.port })), (commanderOptions.target && { target: commanderOptions.target })), (commanderOptions.username && { username: commanderOptions.username }))).start();
31
- //# sourceMappingURL=cli.js.map
package/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,yCAA+C;AAC/C,yBAAyB;AACzB,6BAA6B;AAE7B,6CAAwC;AAExC,MAAM,sBAAsB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QAAQ,IAAI,EAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EAAC,CAAC,GACpE,CAAC,gBAAgB,CAAC,IAAI,IAAI,EAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAC,CAAC,GACxD,CAAC,gBAAgB,CAAC,MAAM,IAAI,EAAC,MAAM,EAAE,gBAAgB,CAAC,MAAM,EAAC,CAAC,GAC9D,CAAC,gBAAgB,CAAC,QAAQ,IAAI,EAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EAAC,CAAC,EACvE,CAAC,KAAK,EAAE,CAAC"}
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './HttpsProxy';
package/index.js DELETED
@@ -1,18 +0,0 @@
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("./HttpsProxy"), exports);
18
- //# sourceMappingURL=index.js.map
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
File without changes
File without changes