node-red-contrib-mobius-flow-base 3.1.6 → 3.1.7
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;
|
|
@@ -63,7 +63,7 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
63
63
|
throw error;
|
|
64
64
|
});
|
|
65
65
|
this.EngineWebSocket = new engine_websocket_1.EngineWebSocket(this.hostname, this.protocol);
|
|
66
|
-
this.EngineWebSocket.on(
|
|
66
|
+
this.EngineWebSocket.on('disconnected', () => {
|
|
67
67
|
this.loggedIn = false;
|
|
68
68
|
});
|
|
69
69
|
}
|
|
@@ -71,8 +71,8 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
71
71
|
console.log(`(${this.hostname}) -> Attempting Mobius Engine API Login`);
|
|
72
72
|
try {
|
|
73
73
|
const response = await this.client({
|
|
74
|
-
method:
|
|
75
|
-
url:
|
|
74
|
+
method: 'post',
|
|
75
|
+
url: '/auth/login',
|
|
76
76
|
data: {
|
|
77
77
|
username: this.username,
|
|
78
78
|
password: this.password,
|
|
@@ -98,8 +98,8 @@ class EngineApiClient extends engine_api_calls_1.EngineApiCalls {
|
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
100
100
|
const response = await this.client({
|
|
101
|
-
method:
|
|
102
|
-
url:
|
|
101
|
+
method: 'post',
|
|
102
|
+
url: '/auth/refresh',
|
|
103
103
|
data: {
|
|
104
104
|
refreshToken: this.tokens.refreshToken,
|
|
105
105
|
},
|
|
@@ -108,6 +108,7 @@ module.exports = function (RED) {
|
|
|
108
108
|
shape: 'dot',
|
|
109
109
|
text: 'Failed discovery',
|
|
110
110
|
});
|
|
111
|
+
node.error(`Failed to discover objects`);
|
|
111
112
|
});
|
|
112
113
|
if (done) {
|
|
113
114
|
done();
|
|
@@ -122,113 +123,101 @@ module.exports = function (RED) {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
node.discoverAllObjectURIs = async function (msg) {
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
let objectList = [];
|
|
127
|
+
const hid = node.hid === '' ? node.serviceConn.hubId : node.hid;
|
|
128
|
+
const profiles = await discoverProfiles(
|
|
129
|
+
node.serviceConn,
|
|
130
|
+
hid,
|
|
131
|
+
node.subscriptions
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
for await (let entry of profiles.entries()) {
|
|
135
|
+
let discoverParams = {};
|
|
136
|
+
const serviceURI = entry[0];
|
|
137
|
+
const pids = entry[1];
|
|
138
|
+
if (node.useRIDValueFiltering) {
|
|
139
|
+
discoverParams = {
|
|
140
|
+
uri: serviceURI,
|
|
141
|
+
pids: pids,
|
|
142
|
+
rid: node.rid,
|
|
143
|
+
func: node.func,
|
|
144
|
+
limit: node.limit,
|
|
145
|
+
};
|
|
146
|
+
} else {
|
|
147
|
+
discoverParams = {
|
|
148
|
+
uri: serviceURI,
|
|
149
|
+
pids: pids,
|
|
150
|
+
rid: '00',
|
|
151
|
+
func: '(v) => { return true; }',
|
|
152
|
+
limit: 512,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
127
155
|
try {
|
|
128
|
-
|
|
129
|
-
const profiles = await discoverProfiles(
|
|
156
|
+
let objects = await filterObjectsByRIDValue(
|
|
130
157
|
node.serviceConn,
|
|
131
|
-
|
|
132
|
-
node.subscriptions
|
|
158
|
+
discoverParams
|
|
133
159
|
);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
rid: node.rid,
|
|
144
|
-
func: node.func,
|
|
145
|
-
limit: node.limit,
|
|
146
|
-
};
|
|
147
|
-
} else {
|
|
148
|
-
discoverParams = {
|
|
149
|
-
uri: serviceURI,
|
|
150
|
-
pids: pids,
|
|
151
|
-
rid: '00',
|
|
152
|
-
func: '(v) => { return true; }',
|
|
153
|
-
limit: 512,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
let objects = await filterObjectsByRIDValue(
|
|
158
|
-
node.serviceConn,
|
|
159
|
-
discoverParams
|
|
160
|
-
);
|
|
161
|
-
for (let lp = 0; lp < objects.value.length; lp++) {
|
|
162
|
-
objects.value[lp][
|
|
163
|
-
'uri'
|
|
164
|
-
] = `${serviceURI}/${objects.value[lp].pid}/${objects.value[lp].ins}`;
|
|
165
|
-
if (
|
|
166
|
-
isIncluded(
|
|
167
|
-
`${objects.value[lp]['uri']}`,
|
|
168
|
-
node.subscriptions
|
|
169
|
-
) &&
|
|
170
|
-
!isExcluded(`${objects.value[lp]['uri']}`, node.subscriptions)
|
|
171
|
-
) {
|
|
172
|
-
objectList.push(objects.value[lp]);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
} catch (err) {
|
|
176
|
-
node.warn(
|
|
177
|
-
`Discover object failed for service (${serviceURI}) - ${err.message}`
|
|
178
|
-
);
|
|
160
|
+
for (let lp = 0; lp < objects.value.length; lp++) {
|
|
161
|
+
objects.value[lp][
|
|
162
|
+
'uri'
|
|
163
|
+
] = `${serviceURI}/${objects.value[lp].pid}/${objects.value[lp].ins}`;
|
|
164
|
+
if (
|
|
165
|
+
isIncluded(`${objects.value[lp]['uri']}`, node.subscriptions) &&
|
|
166
|
+
!isExcluded(`${objects.value[lp]['uri']}`, node.subscriptions)
|
|
167
|
+
) {
|
|
168
|
+
objectList.push(objects.value[lp]);
|
|
179
169
|
}
|
|
180
170
|
}
|
|
181
|
-
|
|
182
|
-
if (objectList.length === 0) {
|
|
183
|
-
throw new Error('No discovery data found');
|
|
184
|
-
}
|
|
185
171
|
} catch (err) {
|
|
186
|
-
node.warn(
|
|
187
|
-
|
|
172
|
+
node.warn(
|
|
173
|
+
`Discover object failed for service (${serviceURI}) - ${err.message}`
|
|
174
|
+
);
|
|
188
175
|
}
|
|
189
|
-
|
|
190
|
-
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (objectList.length === 0) {
|
|
179
|
+
throw new Error('No discovery data found');
|
|
180
|
+
}
|
|
181
|
+
return objectList;
|
|
191
182
|
};
|
|
192
183
|
}
|
|
193
184
|
|
|
194
185
|
async function discoverProfiles(serviceConn, hid, subscriptions) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
pids.push(pid);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (pids.length > 0) {
|
|
210
|
-
discoveredProfiles.set(`${hid}/${sid}`, pids);
|
|
186
|
+
let discoveredProfiles = new Map();
|
|
187
|
+
let services = await discover(serviceConn, hid);
|
|
188
|
+
for (const service of services.data) {
|
|
189
|
+
if (service.status === 'online') {
|
|
190
|
+
let sid = service.id.split('/')[1];
|
|
191
|
+
if (isIncluded(`${hid}/${sid}/#`, subscriptions)) {
|
|
192
|
+
let profiles = await discover(serviceConn, `${hid}/${sid}`);
|
|
193
|
+
let pids = [];
|
|
194
|
+
for (const pid of profiles.data) {
|
|
195
|
+
if (isIncluded(`${hid}/${sid}/${pid}/#`, subscriptions)) {
|
|
196
|
+
pids.push(pid);
|
|
211
197
|
}
|
|
212
198
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
service.id.split('/')[1]
|
|
217
|
-
} as it is offline.`
|
|
218
|
-
);
|
|
199
|
+
if (pids.length > 0) {
|
|
200
|
+
discoveredProfiles.set(`${hid}/${sid}`, pids);
|
|
201
|
+
}
|
|
219
202
|
}
|
|
203
|
+
} else {
|
|
204
|
+
RED.log.warn(
|
|
205
|
+
`Failed to discover objects for service ${
|
|
206
|
+
service.id.split('/')[1]
|
|
207
|
+
} as it is offline.`
|
|
208
|
+
);
|
|
220
209
|
}
|
|
221
|
-
|
|
222
|
-
|
|
210
|
+
}
|
|
211
|
+
return discoveredProfiles;
|
|
223
212
|
}
|
|
224
213
|
|
|
225
214
|
async function discover(serviceConn, params) {
|
|
226
215
|
return new Promise((resolve, reject) => {
|
|
227
216
|
serviceConn.discover(params, (err, response) => {
|
|
228
217
|
if (err) {
|
|
229
|
-
reject(err);
|
|
218
|
+
return reject(err);
|
|
230
219
|
} else {
|
|
231
|
-
resolve(response);
|
|
220
|
+
return resolve(response);
|
|
232
221
|
}
|
|
233
222
|
});
|
|
234
223
|
});
|
|
@@ -244,9 +233,9 @@ module.exports = function (RED) {
|
|
|
244
233
|
eval('(' + params.func + ')'),
|
|
245
234
|
(err, response) => {
|
|
246
235
|
if (err) {
|
|
247
|
-
reject(err);
|
|
236
|
+
return reject(err);
|
|
248
237
|
} else {
|
|
249
|
-
resolve(response);
|
|
238
|
+
return resolve(response);
|
|
250
239
|
}
|
|
251
240
|
}
|
|
252
241
|
);
|