@nora-link/client 1.0.10 → 1.0.12

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
@@ -32,4 +32,10 @@ You can acess the tunnel by navigating to [https://noralink.eu/home](https://nor
32
32
 
33
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
- 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).
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).
36
+
37
+ ## Pricing
38
+
39
+ This service is currently free to use, but as our cloud costs grow, we plan to charge for use to cover the costs. This
40
+ means that while basic features will remain free, full access and advanced features will require a subscription. We
41
+ appreciate your understanding and support as we continue to improve our service.
package/dist/cli.js CHANGED
@@ -11,6 +11,7 @@ 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('-h, --host <hostname>', 'Server host name')
14
15
  .option('-l, --log <log-level>', `min log level to display. Options: ${logger_1.LOG_LEVEL.join(',')}`, (value, previous) => {
15
16
  const v = value?.toLowerCase();
16
17
  if (logger_1.LOG_LEVEL.includes(v)) {
@@ -20,7 +21,6 @@ commander_1.program
20
21
  }, 'info')
21
22
  .requiredOption('-f, --forward <subdomain|label|url...>', 'Tunnel subdomain to local url. Label is optional')
22
23
  .requiredOption('-k, --key <api-key>', 'Api Key')
23
- .requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
24
24
  .addHelpText('afterAll', 'To tunnel a local port to the subdomain `test`, you can use `-f "test|localhost:3000"`')
25
25
  .addHelpText('afterAll', 'To tunnel an ip to the subdomain `test`, you can use `-f "test|192.168.1.130"`')
26
26
  .addHelpText('afterAll', 'To tunnel a local hostname to the subdomain `test` with label `My App`, you can use `-f "test|My App|local-host.local"`')
@@ -31,15 +31,15 @@ if (Array.isArray(options.forward)) {
31
31
  tunnels = options.forward
32
32
  .filter((v) => typeof v === 'string')
33
33
  .map(v => {
34
- const [segment, labelOrUrl, urlPart] = v.split('|');
35
- const label = urlPart ? labelOrUrl : segment;
34
+ const [subdomain, labelOrUrl, urlPart] = v.split('|');
35
+ const label = urlPart ? labelOrUrl : subdomain;
36
36
  let url = urlPart ?? labelOrUrl;
37
37
  const urlHasProtocol = /^https?:\/\//.test(url);
38
38
  if (!urlHasProtocol) {
39
39
  //if missing protocol, assume http
40
40
  url = `http://${url}`;
41
41
  }
42
- return { remotePath: segment, url, label };
42
+ return { subdomain, url, label };
43
43
  });
44
44
  }
45
45
  if (!tunnels.length) {
package/dist/client.d.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  import { Observable } from 'rxjs';
2
- import WebSocket from 'ws';
3
2
  import { Logger } from './logger';
4
3
  export interface TunnelOptions {
5
- remotePath: string;
4
+ subdomain: string;
6
5
  url: string;
7
6
  label: string;
8
7
  removeHostHeader?: boolean;
9
8
  }
10
9
  export interface ClientConnectionOptions {
11
10
  agent?: string;
12
- hostname: string;
11
+ hostname?: string;
13
12
  secure?: boolean;
14
13
  apiKey: string;
15
14
  tunnels: TunnelOptions[];
@@ -20,8 +19,8 @@ export declare class Client {
20
19
  constructor(options: ClientConnectionOptions);
21
20
  private server$;
22
21
  private data$;
23
- readonly handle$: Observable<void | WebSocket>;
24
- send(id: number, type: string, msg?: Buffer): Observable<void>;
22
+ readonly handle$: Observable<'connected' | 'connecting'>;
23
+ private send;
25
24
  private getStreamData;
26
25
  private httpRequest;
27
26
  }
package/dist/client.js CHANGED
@@ -13,8 +13,8 @@ class Client {
13
13
  constructor(options) {
14
14
  this.options = options;
15
15
  this.server$ = new rxjs_1.Observable(observer => {
16
- const segments = this.options.tunnels.map(v => `${v.remotePath}|${v.label}`);
17
- const qs = (0, node_querystring_1.stringify)({ s: segments });
16
+ const subdomains = this.options.tunnels.map(v => `${v.subdomain}|${v.label}`);
17
+ const qs = (0, node_querystring_1.stringify)({ s: subdomains });
18
18
  this.options.logger?.info(`[nora-link] connecting`);
19
19
  const protocol = this.options.secure ? 'wss' : 'ws';
20
20
  const headers = {
@@ -23,7 +23,8 @@ class Client {
23
23
  'user-agent': this.options.agent,
24
24
  } : {}),
25
25
  };
26
- const ws = new ws_1.default(`${protocol}://${this.options.hostname}/api/tunnel?${qs}`, { headers });
26
+ const hostname = this.options.hostname ?? 'noralink.eu';
27
+ const ws = new ws_1.default(`${protocol}://${hostname}/api/tunnel?${qs}`, { headers });
27
28
  ws.on('open', () => {
28
29
  this.options.logger?.info(`[nora-link] connected`);
29
30
  observer.next(ws);
@@ -62,11 +63,11 @@ class Client {
62
63
  data$: this.getStreamData(id),
63
64
  send: (type, msg) => this.send(id, type, msg),
64
65
  })
65
- : rxjs_1.EMPTY))).pipe((0, rxjs_1.retry)({
66
+ : rxjs_1.EMPTY))).pipe((0, rxjs_1.startWith)('connecting'), (0, rxjs_1.map)(_ => 'connected'), (0, rxjs_1.retry)({
66
67
  resetOnSuccess: true,
67
68
  delay: (err, retryCount) => {
68
69
  const delaySeconds = Math.round(Math.min(600, Math.pow(1.8, retryCount - 1)));
69
- this.options.logger?.error(`[nora-link] connection error`, err);
70
+ this.options.logger?.error(`[nora-link] connection error: ${err}`);
70
71
  this.options.logger?.info(`[nora-link] retrying in ${delaySeconds} sec`);
71
72
  return (0, rxjs_1.timer)(delaySeconds * 1000);
72
73
  },
@@ -98,7 +99,7 @@ class Client {
98
99
  const { url, subdomain, method, headers } = options;
99
100
  return new rxjs_1.Observable(reqObserver => {
100
101
  this.options.logger?.trace(`[nora-link] START ${method} ${url}`);
101
- const tunnel = this.options.tunnels.find(v => v.remotePath === subdomain);
102
+ const tunnel = this.options.tunnels.find(v => v.subdomain === subdomain);
102
103
  if (!tunnel) {
103
104
  throw new Error(`subdomain ${subdomain} not registered`);
104
105
  }
@@ -206,7 +207,7 @@ class Client {
206
207
  }
207
208
  return () => req.end();
208
209
  }).pipe((0, rxjs_1.catchError)(err => {
209
- this.options.logger?.warn(`[nora-link] error handling request`, err);
210
+ this.options.logger?.warn(`[nora-link] error handling request: ${err}`);
210
211
  return send(const_1.MessageTypes.BADGATEWAY);
211
212
  }), (0, rxjs_1.finalize)(() => {
212
213
  this.options.logger?.trace(`[nora-link] DONE ${method} ${url}`);
package/dist/logger.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export declare const LOG_LEVEL: readonly ["trace", "debug", "info", "warn", "error"];
2
2
  export type LogLevel = typeof LOG_LEVEL[number];
3
3
  export type Logger = {
4
- [P in LogLevel]: (msg: string, err?: any) => void;
4
+ [P in LogLevel]: (msg: string) => void;
5
5
  };
6
6
  export declare function createConsoleLogger(minLevel: LogLevel): Logger;
package/dist/logger.js CHANGED
@@ -17,10 +17,7 @@ function createConsoleLogger(minLevel) {
17
17
  return;
18
18
  }
19
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);
20
+ console.log(`[${now}][${kind}]${args[0]}`);
24
21
  }
25
22
  return new Proxy({}, {
26
23
  get: function (_, name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nora-link/client",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "noralink.eu client",
5
5
  "bin": {
6
6
  "noralink": "dist/cli.js"