@nora-link/client 1.1.1 → 1.3.0

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/client.d.ts CHANGED
@@ -13,6 +13,7 @@ export interface ClientConnectionOptions {
13
13
  apiKey: string;
14
14
  tunnels: TunnelOptions[];
15
15
  logger?: Logger;
16
+ clientId?: string;
16
17
  }
17
18
  export declare class Client {
18
19
  private options;
package/dist/client.js CHANGED
@@ -119,7 +119,7 @@ class Client {
119
119
  const { name, version } = require('../package.json');
120
120
  options.agent = `${name}@${version}`;
121
121
  }
122
- this.clientId = (0, node_crypto_1.randomBytes)(16).toString('base64url');
122
+ this.clientId = options.clientId ?? (0, node_crypto_1.randomBytes)(16).toString('base64url');
123
123
  }
124
124
  send(id, type, msg) {
125
125
  return this.server$.pipe((0, rxjs_1.first)(), (0, rxjs_1.switchMap)(ws => {
@@ -8,4 +8,4 @@ export declare function goIdleAndWaitForSignal(opts: {
8
8
  subdomains: string[];
9
9
  goOutOfIdle: () => void;
10
10
  logger?: Logger;
11
- }): Observable<'idle'>;
11
+ }): Observable<"idle">;
package/dist/firebase.js CHANGED
@@ -6,17 +6,24 @@ const app_1 = require("firebase/app");
6
6
  const auth_1 = require("firebase/auth");
7
7
  const database_1 = require("firebase/database");
8
8
  function goIdleAndWaitForSignal(opts) {
9
- return (0, rxjs_1.defer)(async () => {
9
+ return new rxjs_1.Observable((observer) => {
10
10
  const app = (0, app_1.initializeApp)({
11
11
  apiKey: opts.apiKey,
12
12
  }, `app-${new Date().getTime()}`);
13
13
  const auth = (0, auth_1.getAuth)(app);
14
- await (0, auth_1.signInWithCustomToken)(auth, opts.token);
15
- const db = (0, database_1.getDatabase)(app, opts.db);
16
- return (0, database_1.ref)(db, opts.dbKey);
17
- }).pipe((0, rxjs_1.switchMap)((watchRef) => new rxjs_1.Observable(observer => (0, database_1.onValue)(watchRef, snap => {
14
+ (0, auth_1.signInWithCustomToken)(auth, opts.token)
15
+ .then(() => {
16
+ const db = (0, database_1.getDatabase)(app, opts.db);
17
+ const dbRef = (0, database_1.ref)(db, opts.dbKey);
18
+ observer.next(dbRef);
19
+ })
20
+ .catch((err) => {
21
+ observer.error(err);
22
+ });
23
+ return () => (0, app_1.deleteApp)(app);
24
+ }).pipe((0, rxjs_1.switchMap)((watchRef) => new rxjs_1.Observable((observer) => (0, database_1.onValue)(watchRef, (snap) => {
18
25
  const value = snap.val() ?? {};
19
- observer.next(opts.subdomains.map(s => value[s] ?? null));
26
+ observer.next(opts.subdomains.map((s) => value[s] ?? null));
20
27
  }, (err) => {
21
28
  observer.error(err);
22
29
  }))), (0, rxjs_1.distinctUntilChanged)((a, b) => {
@@ -26,7 +33,7 @@ function goIdleAndWaitForSignal(opts) {
26
33
  }
27
34
  }
28
35
  return true;
29
- }), (0, rxjs_1.skip)(1), (0, rxjs_1.timeout)(3600 * 1000), (0, rxjs_1.tap)(() => opts.goOutOfIdle()), (0, rxjs_1.ignoreElements)(), (0, rxjs_1.startWith)('idle'), (0, rxjs_1.catchError)(err => {
36
+ }), (0, rxjs_1.skip)(1), (0, rxjs_1.timeout)(3600 * 1000), (0, rxjs_1.tap)(() => opts.goOutOfIdle()), (0, rxjs_1.ignoreElements)(), (0, rxjs_1.startWith)("idle"), (0, rxjs_1.catchError)((err) => {
30
37
  if (!(err instanceof rxjs_1.TimeoutError)) {
31
38
  opts.logger?.error(`[nora-link] idle error ${err}`);
32
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nora-link/client",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "noralink.eu client",
5
5
  "bin": {
6
6
  "noralink": "dist/cli.js"