This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
73 lines (67 loc) · 1.85 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {ApiConnection} from '../common/connection.js';
import {RequestFunction} from 'src/common/types.js';
import {MiddlewareBitcoin} from './bitcoin.js';
import {MiddlewareLND} from './lnd.js';
import {MiddlewareLiquid} from './liquid';
import {MiddlewarePages} from './pages.js';
export class Middleware extends ApiConnection {
readonly pages: MiddlewarePages;
readonly bitcoin: MiddlewareBitcoin;
readonly lightning: MiddlewareLND;
readonly liquid: MiddlewareLiquid;
constructor(baseUrl: string) {
super(baseUrl);
this.pages = new MiddlewarePages(baseUrl);
this.bitcoin = new MiddlewareBitcoin(baseUrl);
this.lightning = new MiddlewareLND(baseUrl);
this.liquid = new MiddlewareLiquid(baseUrl);
}
/**
* Ping a node and get version information
*
* @returns Version information about the node
*/
public async ping(): Promise<{
version: string;
features?: string[];
isCitadel?: true | undefined;
}> {
return await this.get<{
version: string;
features?: string[];
isCitadel?: true | undefined;
}>('ping');
}
public async isOnline(): Promise<boolean> {
try {
await this.ping();
return true;
} catch {
return false;
}
}
public set jwt(newJwt: string) {
this.bitcoin.jwt =
this.pages.jwt =
this.lightning.jwt =
this.liquid.jwt =
this._jwt =
newJwt;
}
public set requestFunc(requestFunc: RequestFunction) {
this.bitcoin.requestFunc =
this.pages.requestFunc =
this.lightning.requestFunc =
this.liquid.requestFunc =
this._requestFunc =
requestFunc;
}
public set onAuthFailed(callback: (url: string) => void) {
this.bitcoin.onAuthFailed =
this.pages.onAuthFailed =
this.lightning.onAuthFailed =
this.liquid.onAuthFailed =
this._onAuthFailed =
callback;
}
}