node-red-contrib-mobius-flow-base 3.0.0-beta.15 → 3.0.0-beta.17
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/engine-api-calls.js
CHANGED
|
@@ -119,7 +119,6 @@ const sendDirectCommand = async (apiClient, uri, cid, commandData, timeout, call
|
|
|
119
119
|
};
|
|
120
120
|
exports.sendDirectCommand = sendDirectCommand;
|
|
121
121
|
const getServiceConfig = async (apiClient, uri, callback) => {
|
|
122
|
-
console.log(uri);
|
|
123
122
|
try {
|
|
124
123
|
const response = await apiClient({
|
|
125
124
|
method: 'get',
|
|
@@ -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 * 5);
|
|
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
|
}
|
|
@@ -73,10 +88,10 @@ const getApiClient = (protocol, host, port, username, password) => {
|
|
|
73
88
|
exports.loggedIn = true;
|
|
74
89
|
}
|
|
75
90
|
catch (err) {
|
|
91
|
+
console.log(JSON.stringify(err));
|
|
76
92
|
console.log('Failed to refresh Mobius Engine API token');
|
|
77
93
|
}
|
|
78
94
|
};
|
|
79
|
-
setInterval(refresh, 1000 * 60 * 5);
|
|
80
95
|
client.interceptors.response.use((res) => {
|
|
81
96
|
return res;
|
|
82
97
|
}, async (error) => {
|
|
@@ -85,6 +100,7 @@ const getApiClient = (protocol, host, port, username, password) => {
|
|
|
85
100
|
}
|
|
86
101
|
if (!error.config.url?.endsWith('/auth/login')) {
|
|
87
102
|
console.log(`Logged Out: ${JSON.stringify(error.response)}`);
|
|
103
|
+
clearInterval(refreshLoop);
|
|
88
104
|
(0, engine_websocket_1.disconnectFromWebSocket)();
|
|
89
105
|
exports.loggedIn = false;
|
|
90
106
|
exports.tokens = null;
|