@nora-link/client 1.0.3 → 1.0.5
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 +1 -1
- package/dist/cli.js +24 -25
- package/dist/client.d.ts +1 -0
- package/dist/client.js +7 -5
- package/package.json +1 -1
- package/src/cli.ts +24 -25
- package/src/client.ts +10 -5
package/README.md
CHANGED
|
@@ -30,6 +30,6 @@ You can acess the tunnel by navigating to [https://noralink.eu/home](https://nor
|
|
|
30
30
|
|
|
31
31
|
## Available subdomains
|
|
32
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*.
|
|
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, smarthome, test*.
|
|
34
34
|
|
|
35
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,8 +11,8 @@ 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. Options: ${logger_1.LOG_LEVEL.join(',')}`, (value, previous) => {
|
|
15
|
-
const v = value
|
|
14
|
+
.option('-l, --log <log-level>', `min log level to display. Options: ${logger_1.LOG_LEVEL.join(',')}`, (value, previous) => {
|
|
15
|
+
const v = value?.toLowerCase();
|
|
16
16
|
if (logger_1.LOG_LEVEL.includes(v)) {
|
|
17
17
|
return v;
|
|
18
18
|
}
|
|
@@ -25,30 +25,29 @@ commander_1.program
|
|
|
25
25
|
.addHelpText('afterAll', 'To tunnel an ip to the subdomain `test`, you can use `-f test|192.168.1.130`')
|
|
26
26
|
.parse();
|
|
27
27
|
const options = commander_1.program.opts();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}
|
|
28
|
+
const forward = Array.isArray(options.forward) ? options.forward : [options.forward];
|
|
29
|
+
const tunnels = forward
|
|
30
|
+
.filter((v) => typeof v === 'string')
|
|
31
|
+
.map(v => {
|
|
32
|
+
const [segment, labelOrUrl, urlPart] = v.split('|');
|
|
33
|
+
let toUrl;
|
|
34
|
+
const label = urlPart ? labelOrUrl : segment;
|
|
35
|
+
const url = urlPart ?? labelOrUrl;
|
|
36
|
+
if (/^https?:\/\//.test(url)) {
|
|
37
|
+
toUrl = url;
|
|
38
|
+
}
|
|
39
|
+
else if (url.startsWith(':')) {
|
|
40
|
+
//only port specified
|
|
41
|
+
const port = +url.split(':')[1];
|
|
42
|
+
toUrl = `http://127.0.0.1:${port}`;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
toUrl = `http://${url}`;
|
|
46
|
+
}
|
|
47
|
+
return { remotePath: segment, localUrl: toUrl, label };
|
|
48
|
+
});
|
|
51
49
|
new client_1.Client({
|
|
50
|
+
agent: `${name}@${version}`,
|
|
52
51
|
hostname: options.host,
|
|
53
52
|
secure: !options.nonSecure,
|
|
54
53
|
tunnels,
|
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -17,11 +17,13 @@ class Client {
|
|
|
17
17
|
const qs = (0, node_querystring_1.stringify)({ s: segments });
|
|
18
18
|
this.options.logger?.info(`[nora-link] connecting`);
|
|
19
19
|
const protocol = this.options.secure ? 'wss' : 'ws';
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const headers = {
|
|
21
|
+
authorization: `Bearer ${this.options.apiKey}`,
|
|
22
|
+
...(this.options.agent ? {
|
|
23
|
+
'user-agent': this.options.agent,
|
|
24
|
+
} : {}),
|
|
25
|
+
};
|
|
26
|
+
const ws = new ws_1.default(`${protocol}://${this.options.hostname}/api/tunnel?${qs}`, { headers });
|
|
25
27
|
ws.on('open', () => {
|
|
26
28
|
this.options.logger?.info(`[nora-link] connected`);
|
|
27
29
|
observer.next(ws);
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -12,8 +12,8 @@ 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<LogLevel>('-l, --log', `min log level to display. Options: ${LOG_LEVEL.join(',')}`, (value, previous) => {
|
|
16
|
-
const v = value
|
|
15
|
+
.option<LogLevel>('-l, --log <log-level>', `min log level to display. Options: ${LOG_LEVEL.join(',')}`, (value, previous) => {
|
|
16
|
+
const v = value?.toLowerCase() as LogLevel;
|
|
17
17
|
if (LOG_LEVEL.includes(v)) {
|
|
18
18
|
return v;
|
|
19
19
|
}
|
|
@@ -28,32 +28,31 @@ program
|
|
|
28
28
|
|
|
29
29
|
const options = program.opts();
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
31
|
+
const forward = Array.isArray(options.forward) ? options.forward : [options.forward];
|
|
32
|
+
const tunnels: ClientConnectionOptions['tunnels'] = forward
|
|
33
|
+
.filter((v): v is string => typeof v === 'string')
|
|
34
|
+
.map(v => {
|
|
35
|
+
const [segment, labelOrUrl, urlPart] = v.split('|');
|
|
36
|
+
let toUrl: string;
|
|
37
|
+
|
|
38
|
+
const label = urlPart ? labelOrUrl : segment;
|
|
39
|
+
const url = urlPart ?? labelOrUrl;
|
|
40
|
+
|
|
41
|
+
if (/^https?:\/\//.test(url)) {
|
|
42
|
+
toUrl = url;
|
|
43
|
+
} else if (url.startsWith(':')) {
|
|
44
|
+
//only port specified
|
|
45
|
+
const port = +url.split(':')[1];
|
|
46
|
+
toUrl = `http://127.0.0.1:${port}`;
|
|
47
|
+
} else {
|
|
48
|
+
toUrl = `http://${url}`;
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
51
|
+
return { remotePath: segment, localUrl: toUrl, label };
|
|
52
|
+
});
|
|
55
53
|
|
|
56
54
|
new Client({
|
|
55
|
+
agent: `${name}@${version}`,
|
|
57
56
|
hostname: options.host,
|
|
58
57
|
secure: !options.nonSecure,
|
|
59
58
|
tunnels,
|
package/src/client.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface TunnelOptions {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface ClientConnectionOptions {
|
|
20
|
+
agent?: string;
|
|
20
21
|
hostname: string;
|
|
21
22
|
secure?: boolean;
|
|
22
23
|
apiKey: string;
|
|
@@ -33,11 +34,15 @@ export class Client {
|
|
|
33
34
|
const qs = querystringStringify({ s: segments });
|
|
34
35
|
this.options.logger?.info(`[nora-link] connecting`);
|
|
35
36
|
const protocol = this.options.secure ? 'wss' : 'ws';
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
|
|
38
|
+
const headers = {
|
|
39
|
+
authorization: `Bearer ${this.options.apiKey}`,
|
|
40
|
+
...(this.options.agent ? {
|
|
41
|
+
'user-agent': this.options.agent,
|
|
42
|
+
} : {}),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const ws = new WebSocket(`${protocol}://${this.options.hostname}/api/tunnel?${qs}`, { headers });
|
|
41
46
|
|
|
42
47
|
ws.on('open', () => {
|
|
43
48
|
this.options.logger?.info(`[nora-link] connected`);
|