@nora-link/client 1.0.2 → 1.0.3
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/dist/cli.js +10 -4
- package/dist/client.js +7 -4
- package/dist/logger.d.ts +1 -2
- package/package.json +1 -1
- package/src/cli.ts +11 -5
- package/src/client.ts +7 -4
- package/src/logger.ts +1 -1
package/dist/cli.js
CHANGED
|
@@ -11,12 +11,18 @@ commander_1.program
|
|
|
11
11
|
.usage('[OPTIONS]...')
|
|
12
12
|
.option('-d, --debug', 'output extra debugging', false)
|
|
13
13
|
.option('-n, --non-secure', 'don\'t use secure connection', false)
|
|
14
|
-
.option('-l, --log', `min log level to display
|
|
15
|
-
|
|
14
|
+
.option('-l, --log', `min log level to display. Options: ${logger_1.LOG_LEVEL.join(',')}`, (value, previous) => {
|
|
15
|
+
const v = value.toLowerCase();
|
|
16
|
+
if (logger_1.LOG_LEVEL.includes(v)) {
|
|
17
|
+
return v;
|
|
18
|
+
}
|
|
19
|
+
return previous;
|
|
20
|
+
}, 'info')
|
|
21
|
+
.requiredOption('-f, --forward <subdomain|label|url>', 'Tunnel subdomain to local url. Label is optional')
|
|
16
22
|
.requiredOption('-k, --key <api-key>', 'Api Key')
|
|
17
23
|
.requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
|
|
18
|
-
.addHelpText('afterAll', 'To
|
|
19
|
-
.addHelpText('afterAll', 'To
|
|
24
|
+
.addHelpText('afterAll', 'To tunnel a local port to the subdomain `test`, you can use `-f test|:3000`')
|
|
25
|
+
.addHelpText('afterAll', 'To tunnel an ip to the subdomain `test`, you can use `-f test|192.168.1.130`')
|
|
20
26
|
.parse();
|
|
21
27
|
const options = commander_1.program.opts();
|
|
22
28
|
let tunnels = [];
|
package/dist/client.js
CHANGED
|
@@ -15,7 +15,7 @@ class Client {
|
|
|
15
15
|
this.server$ = new rxjs_1.Observable(observer => {
|
|
16
16
|
const segments = this.options.tunnels.map(v => `${v.remotePath}|${v.label}`);
|
|
17
17
|
const qs = (0, node_querystring_1.stringify)({ s: segments });
|
|
18
|
-
this.options.logger?.info(`[nora-link] connecting
|
|
18
|
+
this.options.logger?.info(`[nora-link] connecting`);
|
|
19
19
|
const protocol = this.options.secure ? 'wss' : 'ws';
|
|
20
20
|
const ws = new ws_1.default(`${protocol}://${this.options.hostname}/api/tunnel?${qs}`, {
|
|
21
21
|
headers: {
|
|
@@ -67,9 +67,12 @@ class Client {
|
|
|
67
67
|
}
|
|
68
68
|
return rxjs_1.EMPTY;
|
|
69
69
|
}), (0, rxjs_1.retry)({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
resetOnSuccess: true,
|
|
71
|
+
delay: (err, retryCount) => {
|
|
72
|
+
const delaySeconds = Math.round(Math.min(300, Math.pow(1.8, retryCount + 3)));
|
|
73
|
+
this.options.logger?.trace(`[nora-link] connection error`, err);
|
|
74
|
+
this.options.logger?.error(`[nora-link] retrying in ${delaySeconds} sec`);
|
|
75
|
+
return (0, rxjs_1.timer)(delaySeconds * 1000);
|
|
73
76
|
},
|
|
74
77
|
}), (0, rxjs_1.share)());
|
|
75
78
|
}
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export declare const LOG_LEVEL: readonly ["trace", "debug", "info", "warn", "error"];
|
|
2
|
-
type LogLevel = typeof LOG_LEVEL[number];
|
|
2
|
+
export type LogLevel = typeof LOG_LEVEL[number];
|
|
3
3
|
export type Logger = {
|
|
4
4
|
[P in LogLevel]: (msg: string, err?: any) => void;
|
|
5
5
|
};
|
|
6
6
|
export declare function createConsoleLogger(minLevel: LogLevel): Logger;
|
|
7
|
-
export {};
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { program } from 'commander';
|
|
4
4
|
import { Client, ClientConnectionOptions } from './client';
|
|
5
|
-
import { createConsoleLogger, LOG_LEVEL } from './logger';
|
|
5
|
+
import { createConsoleLogger, LOG_LEVEL, LogLevel } from './logger';
|
|
6
6
|
|
|
7
7
|
const { name, version } = require('../package.json');
|
|
8
8
|
|
|
@@ -12,12 +12,18 @@ program
|
|
|
12
12
|
.usage('[OPTIONS]...')
|
|
13
13
|
.option('-d, --debug', 'output extra debugging', false)
|
|
14
14
|
.option('-n, --non-secure', 'don\'t use secure connection', false)
|
|
15
|
-
.option('-l, --log', `min log level to display
|
|
16
|
-
|
|
15
|
+
.option<LogLevel>('-l, --log', `min log level to display. Options: ${LOG_LEVEL.join(',')}`, (value, previous) => {
|
|
16
|
+
const v = value.toLowerCase() as LogLevel;
|
|
17
|
+
if (LOG_LEVEL.includes(v)) {
|
|
18
|
+
return v;
|
|
19
|
+
}
|
|
20
|
+
return previous;
|
|
21
|
+
}, 'info')
|
|
22
|
+
.requiredOption('-f, --forward <subdomain|label|url>', 'Tunnel subdomain to local url. Label is optional')
|
|
17
23
|
.requiredOption('-k, --key <api-key>', 'Api Key')
|
|
18
24
|
.requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
|
|
19
|
-
.addHelpText('afterAll', 'To
|
|
20
|
-
.addHelpText('afterAll', 'To
|
|
25
|
+
.addHelpText('afterAll', 'To tunnel a local port to the subdomain `test`, you can use `-f test|:3000`')
|
|
26
|
+
.addHelpText('afterAll', 'To tunnel an ip to the subdomain `test`, you can use `-f test|192.168.1.130`')
|
|
21
27
|
.parse();
|
|
22
28
|
|
|
23
29
|
const options = program.opts();
|
package/src/client.ts
CHANGED
|
@@ -31,7 +31,7 @@ export class Client {
|
|
|
31
31
|
private server$ = new Observable<WebSocket>(observer => {
|
|
32
32
|
const segments = this.options.tunnels.map(v => `${v.remotePath}|${v.label}`);
|
|
33
33
|
const qs = querystringStringify({ s: segments });
|
|
34
|
-
this.options.logger?.info(`[nora-link] connecting
|
|
34
|
+
this.options.logger?.info(`[nora-link] connecting`);
|
|
35
35
|
const protocol = this.options.secure ? 'wss' : 'ws';
|
|
36
36
|
const ws = new WebSocket(`${protocol}://${this.options.hostname}/api/tunnel?${qs}`, {
|
|
37
37
|
headers: {
|
|
@@ -96,9 +96,12 @@ export class Client {
|
|
|
96
96
|
return EMPTY;
|
|
97
97
|
}),
|
|
98
98
|
retry({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
resetOnSuccess: true,
|
|
100
|
+
delay: (err, retryCount) => {
|
|
101
|
+
const delaySeconds = Math.round(Math.min(300, Math.pow(1.8, retryCount + 3)));
|
|
102
|
+
this.options.logger?.trace(`[nora-link] connection error`, err);
|
|
103
|
+
this.options.logger?.error(`[nora-link] retrying in ${delaySeconds} sec`);
|
|
104
|
+
return timer(delaySeconds * 1000);
|
|
102
105
|
},
|
|
103
106
|
}),
|
|
104
107
|
share(),
|