@nora-link/client 1.2.0 → 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.
@@ -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.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "noralink.eu client",
5
5
  "bin": {
6
6
  "noralink": "dist/cli.js"