node-red-contrib-mobius-flow-base 3.1.4 → 3.1.6-debug.1
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 +34 -34
- package/dist/engine-api-client.d.ts +4 -4
- package/dist/engine-api-client.js +15 -20
- package/package.json +1 -1
package/dist/engine-api-calls.js
CHANGED
|
@@ -8,9 +8,9 @@ class EngineApiCalls {
|
|
|
8
8
|
this.apiClient = apiClient;
|
|
9
9
|
};
|
|
10
10
|
discover = async (uri, callback) => {
|
|
11
|
-
if (!this.apiClient)
|
|
12
|
-
throw new Error('No API client set');
|
|
13
11
|
try {
|
|
12
|
+
if (!this.apiClient)
|
|
13
|
+
throw new Error('No API client set');
|
|
14
14
|
const response = await this.apiClient({
|
|
15
15
|
method: 'get',
|
|
16
16
|
url: `/mobius/discover/${uri}`,
|
|
@@ -22,9 +22,9 @@ class EngineApiCalls {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
writeResource = async (uri, value, priority, callback) => {
|
|
25
|
-
if (!this.apiClient)
|
|
26
|
-
throw new Error('No API client set');
|
|
27
25
|
try {
|
|
26
|
+
if (!this.apiClient)
|
|
27
|
+
throw new Error('No API client set');
|
|
28
28
|
const response = await this.apiClient({
|
|
29
29
|
method: 'patch',
|
|
30
30
|
url: `/mobius/object/resource/${uri}`,
|
|
@@ -40,9 +40,9 @@ class EngineApiCalls {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
writeMultiResource = async (uri, updates, callback) => {
|
|
43
|
-
if (!this.apiClient)
|
|
44
|
-
throw new Error('No API client set');
|
|
45
43
|
try {
|
|
44
|
+
if (!this.apiClient)
|
|
45
|
+
throw new Error('No API client set');
|
|
46
46
|
const response = await this.apiClient({
|
|
47
47
|
method: 'patch',
|
|
48
48
|
url: `/mobius/object/resource/${uri}`,
|
|
@@ -55,9 +55,9 @@ class EngineApiCalls {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
clearResource = async (uri, priority, callback) => {
|
|
58
|
-
if (!this.apiClient)
|
|
59
|
-
throw new Error('No API client set');
|
|
60
58
|
try {
|
|
59
|
+
if (!this.apiClient)
|
|
60
|
+
throw new Error('No API client set');
|
|
61
61
|
const response = await this.apiClient({
|
|
62
62
|
method: 'patch',
|
|
63
63
|
url: `/mobius/object/resource/clear/${uri}`,
|
|
@@ -72,9 +72,9 @@ class EngineApiCalls {
|
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
readResource = async (uri, callback) => {
|
|
75
|
-
if (!this.apiClient)
|
|
76
|
-
throw new Error('No API client set');
|
|
77
75
|
try {
|
|
76
|
+
if (!this.apiClient)
|
|
77
|
+
throw new Error('No API client set');
|
|
78
78
|
const response = await this.apiClient({
|
|
79
79
|
method: 'get',
|
|
80
80
|
url: `/mobius/object/resource/${uri}`,
|
|
@@ -86,9 +86,9 @@ class EngineApiCalls {
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
readObject = async (uri, callback) => {
|
|
89
|
-
if (!this.apiClient)
|
|
90
|
-
throw new Error('No API client set');
|
|
91
89
|
try {
|
|
90
|
+
if (!this.apiClient)
|
|
91
|
+
throw new Error('No API client set');
|
|
92
92
|
const response = await this.apiClient({
|
|
93
93
|
method: 'get',
|
|
94
94
|
url: `/mobius/object/${uri}`,
|
|
@@ -100,9 +100,9 @@ class EngineApiCalls {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
sendBroadcastCommand = async (cid, commandData) => {
|
|
103
|
-
if (!this.apiClient)
|
|
104
|
-
throw new Error('No API client set');
|
|
105
103
|
try {
|
|
104
|
+
if (!this.apiClient)
|
|
105
|
+
throw new Error('No API client set');
|
|
106
106
|
const response = await this.apiClient({
|
|
107
107
|
method: 'post',
|
|
108
108
|
url: `/mobius/command/${cid}`,
|
|
@@ -114,9 +114,9 @@ class EngineApiCalls {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
sendDirectCommand = async (uri, cid, commandData, timeout, callback) => {
|
|
117
|
-
if (!this.apiClient)
|
|
118
|
-
throw new Error('No API client set');
|
|
119
117
|
try {
|
|
118
|
+
if (!this.apiClient)
|
|
119
|
+
throw new Error('No API client set');
|
|
120
120
|
const response = await this.apiClient({
|
|
121
121
|
method: 'post',
|
|
122
122
|
url: `/mobius/directCommand/${cid}`,
|
|
@@ -133,9 +133,9 @@ class EngineApiCalls {
|
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
getServiceConfig = async (uri, callback) => {
|
|
136
|
-
if (!this.apiClient)
|
|
137
|
-
throw new Error('No API client set');
|
|
138
136
|
try {
|
|
137
|
+
if (!this.apiClient)
|
|
138
|
+
throw new Error('No API client set');
|
|
139
139
|
const response = await this.apiClient({
|
|
140
140
|
method: 'get',
|
|
141
141
|
url: `/mobius/service/config/${uri}`,
|
|
@@ -147,9 +147,9 @@ class EngineApiCalls {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
updateObject = async (uri, config, callback) => {
|
|
150
|
-
if (!this.apiClient)
|
|
151
|
-
throw new Error('No API client set');
|
|
152
150
|
try {
|
|
151
|
+
if (!this.apiClient)
|
|
152
|
+
throw new Error('No API client set');
|
|
153
153
|
const response = await this.apiClient({
|
|
154
154
|
method: 'post',
|
|
155
155
|
url: `/mobius/object/config/${uri}`,
|
|
@@ -162,9 +162,9 @@ class EngineApiCalls {
|
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
164
|
filterObjectsByRIDValue = async (uri, pids, rid, limit, func, callback) => {
|
|
165
|
-
if (!this.apiClient)
|
|
166
|
-
throw new Error('No API client set');
|
|
167
165
|
try {
|
|
166
|
+
if (!this.apiClient)
|
|
167
|
+
throw new Error('No API client set');
|
|
168
168
|
const discoveries = [];
|
|
169
169
|
for (let pid of pids) {
|
|
170
170
|
discoveries.push(this.apiClient({
|
|
@@ -211,9 +211,9 @@ class EngineApiCalls {
|
|
|
211
211
|
}
|
|
212
212
|
};
|
|
213
213
|
getHubId = async (callback) => {
|
|
214
|
-
if (!this.apiClient)
|
|
215
|
-
throw new Error('No API client set');
|
|
216
214
|
try {
|
|
215
|
+
if (!this.apiClient)
|
|
216
|
+
throw new Error('No API client set');
|
|
217
217
|
const response = await this.apiClient({
|
|
218
218
|
method: 'get',
|
|
219
219
|
url: `/mobius/admin/settings`,
|
|
@@ -225,9 +225,9 @@ class EngineApiCalls {
|
|
|
225
225
|
}
|
|
226
226
|
};
|
|
227
227
|
getNodeConfig = async (uri, callback) => {
|
|
228
|
-
if (!this.apiClient)
|
|
229
|
-
throw new Error('No API client set');
|
|
230
228
|
try {
|
|
229
|
+
if (!this.apiClient)
|
|
230
|
+
throw new Error('No API client set');
|
|
231
231
|
const response = await this.apiClient({
|
|
232
232
|
method: 'get',
|
|
233
233
|
url: `/mobius/node/config/${uri}`,
|
|
@@ -239,9 +239,9 @@ class EngineApiCalls {
|
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
changeAdminPassword = async (password, callback) => {
|
|
242
|
-
if (!this.apiClient)
|
|
243
|
-
throw new Error('No API client set');
|
|
244
242
|
try {
|
|
243
|
+
if (!this.apiClient)
|
|
244
|
+
throw new Error('No API client set');
|
|
245
245
|
const response = await this.apiClient({
|
|
246
246
|
method: 'get',
|
|
247
247
|
url: `/auth/user/admin`,
|
|
@@ -261,9 +261,9 @@ class EngineApiCalls {
|
|
|
261
261
|
}
|
|
262
262
|
};
|
|
263
263
|
getNodeConfigTree = async (hid, callback) => {
|
|
264
|
-
if (!this.apiClient)
|
|
265
|
-
throw new Error('No API client set');
|
|
266
264
|
try {
|
|
265
|
+
if (!this.apiClient)
|
|
266
|
+
throw new Error('No API client set');
|
|
267
267
|
const response = await this.apiClient({
|
|
268
268
|
method: 'get',
|
|
269
269
|
url: `/mobius/node/configtree/${hid}`,
|
|
@@ -275,9 +275,9 @@ class EngineApiCalls {
|
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
getProfileByPid = async (hid, pid, callback) => {
|
|
278
|
-
if (!this.apiClient)
|
|
279
|
-
throw new Error('No API client set');
|
|
280
278
|
try {
|
|
279
|
+
if (!this.apiClient)
|
|
280
|
+
throw new Error('No API client set');
|
|
281
281
|
const response = await this.apiClient({
|
|
282
282
|
method: 'get',
|
|
283
283
|
url: `/mobius/profile/object/${hid}/${pid}`,
|
|
@@ -289,9 +289,9 @@ class EngineApiCalls {
|
|
|
289
289
|
}
|
|
290
290
|
};
|
|
291
291
|
getAllObjectProfiles = async (hid, callback) => {
|
|
292
|
-
if (!this.apiClient)
|
|
293
|
-
throw new Error('No API client set');
|
|
294
292
|
try {
|
|
293
|
+
if (!this.apiClient)
|
|
294
|
+
throw new Error('No API client set');
|
|
295
295
|
const response = await this.apiClient({
|
|
296
296
|
method: 'get',
|
|
297
297
|
url: `/mobius/profile/object/${hid}`,
|
|
@@ -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(
|
|
46
|
-
clearInterval(this.reloginInterval);
|
|
45
|
+
console.log('No username, password, host, or port provided. Not attempting to login to Mobius Engine API.');
|
|
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,27 +60,22 @@ 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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// if (!error.config.url?.endsWith("/auth/login")) {
|
|
67
|
-
// console.log(`(${this.hostname}) -> Logged Out: ${error.response}`);
|
|
68
|
-
// clearInterval(this.refreshLoop!);
|
|
69
|
-
// this.loggedIn = false;
|
|
70
|
-
// this.tokens = null;
|
|
71
|
-
// this.login();
|
|
72
|
-
// }
|
|
73
|
-
// Promise.reject(error);
|
|
63
|
+
console.log('******************************* BEGIN PLANNED ERROR *******************************');
|
|
64
|
+
console.log(JSON.stringify(error, null, 2));
|
|
65
|
+
console.log('******************************* END PLANNED ERROR *******************************');
|
|
74
66
|
throw error;
|
|
75
67
|
});
|
|
76
68
|
this.EngineWebSocket = new engine_websocket_1.EngineWebSocket(this.hostname, this.protocol);
|
|
69
|
+
this.EngineWebSocket.on('disconnected', () => {
|
|
70
|
+
this.loggedIn = false;
|
|
71
|
+
});
|
|
77
72
|
}
|
|
78
73
|
login = async () => {
|
|
79
74
|
console.log(`(${this.hostname}) -> Attempting Mobius Engine API Login`);
|
|
80
75
|
try {
|
|
81
76
|
const response = await this.client({
|
|
82
|
-
method:
|
|
83
|
-
url:
|
|
77
|
+
method: 'post',
|
|
78
|
+
url: '/auth/login',
|
|
84
79
|
data: {
|
|
85
80
|
username: this.username,
|
|
86
81
|
password: this.password,
|
|
@@ -106,8 +101,8 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
106
101
|
}
|
|
107
102
|
try {
|
|
108
103
|
const response = await this.client({
|
|
109
|
-
method:
|
|
110
|
-
url:
|
|
104
|
+
method: 'post',
|
|
105
|
+
url: '/auth/refresh',
|
|
111
106
|
data: {
|
|
112
107
|
refreshToken: this.tokens.refreshToken,
|
|
113
108
|
},
|