node-red-contrib-mobius-flow-base 3.1.6-debug.1 → 3.1.6
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,6 +1,6 @@
|
|
|
1
|
-
import { AxiosInstance } from
|
|
2
|
-
import { EngineWebSocket } from
|
|
3
|
-
import { EngineApiCalls } from
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { EngineWebSocket } from "./engine-websocket";
|
|
3
|
+
import { EngineApiCalls } from "./engine-api-calls";
|
|
4
4
|
export declare class EngineApiClient extends EngineApiCalls {
|
|
5
5
|
private reloginInterval;
|
|
6
6
|
client: AxiosInstance | null;
|
|
@@ -15,7 +15,7 @@ export declare class EngineApiClient extends EngineApiCalls {
|
|
|
15
15
|
EngineWebSocket: EngineWebSocket;
|
|
16
16
|
private hostname;
|
|
17
17
|
private protocol;
|
|
18
|
-
constructor(protocol:
|
|
18
|
+
constructor(protocol: "http" | "https", host: string, username: string, password: string);
|
|
19
19
|
private login;
|
|
20
20
|
private refresh;
|
|
21
21
|
close: () => void;
|
|
@@ -29,7 +29,7 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
29
29
|
this.client = axios_1.default.create({
|
|
30
30
|
baseURL: baseURL,
|
|
31
31
|
headers: {
|
|
32
|
-
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
35
|
this.setApiClient(this.client);
|
|
@@ -42,15 +42,15 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
42
42
|
this.login();
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
console.log(
|
|
45
|
+
console.log("No username, password, host, or port provided. Not attempting to login to Mobius Engine API.");
|
|
46
46
|
this.reloginInterval && clearInterval(this.reloginInterval);
|
|
47
47
|
this.reloginInterval = null;
|
|
48
48
|
}
|
|
49
49
|
// Add auth headers to all axios calls
|
|
50
50
|
this.client.interceptors.request.use((config) => {
|
|
51
|
-
if (!config.url?.endsWith(
|
|
51
|
+
if (!config.url?.endsWith("/auth/login")) {
|
|
52
52
|
if (this.tokens && config.headers) {
|
|
53
|
-
config.headers[
|
|
53
|
+
config.headers["Authorization"] = `Bearer ${this.tokens.token}`;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
return config;
|
|
@@ -60,13 +60,10 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
60
60
|
this.client.interceptors.response.use((res) => {
|
|
61
61
|
return res;
|
|
62
62
|
}, async (error) => {
|
|
63
|
-
console.log('******************************* BEGIN PLANNED ERROR *******************************');
|
|
64
|
-
console.log(JSON.stringify(error, null, 2));
|
|
65
|
-
console.log('******************************* END PLANNED ERROR *******************************');
|
|
66
63
|
throw error;
|
|
67
64
|
});
|
|
68
65
|
this.EngineWebSocket = new engine_websocket_1.EngineWebSocket(this.hostname, this.protocol);
|
|
69
|
-
this.EngineWebSocket.on(
|
|
66
|
+
this.EngineWebSocket.on("disconnected", () => {
|
|
70
67
|
this.loggedIn = false;
|
|
71
68
|
});
|
|
72
69
|
}
|
|
@@ -74,8 +71,8 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
74
71
|
console.log(`(${this.hostname}) -> Attempting Mobius Engine API Login`);
|
|
75
72
|
try {
|
|
76
73
|
const response = await this.client({
|
|
77
|
-
method:
|
|
78
|
-
url:
|
|
74
|
+
method: "post",
|
|
75
|
+
url: "/auth/login",
|
|
79
76
|
data: {
|
|
80
77
|
username: this.username,
|
|
81
78
|
password: this.password,
|
|
@@ -101,8 +98,8 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
101
98
|
}
|
|
102
99
|
try {
|
|
103
100
|
const response = await this.client({
|
|
104
|
-
method:
|
|
105
|
-
url:
|
|
101
|
+
method: "post",
|
|
102
|
+
url: "/auth/refresh",
|
|
106
103
|
data: {
|
|
107
104
|
refreshToken: this.tokens.refreshToken,
|
|
108
105
|
},
|