tunli 0.0.20 → 0.0.21

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/client.js CHANGED
@@ -8,6 +8,7 @@ import {createCommandRefresh} from "#commands/CommandRefresh";
8
8
  import {argumentAliasResolver} from "#commands/helper/AliasResolver";
9
9
  import {createCommandInvite} from "#commands/CommandInvite";
10
10
  import {addExamples, addUsage} from "#commands/utils";
11
+ import {profileListOption} from "#commands/Option/ProfileListOption";
11
12
 
12
13
  program
13
14
  .name('tunli')
@@ -17,6 +18,7 @@ program
17
18
  console.log(`tunli: ${packageJson.version}`)
18
19
  process.exit()
19
20
  })
21
+ .addOption(profileListOption())
20
22
 
21
23
  program.addCommand(createCommandConfig(program))
22
24
  program.addCommand(createCommandHTTP(program), {isDefault: true})
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tunli",
3
3
  "description": "Node.js application for creating HTTP tunnels to make local software projects accessible over the internet.",
4
- "version": "0.0.20",
4
+ "version": "0.0.21",
5
5
  "main": "bin/tunli",
6
6
  "bin": {
7
7
  "tunli": "bin/tunli"
@@ -5,6 +5,7 @@ import {portCommand} from "#commands/SubCommand/PortCommand";
5
5
  import {hostCommand} from "#commands/SubCommand/HostCommand";
6
6
  import {selectConfigOption} from "#commands/Option/SelectConfigOption";
7
7
  import {addExample, extendUsage} from "#commands/utils";
8
+ import {protocolCommand} from "#commands/SubCommand/ProtocolCommand";
8
9
 
9
10
  /**
10
11
  *
@@ -41,6 +42,7 @@ export const createCommandConfig = (program) => {
41
42
  cmd.addCommand(allowDenyCidrCommand('denyCidr', cmd, configRef))
42
43
  cmd.addCommand(portCommand(configRef))
43
44
  cmd.addCommand(hostCommand(configRef))
45
+ cmd.addCommand(protocolCommand(configRef))
44
46
 
45
47
  selectConfigOption(cmd, configRef, true)
46
48
  .action(exec(configRef, program));
@@ -61,6 +61,7 @@ const exec = (configRef, cmd, program) => {
61
61
 
62
62
  options.port ??= port
63
63
  options.host ??= host
64
+ options.protocol ??= protocol ?? 'http'
64
65
 
65
66
  const save = options.save
66
67
  delete options.save
@@ -90,7 +91,7 @@ const exec = (configRef, cmd, program) => {
90
91
  path: undefined,
91
92
  allowCidr: options.allowCidr ?? config.allowCidr,
92
93
  denyCidr: options.denyCidr ?? config.denyCidr,
93
- protocol: protocol ?? 'http'
94
+ protocol: options.protocol
94
95
  }
95
96
 
96
97
  const client = new TunnelClient(clientOptions)
@@ -116,9 +117,9 @@ export const createCommandHTTP = (program) => {
116
117
 
117
118
  cmd.option('--host <string>', 'setting hostname', bindArgs(checkHost, sharedArgument, false))
118
119
  cmd.option('--port <string>', 'setting port', bindArgs(checkPort, sharedArgument, false))
119
- cmd.option('--allow-cidr <string>', 'allow-cidr', validateArrayArguments(validateIpV4))
120
- cmd.option('--deny-cidr <string>', 'deny-cidr', validateArrayArguments(validateIpV4))
121
- cmd.option('--self', 'allow self only', false)
120
+ cmd.option('--allow, --allow-cidr <string>', 'allow-cidr', validateArrayArguments(validateIpV4))
121
+ cmd.option('--deny, --deny-cidr <string>', 'deny-cidr', validateArrayArguments(validateIpV4))
122
+ cmd.option('--allow-self, --self', 'allow self only', false)
122
123
  cmd.option('--save [alias]', 'save current settings as alias/local')
123
124
  cmd.action(exec(configRef, cmd, program))
124
125
 
@@ -0,0 +1,65 @@
1
+ import {Option} from "commander";
2
+ import {ConfigManager} from "#src/config/ConfigManager";
3
+
4
+ export const profileListOption = () => {
5
+ const option = new Option('-l, --list', 'profile list')
6
+ option.argParser(() => {
7
+ /**
8
+ * @param label
9
+ * @param {ConfigAbstract} config
10
+ * @return {string}
11
+ */
12
+ const createOutput = (label, config) => {
13
+ const profiles = [...config.profiles]
14
+ const maxLabelLength = Math.max(...profiles.map(x => x.length))
15
+ const whitespace = ''.padEnd(2)
16
+ const rows = [`${label}`, '']
17
+ // const rows = [`${label}${profiles.shift()}`]
18
+ const overview = {}
19
+ const proxyURLs = []
20
+ for (const profile of profiles) {
21
+
22
+ const info = config.use(profile)
23
+ const host = info.host
24
+ const port = info.port
25
+ const protocol = info.protocol
26
+ let proxyURL = info.proxyURL
27
+
28
+ let targetUrl = new URL(`${protocol}://${host}:${port}`).toString()
29
+ if (proxyURL) {
30
+ proxyURL = proxyURL.substring(0, proxyURL.length - 1)
31
+ }
32
+
33
+ targetUrl = targetUrl.substring(0, targetUrl.length - 1)
34
+ proxyURLs.push(proxyURL.length)
35
+ overview[profile] = {
36
+ host,
37
+ port,
38
+ targetUrl,
39
+ proxyURL
40
+ }
41
+ }
42
+
43
+ const maxProxyUrlLength = Math.max(...proxyURLs)
44
+
45
+ for (const profile of profiles) {
46
+ let {targetUrl, proxyURL} = overview[profile]
47
+ proxyURL = proxyURL.padEnd(maxProxyUrlLength)
48
+ rows.push(`${whitespace}${profile.padEnd(maxLabelLength)} ${proxyURL} -> ${targetUrl}`)
49
+ }
50
+
51
+ return rows.join("\n") + "\n"
52
+ }
53
+ const localConf = ConfigManager.loadLocalOnly()
54
+ const globalConf = ConfigManager.loadGlobalOnly()
55
+
56
+ if (localConf.exists()) {
57
+ console.log(createOutput('Alias local config: ', localConf))
58
+ }
59
+ if (globalConf.exists()) {
60
+ console.log(createOutput('Alias global config: ', globalConf))
61
+ }
62
+ process.exit()
63
+ })
64
+ return option
65
+ }
@@ -10,7 +10,7 @@ import {ConfigManager} from "#src/config/ConfigManager";
10
10
  export const selectConfigOption = (command, configRef, strictMode = false) => {
11
11
 
12
12
  command.option('--global', 'Use the global configuration file (default)')
13
- .option('--workdir', 'Use the configuration file for the current working directory')
13
+ .option('--local, --workdir', 'Use the configuration file for the current working directory')
14
14
  .option('-p --alias <string>', 'setting alias name', 'default')
15
15
 
16
16
  if (configRef) {
@@ -0,0 +1,21 @@
1
+ import {Command} from "commander";
2
+
3
+ import {checkProtocol} from "#src/utils/checkFunctions";
4
+ import {deleteOption} from "#commands/Option/DeleteOption";
5
+ import {addGetDeleteValueAction} from "#commands/Action/addDelValuesAction";
6
+
7
+ export const protocolCommand = (configRef) => {
8
+ const cmd = new Command('protocol')
9
+
10
+ cmd.description('default protocol "http"')
11
+ .argument('[PROTOCOL]', 'füge eine kurze beschreibung ein', checkProtocol)
12
+ .hook('preAction', (thisCommand, actionCommand) => {
13
+ if (thisCommand.args.length && thisCommand.opts().del) {
14
+ actionCommand.error("error: wenn delete dann keine argumente");
15
+ }
16
+ })
17
+ .addOption(deleteOption())
18
+ .action(addGetDeleteValueAction('protocol', configRef))
19
+
20
+ return cmd
21
+ }
@@ -1,4 +1,4 @@
1
- import {writeFileSync} from "fs"
1
+ import {existsSync, writeFileSync} from "fs"
2
2
  import {dirname} from 'path'
3
3
  import {ensureDirectoryExists} from "#src/core/FS/utils";
4
4
  import {PropertyConfig} from "#src/config/PropertyConfig";
@@ -143,6 +143,17 @@ export class ConfigAbstract {
143
143
  return this.#activeProfile
144
144
  }
145
145
 
146
+ /**
147
+ * @return {string[]}
148
+ */
149
+ get profiles() {
150
+ return Object.keys(this.#profileData.profile)
151
+ }
152
+
153
+ exists() {
154
+ return existsSync(this.#path)
155
+ }
156
+
146
157
  /**
147
158
  * Prepare the configuration by defining properties.
148
159
  * @param {{[p: string]: PropertyConfig}} propertyConfig - The configuration properties.
@@ -1,4 +1,4 @@
1
- import {checkHost, checkIpV4Cidr, checkPort, checkUrl} from "#src/utils/checkFunctions";
1
+ import {checkHost, checkInArray, checkIpV4Cidr, checkPort, checkUrl} from "#src/utils/checkFunctions";
2
2
  import {ConfigAbstract, VISIBILITY_PUBLIC} from "#src/config/ConfigAbstract";
3
3
  import {property} from "#src/config/PropertyConfig";
4
4
  import {ConfigManager} from "#src/config/ConfigManager";
@@ -58,6 +58,15 @@ export class GlobalLocalShardConfigAbstract extends ConfigAbstract {
58
58
  return checkHost(val)
59
59
  }
60
60
  }),
61
+ protocol: property({
62
+ visibility: VISIBILITY_PUBLIC,
63
+ writeable: true,
64
+ type: String,
65
+ defaultValue: 'http',
66
+ validate(val) {
67
+ return checkInArray(val, ['http', 'https'])
68
+ }
69
+ }),
61
70
  }
62
71
 
63
72
  /**
@@ -16,7 +16,7 @@ export class TunnelClient extends EventEmitter {
16
16
  #latency = ref(0)
17
17
 
18
18
  /**
19
- * @param {tunnelClientOptions} options
19
+ * @param {...tunnelClientOptions} options
20
20
  */
21
21
  constructor(options) {
22
22
  super()
@@ -159,3 +159,15 @@ export const checkPort = (valueOrSharedArg, isArgument = false, value) => {
159
159
 
160
160
  return value
161
161
  }
162
+
163
+ export const checkProtocol = (value) => {
164
+ return checkInArray(value, ['http', 'https'])
165
+ }
166
+
167
+ export const checkInArray = (val, arr) => {
168
+ if (!arr.includes(val)) {
169
+ throw new InvalidArgumentError(`Value must be one of (${arr.join(', ')})`)
170
+ }
171
+
172
+ return val
173
+ }
package/types/index.d.ts CHANGED
@@ -48,6 +48,7 @@ interface ConfigAbstract {
48
48
 
49
49
  export interface AppConfig {
50
50
 
51
+ protocol: protocol
51
52
  port: number
52
53
  host: string
53
54
  authToken: string