@nora-link/client 1.0.11 → 1.0.13

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 CHANGED
@@ -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,7 +1,7 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { Logger } from './logger';
3
3
  export interface TunnelOptions {
4
- remotePath: string;
4
+ subdomain: string;
5
5
  url: string;
6
6
  label: string;
7
7
  removeHostHeader?: boolean;
package/dist/client.js CHANGED
@@ -13,10 +13,10 @@ 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
- const protocol = this.options.secure ? 'wss' : 'ws';
19
+ const protocol = (this.options.secure ?? true) ? 'wss' : 'ws';
20
20
  const headers = {
21
21
  authorization: `Bearer ${this.options.apiKey}`,
22
22
  ...(this.options.agent ? {
@@ -67,7 +67,7 @@ class Client {
67
67
  resetOnSuccess: true,
68
68
  delay: (err, retryCount) => {
69
69
  const delaySeconds = Math.round(Math.min(600, Math.pow(1.8, retryCount - 1)));
70
- this.options.logger?.error(`[nora-link] connection error`, err);
70
+ this.options.logger?.error(`[nora-link] connection error: ${err}`);
71
71
  this.options.logger?.info(`[nora-link] retrying in ${delaySeconds} sec`);
72
72
  return (0, rxjs_1.timer)(delaySeconds * 1000);
73
73
  },
@@ -99,7 +99,7 @@ class Client {
99
99
  const { url, subdomain, method, headers } = options;
100
100
  return new rxjs_1.Observable(reqObserver => {
101
101
  this.options.logger?.trace(`[nora-link] START ${method} ${url}`);
102
- const tunnel = this.options.tunnels.find(v => v.remotePath === subdomain);
102
+ const tunnel = this.options.tunnels.find(v => v.subdomain === subdomain);
103
103
  if (!tunnel) {
104
104
  throw new Error(`subdomain ${subdomain} not registered`);
105
105
  }
@@ -207,7 +207,7 @@ class Client {
207
207
  }
208
208
  return () => req.end();
209
209
  }).pipe((0, rxjs_1.catchError)(err => {
210
- this.options.logger?.warn(`[nora-link] error handling request`, err);
210
+ this.options.logger?.warn(`[nora-link] error handling request: ${err}`);
211
211
  return send(const_1.MessageTypes.BADGATEWAY);
212
212
  }), (0, rxjs_1.finalize)(() => {
213
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,14 +1,15 @@
1
1
  {
2
2
  "name": "@nora-link/client",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "noralink.eu client",
5
5
  "bin": {
6
6
  "noralink": "dist/cli.js"
7
7
  },
8
8
  "main": "dist/index.js",
9
9
  "scripts": {
10
+ "clean": "rm -rf dist",
10
11
  "build": "tsc",
11
- "pub": "npm run build && npm publish --access=public --registry https://registry.npmjs.org/"
12
+ "pub": "npm run clean && npm run build && npm publish --access=public --registry https://registry.npmjs.org/"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",