node-red-contrib-mobius-flow-base 3.0.0-beta.15 → 3.0.0-beta.16
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.
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
1
2
|
export declare let tokens: null | {
|
|
2
3
|
token: string;
|
|
3
4
|
refreshToken: string;
|
|
4
5
|
};
|
|
5
6
|
export declare let loggedIn: boolean;
|
|
6
|
-
export declare const getApiClient: (protocol: 'http' | 'https', host: string, port: number, username: string, password: string) =>
|
|
7
|
+
export declare const getApiClient: (protocol: 'http' | 'https', host: string, port: number, username: string, password: string) => AxiosInstance;
|
|
7
8
|
export declare const setLoggedIn: (value: boolean) => void;
|
|
8
9
|
export declare const closeApiClient: () => void;
|
|
@@ -9,11 +9,24 @@ const engine_websocket_1 = require("./engine-websocket");
|
|
|
9
9
|
exports.tokens = null;
|
|
10
10
|
exports.loggedIn = false;
|
|
11
11
|
let reloginInterval = null;
|
|
12
|
+
let client = null;
|
|
13
|
+
let refreshLoop = null;
|
|
12
14
|
const getApiClient = (protocol, host, port, username, password) => {
|
|
15
|
+
if (client) {
|
|
16
|
+
try {
|
|
17
|
+
(0, engine_websocket_1.disconnectFromWebSocket)();
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
client = null;
|
|
21
|
+
}
|
|
22
|
+
if (refreshLoop) {
|
|
23
|
+
clearInterval(refreshLoop);
|
|
24
|
+
refreshLoop = null;
|
|
25
|
+
}
|
|
13
26
|
(0, engine_websocket_1.setWebSocketConnectParams)(host, port, protocol);
|
|
14
27
|
//const baseURL = `http://localhost:8443/api/v1`;
|
|
15
28
|
const baseURL = `${protocol}://${host}:${port}/api/v1`;
|
|
16
|
-
|
|
29
|
+
client = axios_1.default.create({
|
|
17
30
|
baseURL: baseURL,
|
|
18
31
|
headers: {
|
|
19
32
|
'Content-Type': 'application/json',
|
|
@@ -49,9 +62,11 @@ const getApiClient = (protocol, host, port, username, password) => {
|
|
|
49
62
|
exports.tokens = response.data;
|
|
50
63
|
exports.loggedIn = true;
|
|
51
64
|
console.log('Logged in to Mobius Engine API');
|
|
65
|
+
refreshLoop = setInterval(refresh, 1000 * 60 * 1);
|
|
52
66
|
(0, engine_websocket_1.connectToWebSocket)();
|
|
53
67
|
}
|
|
54
68
|
catch (e) {
|
|
69
|
+
clearInterval(refreshLoop);
|
|
55
70
|
(0, engine_websocket_1.disconnectFromWebSocket)();
|
|
56
71
|
exports.loggedIn = false;
|
|
57
72
|
}
|
|
@@ -62,6 +77,7 @@ const getApiClient = (protocol, host, port, username, password) => {
|
|
|
62
77
|
return;
|
|
63
78
|
}
|
|
64
79
|
try {
|
|
80
|
+
console.log(exports.tokens);
|
|
65
81
|
const response = await client({
|
|
66
82
|
method: 'post',
|
|
67
83
|
url: '/auth/refresh',
|
|
@@ -73,10 +89,10 @@ const getApiClient = (protocol, host, port, username, password) => {
|
|
|
73
89
|
exports.loggedIn = true;
|
|
74
90
|
}
|
|
75
91
|
catch (err) {
|
|
92
|
+
console.log(JSON.stringify(err));
|
|
76
93
|
console.log('Failed to refresh Mobius Engine API token');
|
|
77
94
|
}
|
|
78
95
|
};
|
|
79
|
-
setInterval(refresh, 1000 * 60 * 5);
|
|
80
96
|
client.interceptors.response.use((res) => {
|
|
81
97
|
return res;
|
|
82
98
|
}, async (error) => {
|
|
@@ -85,6 +101,7 @@ const getApiClient = (protocol, host, port, username, password) => {
|
|
|
85
101
|
}
|
|
86
102
|
if (!error.config.url?.endsWith('/auth/login')) {
|
|
87
103
|
console.log(`Logged Out: ${JSON.stringify(error.response)}`);
|
|
104
|
+
clearInterval(refreshLoop);
|
|
88
105
|
(0, engine_websocket_1.disconnectFromWebSocket)();
|
|
89
106
|
exports.loggedIn = false;
|
|
90
107
|
exports.tokens = null;
|