@nora-link/client 1.0.1 → 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/README.md +20 -4
- package/dist/cli.js +11 -4
- package/dist/client.js +7 -4
- package/dist/logger.d.ts +6 -6
- package/dist/logger.js +28 -12
- package/package.json +1 -1
- package/src/cli.ts +12 -5
- package/src/client.ts +7 -4
- package/src/logger.ts +30 -15
package/README.md
CHANGED
|
@@ -4,16 +4,32 @@ This package helps you access your private servers inside your home network, sec
|
|
|
4
4
|
|
|
5
5
|
## Getting an API key
|
|
6
6
|
|
|
7
|
-
1. Go to [https://noralink.eu
|
|
8
|
-
2. Navigate from the dropdown (or follow [link](https://noralink.eu
|
|
7
|
+
1. Go to [https://noralink.eu/home](https://noralink.eu/home) and create an account
|
|
8
|
+
2. Navigate from the dropdown (or follow [link](https://noralink.eu/home/api-keys)) to the **Manage API keys** menu
|
|
9
9
|
3. Create a new key and copy it somewhere safe
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
## Creating a tunnel
|
|
13
13
|
|
|
14
|
-
The following command creates a tunnel under
|
|
14
|
+
The following command creates a tunnel under subdomain `app` to `internal-server.local:1234/sample-path`. Replace `[your-api-key]` with the API key you obtained before.
|
|
15
15
|
|
|
16
|
-
`npx @nora-link/client -f
|
|
16
|
+
`npx @nora-link/client -f "app|internal-server.local:1234/sample-path" -k [your-api-key]`
|
|
17
|
+
|
|
18
|
+
You can also specify a label to be displayed in the UI:
|
|
19
|
+
|
|
20
|
+
`npx @nora-link/client -f "app|This is my test app|internal-server.local:1234/sample-path" -k [your-api-key]`
|
|
21
|
+
|
|
22
|
+
Or you can create multiple tunnels to different apps:
|
|
23
|
+
|
|
24
|
+
`npx @nora-link/client -f "app|app1.local:1234" -f "test|app2.local:1234" -k [your-api-key]`
|
|
17
25
|
|
|
18
26
|
## Accessing the tunnel
|
|
19
27
|
|
|
28
|
+
You can acess the tunnel by navigating to [https://noralink.eu/home](https://noralink.eu/home) and clicking the card corresponding your tunnel, or by going directly to the subdomain associated to your tunnerl. Eg: [https://app.noralink.eu](https://app.noralink.eu).
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Available subdomains
|
|
32
|
+
|
|
33
|
+
Currently only a subset of subdomains are available to use with your own tunnels, from the following: *admin, api, app, control, dashboard, home, my, nodered*.
|
|
34
|
+
|
|
35
|
+
If you want a new subdomain, add a request here: [Request a new subdomain thread](https://github.com/andrei-tatar/nora-link-client/issues/1).
|
package/dist/cli.js
CHANGED
|
@@ -11,11 +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
|
-
.
|
|
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')
|
|
15
22
|
.requiredOption('-k, --key <api-key>', 'Api Key')
|
|
16
23
|
.requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
|
|
17
|
-
.addHelpText('afterAll', 'To
|
|
18
|
-
.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`')
|
|
19
26
|
.parse();
|
|
20
27
|
const options = commander_1.program.opts();
|
|
21
28
|
let tunnels = [];
|
|
@@ -46,6 +53,6 @@ new client_1.Client({
|
|
|
46
53
|
secure: !options.nonSecure,
|
|
47
54
|
tunnels,
|
|
48
55
|
apiKey: options.key,
|
|
49
|
-
logger: logger_1.
|
|
56
|
+
logger: (0, logger_1.createConsoleLogger)(options.log),
|
|
50
57
|
}).handle$
|
|
51
58
|
.subscribe();
|
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,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export declare
|
|
1
|
+
export declare const LOG_LEVEL: readonly ["trace", "debug", "info", "warn", "error"];
|
|
2
|
+
export type LogLevel = typeof LOG_LEVEL[number];
|
|
3
|
+
export type Logger = {
|
|
4
|
+
[P in LogLevel]: (msg: string, err?: any) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function createConsoleLogger(minLevel: LogLevel): Logger;
|
package/dist/logger.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
info
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
exports.LOG_LEVEL = void 0;
|
|
4
|
+
exports.createConsoleLogger = createConsoleLogger;
|
|
5
|
+
exports.LOG_LEVEL = [
|
|
6
|
+
'trace',
|
|
7
|
+
'debug',
|
|
8
|
+
'info',
|
|
9
|
+
'warn',
|
|
10
|
+
'error'
|
|
11
|
+
];
|
|
12
|
+
function createConsoleLogger(minLevel) {
|
|
13
|
+
const minLevelIndex = exports.LOG_LEVEL.indexOf(minLevel);
|
|
14
|
+
function log(kind, ...args) {
|
|
15
|
+
const level = exports.LOG_LEVEL.indexOf(kind);
|
|
16
|
+
if (level < minLevelIndex) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const now = new Date().toLocaleString();
|
|
20
|
+
const logArgs = [`[${now}][${kind}]${args[0]}`];
|
|
21
|
+
if (args[1])
|
|
22
|
+
logArgs.push(args[1]);
|
|
23
|
+
console.log(...logArgs);
|
|
24
|
+
}
|
|
25
|
+
return new Proxy({}, {
|
|
26
|
+
get: function (_, name) {
|
|
27
|
+
return log.bind(null, name);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
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 {
|
|
5
|
+
import { createConsoleLogger, LOG_LEVEL, LogLevel } from './logger';
|
|
6
6
|
|
|
7
7
|
const { name, version } = require('../package.json');
|
|
8
8
|
|
|
@@ -12,11 +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
|
-
.
|
|
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')
|
|
16
23
|
.requiredOption('-k, --key <api-key>', 'Api Key')
|
|
17
24
|
.requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
|
|
18
|
-
.addHelpText('afterAll', 'To
|
|
19
|
-
.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`')
|
|
20
27
|
.parse();
|
|
21
28
|
|
|
22
29
|
const options = program.opts();
|
|
@@ -51,7 +58,7 @@ new Client({
|
|
|
51
58
|
secure: !options.nonSecure,
|
|
52
59
|
tunnels,
|
|
53
60
|
apiKey: options.key,
|
|
54
|
-
logger:
|
|
61
|
+
logger: createConsoleLogger(options.log),
|
|
55
62
|
}).handle$
|
|
56
63
|
.subscribe();
|
|
57
64
|
|
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(),
|
package/src/logger.ts
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
export
|
|
2
|
-
trace
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export const LOG_LEVEL = [
|
|
2
|
+
'trace',
|
|
3
|
+
'debug',
|
|
4
|
+
'info',
|
|
5
|
+
'warn',
|
|
6
|
+
'error'
|
|
7
|
+
] as const;
|
|
8
|
+
|
|
9
|
+
export type LogLevel = typeof LOG_LEVEL[number];
|
|
10
|
+
|
|
11
|
+
export type Logger = {
|
|
12
|
+
[P in LogLevel]: (msg: string, err?: any) => void;
|
|
5
13
|
}
|
|
6
14
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
export function createConsoleLogger(minLevel: LogLevel): Logger {
|
|
16
|
+
const minLevelIndex = LOG_LEVEL.indexOf(minLevel);
|
|
17
|
+
function log(kind: keyof Logger, ...args: Parameters<Logger['info']>) {
|
|
18
|
+
const level = LOG_LEVEL.indexOf(kind);
|
|
19
|
+
if (level < minLevelIndex) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
11
22
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
const now = new Date().toLocaleString();
|
|
24
|
+
const logArgs = [`[${now}][${kind}]${args[0]}`];
|
|
25
|
+
if (args[1]) logArgs.push(args[1]);
|
|
26
|
+
console.log(...logArgs);
|
|
27
|
+
}
|
|
15
28
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
29
|
+
return new Proxy({}, {
|
|
30
|
+
get: function (_, name: LogLevel) {
|
|
31
|
+
return log.bind(null, name);
|
|
32
|
+
}
|
|
33
|
+
}) as Logger;
|
|
34
|
+
}
|