@nora-link/client 1.0.1 → 1.0.2

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
@@ -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/-/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
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 path `test-app` to `internal-server.local:1234/sample-path`. Replace `[your-api-key]` with the API key you obtained before.
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 test-app|internal-server.local:1234/sample-path -k [your-api-key]`
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,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('-l, --log', `min log level to display (${logger_1.LOG_LEVEL.join(',')})`, new RegExp(`^${logger_1.LOG_LEVEL.join('|')}$`), 'info')
14
15
  .requiredOption('-f, --forward <path|label|url...>', 'Forward path to local url')
15
16
  .requiredOption('-k, --key <api-key>', 'Api Key')
16
17
  .requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
@@ -46,6 +47,6 @@ new client_1.Client({
46
47
  secure: !options.nonSecure,
47
48
  tunnels,
48
49
  apiKey: options.key,
49
- logger: logger_1.consoleLogger,
50
+ logger: (0, logger_1.createConsoleLogger)(options.log),
50
51
  }).handle$
51
52
  .subscribe();
package/dist/logger.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export interface Logger {
2
- trace(msg: string, err?: any): void;
3
- info(msg: string, err?: any): void;
4
- error(msg: string, err?: any): void;
5
- }
6
- export declare const consoleLogger: Logger;
1
+ export declare const LOG_LEVEL: readonly ["trace", "debug", "info", "warn", "error"];
2
+ 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;
7
+ export {};
package/dist/logger.js CHANGED
@@ -1,14 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.consoleLogger = void 0;
4
- exports.consoleLogger = {
5
- trace(...args) {
6
- console.log(...args);
7
- },
8
- info(...args) {
9
- console.log(...args);
10
- },
11
- error(...args) {
12
- console.log(...args);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nora-link/client",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "noralink.eu client",
5
5
  "bin": {
6
6
  "noralink": "dist/cli.js"
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 { consoleLogger } from './logger';
5
+ import { createConsoleLogger, LOG_LEVEL } from './logger';
6
6
 
7
7
  const { name, version } = require('../package.json');
8
8
 
@@ -12,6 +12,7 @@ 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 (${LOG_LEVEL.join(',')})`, new RegExp(`^${LOG_LEVEL.join('|')}$`), 'info')
15
16
  .requiredOption('-f, --forward <path|label|url...>', 'Forward path to local url')
16
17
  .requiredOption('-k, --key <api-key>', 'Api Key')
17
18
  .requiredOption('-h, --host <hostname>', 'Server host name', 'noralink.eu')
@@ -51,7 +52,7 @@ new Client({
51
52
  secure: !options.nonSecure,
52
53
  tunnels,
53
54
  apiKey: options.key,
54
- logger: consoleLogger,
55
+ logger: createConsoleLogger(options.log),
55
56
  }).handle$
56
57
  .subscribe();
57
58
 
package/src/logger.ts CHANGED
@@ -1,19 +1,34 @@
1
- export interface Logger {
2
- trace(msg: string, err?: any): void;
3
- info(msg: string, err?: any): void;
4
- error(msg: string, err?: any): void;
1
+ export const LOG_LEVEL = [
2
+ 'trace',
3
+ 'debug',
4
+ 'info',
5
+ 'warn',
6
+ 'error'
7
+ ] as const;
8
+
9
+ 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 const consoleLogger: Logger = {
8
- trace(...args) {
9
- console.log(...args);
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
- info(...args) {
13
- console.log(...args);
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
- error(...args) {
17
- console.log(...args);
18
- },
19
- }
29
+ return new Proxy({}, {
30
+ get: function (_, name: LogLevel) {
31
+ return log.bind(null, name);
32
+ }
33
+ }) as Logger;
34
+ }