node-red-contrib-mobius-flow-base 3.0.0-rc.3 → 3.0.0-rc.5

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,21 +1,52 @@
1
1
  import { AxiosInstance } from 'axios';
2
- export declare const discover: (apiClient: AxiosInstance, uri: string, callback: Function) => Promise<void>;
3
- export declare const writeResource: (apiClient: AxiosInstance, uri: string, value: number | string | boolean, priority: number, callback: Function) => Promise<void>;
4
- export declare const writeMultiResource: (apiClient: AxiosInstance, uri: string, updates: {
5
- r: string;
6
- p: number;
7
- v: number | string | boolean;
8
- }[], callback: Function) => Promise<void>;
9
- export declare const clearResource: (apiClient: AxiosInstance, uri: string, priority: number, callback: Function) => Promise<void>;
10
- export declare const readResource: (apiClient: AxiosInstance, uri: string, callback: Function) => Promise<void>;
11
- export declare const readObject: (apiClient: AxiosInstance, uri: string, callback: Function) => Promise<void>;
12
- export declare const sendBroadcastCommand: (apiClient: AxiosInstance, cid: string, commandData: any) => Promise<void>;
13
- export declare const sendDirectCommand: (apiClient: AxiosInstance, uri: string, cid: string, commandData: any, timeout: number, callback: Function) => Promise<void>;
14
- export declare const getServiceConfig: (apiClient: AxiosInstance, uri: string, callback: Function) => Promise<void>;
15
- export declare const updateObject: (apiClient: AxiosInstance, uri: string, config: any, callback: Function) => Promise<void>;
16
- export declare const filterObjectsByRIDValue: (apiClient: AxiosInstance, uri: string, pids: string[], rid: string, limit: number, func: (v: string | number | boolean) => boolean, callback: Function) => Promise<any>;
17
- export declare const getHubId: (apiClient: AxiosInstance, callback: Function) => Promise<void>;
18
- export declare const getNodeConfig: (apiClient: AxiosInstance, uri: string, callback: Function) => Promise<void>;
19
- export declare const changeAdminPassword: (apiClient: AxiosInstance, password: string, callback: Function) => Promise<void>;
20
- export declare const getNodeConfigTree: (apiClient: AxiosInstance, hid: string, callback: Function) => Promise<void>;
21
- export declare const getProfileByPid: (apiClient: AxiosInstance, hid: string, pid: string, callback: Function) => Promise<void>;
2
+ interface EngineApiCallsInterace {
3
+ setApiClient: (apiClient: AxiosInstance) => void;
4
+ discover: (uri: string, callback: Function) => void;
5
+ writeResource: (uri: string, value: number | string | boolean, priority: number, callback: Function) => void;
6
+ writeMultiResource: (uri: string, updates: {
7
+ r: string;
8
+ p: number;
9
+ v: number | string | boolean;
10
+ }[], callback: Function) => void;
11
+ clearResource: (uri: string, priority: number, callback: Function) => void;
12
+ readResource: (uri: string, callback: Function) => void;
13
+ readObject: (uri: string, callback: Function) => void;
14
+ sendBroadcastCommand: (cid: string, commandData: any) => void;
15
+ sendDirectCommand: (uri: string, cid: string, commandData: any, timeout: number, callback: Function) => void;
16
+ getServiceConfig: (uri: string, callback: Function) => void;
17
+ updateObject: (uri: string, config: any, callback: Function) => void;
18
+ filterObjectsByRIDValue: (uri: string, pids: string[], rid: string, limit: number, func: (v: string | number | boolean) => boolean, callback: Function) => void;
19
+ getHubId: (callback: Function) => void;
20
+ getNodeConfig: (uri: string, callback: Function) => void;
21
+ changeAdminPassword: (password: string, callback: Function) => void;
22
+ getNodeConfigTree: (hid: string, callback: Function) => void;
23
+ getProfileByPid: (hid: string, pid: string, callback: Function) => void;
24
+ getAllObjectProfiles: (hid: string, callback: Function) => void;
25
+ }
26
+ export declare class EngineApiCalls implements EngineApiCallsInterace {
27
+ private apiClient;
28
+ constructor();
29
+ setApiClient: (apiClient: AxiosInstance) => void;
30
+ discover: (uri: string, callback: Function) => Promise<void>;
31
+ writeResource: (uri: string, value: number | string | boolean, priority: number, callback: Function) => Promise<void>;
32
+ writeMultiResource: (uri: string, updates: {
33
+ r: string;
34
+ p: number;
35
+ v: number | string | boolean;
36
+ }[], callback: Function) => Promise<void>;
37
+ clearResource: (uri: string, priority: number, callback: Function) => Promise<void>;
38
+ readResource: (uri: string, callback: Function) => Promise<void>;
39
+ readObject: (uri: string, callback: Function) => Promise<void>;
40
+ sendBroadcastCommand: (cid: string, commandData: any) => Promise<void>;
41
+ sendDirectCommand: (uri: string, cid: string, commandData: any, timeout: number, callback: Function) => Promise<void>;
42
+ getServiceConfig: (uri: string, callback: Function) => Promise<void>;
43
+ updateObject: (uri: string, config: any, callback: Function) => Promise<void>;
44
+ filterObjectsByRIDValue: (uri: string, pids: string[], rid: string, limit: number, func: (v: string | number | boolean) => boolean, callback: Function) => Promise<any>;
45
+ getHubId: (callback: Function) => Promise<void>;
46
+ getNodeConfig: (uri: string, callback: Function) => Promise<void>;
47
+ changeAdminPassword: (password: string, callback: Function) => Promise<void>;
48
+ getNodeConfigTree: (hid: string, callback: Function) => Promise<void>;
49
+ getProfileByPid: (hid: string, pid: string, callback: Function) => Promise<void>;
50
+ getAllObjectProfiles: (hid: string, callback: Function) => Promise<void>;
51
+ }
52
+ export {};
@@ -1,260 +1,299 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProfileByPid = exports.getNodeConfigTree = exports.changeAdminPassword = exports.getNodeConfig = exports.getHubId = exports.filterObjectsByRIDValue = exports.updateObject = exports.getServiceConfig = exports.sendDirectCommand = exports.sendBroadcastCommand = exports.readObject = exports.readResource = exports.clearResource = exports.writeMultiResource = exports.writeResource = exports.discover = void 0;
4
- const discover = async (apiClient, uri, callback) => {
5
- try {
6
- const response = await apiClient({
7
- method: 'get',
8
- url: `/mobius/discover/${uri}`,
9
- });
10
- callback(null, response.data);
11
- }
12
- catch (err) {
13
- callback(err);
14
- }
15
- };
16
- exports.discover = discover;
17
- const writeResource = async (apiClient, uri, value, priority, callback) => {
18
- try {
19
- const response = await apiClient({
20
- method: 'patch',
21
- url: `/mobius/object/resource/${uri}`,
22
- data: {
23
- value,
24
- priority,
25
- },
26
- });
27
- callback(null, response.data);
28
- }
29
- catch (err) {
30
- callback(err);
31
- }
32
- };
33
- exports.writeResource = writeResource;
34
- const writeMultiResource = async (apiClient, uri, updates, callback) => {
35
- try {
36
- const response = await apiClient({
37
- method: 'patch',
38
- url: `/mobius/object/resource/${uri}`,
39
- data: updates,
40
- });
41
- callback(null, response.data);
42
- }
43
- catch (err) {
44
- callback(err);
45
- }
46
- };
47
- exports.writeMultiResource = writeMultiResource;
48
- const clearResource = async (apiClient, uri, priority, callback) => {
49
- try {
50
- const response = await apiClient({
51
- method: 'patch',
52
- url: `/mobius/object/resource/clear/${uri}`,
53
- data: {
54
- priority,
55
- },
56
- });
57
- callback(null, response.data);
58
- }
59
- catch (err) {
60
- callback(err);
61
- }
62
- };
63
- exports.clearResource = clearResource;
64
- const readResource = async (apiClient, uri, callback) => {
65
- try {
66
- const response = await apiClient({
67
- method: 'get',
68
- url: `/mobius/object/resource/${uri}`,
69
- });
70
- callback(null, response.data);
71
- }
72
- catch (err) {
73
- callback(err);
74
- }
75
- };
76
- exports.readResource = readResource;
77
- const readObject = async (apiClient, uri, callback) => {
78
- try {
79
- const response = await apiClient({
80
- method: 'get',
81
- url: `/mobius/object/${uri}`,
82
- });
83
- callback(null, response.data);
84
- }
85
- catch (err) {
86
- callback(err);
87
- }
88
- };
89
- exports.readObject = readObject;
90
- const sendBroadcastCommand = async (apiClient, cid, commandData) => {
91
- try {
92
- const response = await apiClient({
93
- method: 'post',
94
- url: `/mobius/command/${cid}`,
95
- data: commandData,
96
- });
97
- }
98
- catch (err) {
99
- throw `Failed to send broadcast command: ${JSON.stringify(err)}`;
100
- }
101
- };
102
- exports.sendBroadcastCommand = sendBroadcastCommand;
103
- const sendDirectCommand = async (apiClient, uri, cid, commandData, timeout, callback) => {
104
- try {
105
- const response = await apiClient({
106
- method: 'post',
107
- url: `/mobius/directCommand/${cid}`,
108
- data: {
109
- uri,
110
- commandData,
111
- timeout,
112
- },
113
- });
114
- callback(null, response.data);
115
- }
116
- catch (err) {
117
- callback(err);
118
- }
119
- };
120
- exports.sendDirectCommand = sendDirectCommand;
121
- const getServiceConfig = async (apiClient, uri, callback) => {
122
- try {
123
- const response = await apiClient({
124
- method: 'get',
125
- url: `/mobius/service/config/${uri}`,
126
- });
127
- callback(null, response.data);
128
- }
129
- catch (err) {
130
- callback(err);
131
- }
132
- };
133
- exports.getServiceConfig = getServiceConfig;
134
- const updateObject = async (apiClient, uri, config, callback) => {
135
- try {
136
- const response = await apiClient({
137
- method: 'post',
138
- url: `/mobius/object/config/${uri}`,
139
- data: config,
140
- });
141
- callback(null, response.data);
142
- }
143
- catch (err) {
144
- callback(err);
145
- }
146
- };
147
- exports.updateObject = updateObject;
148
- const filterObjectsByRIDValue = async (apiClient, uri, pids, rid, limit, func, callback) => {
149
- try {
150
- const discoveries = [];
151
- for (let pid of pids) {
152
- discoveries.push(apiClient({
3
+ exports.EngineApiCalls = void 0;
4
+ class EngineApiCalls {
5
+ apiClient = null;
6
+ constructor() {
7
+ }
8
+ setApiClient = (apiClient) => {
9
+ this.apiClient = apiClient;
10
+ };
11
+ discover = async (uri, callback) => {
12
+ if (!this.apiClient)
13
+ throw new Error('No API client set');
14
+ try {
15
+ const response = await this.apiClient({
153
16
  method: 'get',
154
- url: `/mobius/discover/${uri}/${pid}`,
155
- }));
17
+ url: `/mobius/discover/${uri}`,
18
+ });
19
+ callback(null, response.data);
156
20
  }
157
- const pidGroups = (await Promise.all(discoveries)).map((response) => ({
158
- uri: response.data.uri,
159
- inss: response.data.data,
160
- }));
161
- const objectUris = [];
162
- for (let pidGroup of pidGroups) {
163
- for (let ins of pidGroup.inss) {
164
- objectUris.push(`${pidGroup.uri}/${ins}`);
165
- }
21
+ catch (err) {
22
+ callback(err);
23
+ }
24
+ };
25
+ writeResource = async (uri, value, priority, callback) => {
26
+ if (!this.apiClient)
27
+ throw new Error('No API client set');
28
+ try {
29
+ const response = await this.apiClient({
30
+ method: 'patch',
31
+ url: `/mobius/object/resource/${uri}`,
32
+ data: {
33
+ value,
34
+ priority,
35
+ },
36
+ });
37
+ callback(null, response.data);
38
+ }
39
+ catch (err) {
40
+ callback(err);
41
+ }
42
+ };
43
+ writeMultiResource = async (uri, updates, callback) => {
44
+ if (!this.apiClient)
45
+ throw new Error('No API client set');
46
+ try {
47
+ const response = await this.apiClient({
48
+ method: 'patch',
49
+ url: `/mobius/object/resource/${uri}`,
50
+ data: updates,
51
+ });
52
+ callback(null, response.data);
53
+ }
54
+ catch (err) {
55
+ callback(err);
56
+ }
57
+ };
58
+ clearResource = async (uri, priority, callback) => {
59
+ if (!this.apiClient)
60
+ throw new Error('No API client set');
61
+ try {
62
+ const response = await this.apiClient({
63
+ method: 'patch',
64
+ url: `/mobius/object/resource/clear/${uri}`,
65
+ data: {
66
+ priority,
67
+ },
68
+ });
69
+ callback(null, response.data);
70
+ }
71
+ catch (err) {
72
+ callback(err);
73
+ }
74
+ };
75
+ readResource = async (uri, callback) => {
76
+ if (!this.apiClient)
77
+ throw new Error('No API client set');
78
+ try {
79
+ const response = await this.apiClient({
80
+ method: 'get',
81
+ url: `/mobius/object/resource/${uri}`,
82
+ });
83
+ callback(null, response.data);
84
+ }
85
+ catch (err) {
86
+ callback(err);
87
+ }
88
+ };
89
+ readObject = async (uri, callback) => {
90
+ if (!this.apiClient)
91
+ throw new Error('No API client set');
92
+ try {
93
+ const response = await this.apiClient({
94
+ method: 'get',
95
+ url: `/mobius/object/${uri}`,
96
+ });
97
+ callback(null, response.data);
98
+ }
99
+ catch (err) {
100
+ callback(err);
101
+ }
102
+ };
103
+ sendBroadcastCommand = async (cid, commandData) => {
104
+ if (!this.apiClient)
105
+ throw new Error('No API client set');
106
+ try {
107
+ const response = await this.apiClient({
108
+ method: 'post',
109
+ url: `/mobius/command/${cid}`,
110
+ data: commandData,
111
+ });
112
+ }
113
+ catch (err) {
114
+ throw `Failed to send broadcast command: ${JSON.stringify(err)}`;
115
+ }
116
+ };
117
+ sendDirectCommand = async (uri, cid, commandData, timeout, callback) => {
118
+ if (!this.apiClient)
119
+ throw new Error('No API client set');
120
+ try {
121
+ const response = await this.apiClient({
122
+ method: 'post',
123
+ url: `/mobius/directCommand/${cid}`,
124
+ data: {
125
+ uri,
126
+ commandData,
127
+ timeout,
128
+ },
129
+ });
130
+ callback(null, response.data);
131
+ }
132
+ catch (err) {
133
+ callback(err);
166
134
  }
167
- const objects = [];
168
- for (let objectUri of objectUris) {
169
- const object = await apiClient({
135
+ };
136
+ getServiceConfig = async (uri, callback) => {
137
+ if (!this.apiClient)
138
+ throw new Error('No API client set');
139
+ try {
140
+ const response = await this.apiClient({
170
141
  method: 'get',
171
- url: `/mobius/object/${objectUri}`,
142
+ url: `/mobius/service/config/${uri}`,
172
143
  });
173
- const resource = object.data.data.resources.find((r) => r.rid === rid);
174
- if (func(resource?.pv)) {
175
- objects.push(object.data.data);
144
+ callback(null, response.data);
145
+ }
146
+ catch (err) {
147
+ callback(err);
148
+ }
149
+ };
150
+ updateObject = async (uri, config, callback) => {
151
+ if (!this.apiClient)
152
+ throw new Error('No API client set');
153
+ try {
154
+ const response = await this.apiClient({
155
+ method: 'post',
156
+ url: `/mobius/object/config/${uri}`,
157
+ data: config,
158
+ });
159
+ callback(null, response.data);
160
+ }
161
+ catch (err) {
162
+ callback(err);
163
+ }
164
+ };
165
+ filterObjectsByRIDValue = async (uri, pids, rid, limit, func, callback) => {
166
+ if (!this.apiClient)
167
+ throw new Error('No API client set');
168
+ try {
169
+ const discoveries = [];
170
+ for (let pid of pids) {
171
+ discoveries.push(this.apiClient({
172
+ method: 'get',
173
+ url: `/mobius/discover/${uri}/${pid}`,
174
+ }));
175
+ }
176
+ const pidGroups = (await Promise.all(discoveries)).map((response) => ({
177
+ uri: response.data.uri,
178
+ inss: response.data.data,
179
+ }));
180
+ const objectUris = [];
181
+ for (let pidGroup of pidGroups) {
182
+ for (let ins of pidGroup.inss) {
183
+ objectUris.push(`${pidGroup.uri}/${ins}`);
184
+ }
176
185
  }
177
- if (objects.length >= limit) {
178
- return callback(null, { uri, ts: new Date().toISOString(), value: objects });
186
+ const objects = [];
187
+ for (let objectUri of objectUris) {
188
+ const object = await this.apiClient({
189
+ method: 'get',
190
+ url: `/mobius/object/${objectUri}`,
191
+ });
192
+ const resource = object.data.data.resources.find((r) => r.rid === rid);
193
+ if (func(resource?.pv)) {
194
+ objects.push(object.data.data);
195
+ }
196
+ if (objects.length >= limit) {
197
+ return callback(null, { uri, ts: new Date().toISOString(), value: objects });
198
+ }
179
199
  }
200
+ return callback(null, { uri, ts: new Date().toISOString(), value: objects });
180
201
  }
181
- return callback(null, { uri, ts: new Date().toISOString(), value: objects });
182
- }
183
- catch (err) {
184
- callback(err);
185
- }
186
- };
187
- exports.filterObjectsByRIDValue = filterObjectsByRIDValue;
188
- const getHubId = async (apiClient, callback) => {
189
- try {
190
- const response = await apiClient({
191
- method: 'get',
192
- url: `/mobius/admin/settings`,
193
- });
194
- callback(null, response.data.data.mobiusFlow.hubID.runtime);
195
- }
196
- catch (err) {
197
- callback(err);
198
- }
199
- };
200
- exports.getHubId = getHubId;
201
- const getNodeConfig = async (apiClient, uri, callback) => {
202
- try {
203
- const response = await apiClient({
204
- method: 'get',
205
- url: `/mobius/node/config/${uri}`,
206
- });
207
- callback(null, response.data);
208
- }
209
- catch (err) {
210
- callback(err);
211
- }
212
- };
213
- exports.getNodeConfig = getNodeConfig;
214
- const changeAdminPassword = async (apiClient, password, callback) => {
215
- try {
216
- const response = await apiClient({
217
- method: 'get',
218
- url: `/auth/user/admin`,
219
- });
220
- const adminUserId = response.data;
221
- await apiClient({
222
- method: 'patch',
223
- url: `/auth/user/password/${adminUserId}`,
224
- data: {
225
- password,
226
- },
227
- });
228
- callback(null, 'Ok');
229
- }
230
- catch (err) {
231
- callback(err);
232
- }
233
- };
234
- exports.changeAdminPassword = changeAdminPassword;
235
- const getNodeConfigTree = async (apiClient, hid, callback) => {
236
- try {
237
- const response = await apiClient({
238
- method: 'get',
239
- url: `/mobius/node/configtree/${hid}`,
240
- });
241
- callback(null, response.data);
242
- }
243
- catch (err) {
244
- callback(err);
245
- }
246
- };
247
- exports.getNodeConfigTree = getNodeConfigTree;
248
- const getProfileByPid = async (apiClient, hid, pid, callback) => {
249
- try {
250
- const response = await apiClient({
251
- method: 'get',
252
- url: `/mobius/profile/object/${hid}/${pid}`,
253
- });
254
- callback(null, response.data);
255
- }
256
- catch (err) {
257
- callback(err);
258
- }
259
- };
260
- exports.getProfileByPid = getProfileByPid;
202
+ catch (err) {
203
+ callback(err);
204
+ }
205
+ };
206
+ getHubId = async (callback) => {
207
+ if (!this.apiClient)
208
+ throw new Error('No API client set');
209
+ try {
210
+ const response = await this.apiClient({
211
+ method: 'get',
212
+ url: `/mobius/admin/settings`,
213
+ });
214
+ callback(null, response.data.data.mobiusFlow.hubID.runtime);
215
+ }
216
+ catch (err) {
217
+ callback(err);
218
+ }
219
+ };
220
+ getNodeConfig = async (uri, callback) => {
221
+ if (!this.apiClient)
222
+ throw new Error('No API client set');
223
+ try {
224
+ const response = await this.apiClient({
225
+ method: 'get',
226
+ url: `/mobius/node/config/${uri}`,
227
+ });
228
+ callback(null, response.data);
229
+ }
230
+ catch (err) {
231
+ callback(err);
232
+ }
233
+ };
234
+ changeAdminPassword = async (password, callback) => {
235
+ if (!this.apiClient)
236
+ throw new Error('No API client set');
237
+ try {
238
+ const response = await this.apiClient({
239
+ method: 'get',
240
+ url: `/auth/user/admin`,
241
+ });
242
+ const adminUserId = response.data;
243
+ await this.apiClient({
244
+ method: 'patch',
245
+ url: `/auth/user/password/${adminUserId}`,
246
+ data: {
247
+ password,
248
+ },
249
+ });
250
+ callback(null, 'Ok');
251
+ }
252
+ catch (err) {
253
+ callback(err);
254
+ }
255
+ };
256
+ getNodeConfigTree = async (hid, callback) => {
257
+ if (!this.apiClient)
258
+ throw new Error('No API client set');
259
+ try {
260
+ const response = await this.apiClient({
261
+ method: 'get',
262
+ url: `/mobius/node/configtree/${hid}`,
263
+ });
264
+ callback(null, response.data);
265
+ }
266
+ catch (err) {
267
+ callback(err);
268
+ }
269
+ };
270
+ getProfileByPid = async (hid, pid, callback) => {
271
+ if (!this.apiClient)
272
+ throw new Error('No API client set');
273
+ try {
274
+ const response = await this.apiClient({
275
+ method: 'get',
276
+ url: `/mobius/profile/object/${hid}/${pid}`,
277
+ });
278
+ callback(null, response.data);
279
+ }
280
+ catch (err) {
281
+ callback(err);
282
+ }
283
+ };
284
+ getAllObjectProfiles = async (hid, callback) => {
285
+ if (!this.apiClient)
286
+ throw new Error('No API client set');
287
+ try {
288
+ const response = await this.apiClient({
289
+ method: 'get',
290
+ url: `/mobius/profile/object/${hid}`,
291
+ });
292
+ callback(null, response.data);
293
+ }
294
+ catch (err) {
295
+ callback(err);
296
+ }
297
+ };
298
+ }
299
+ exports.EngineApiCalls = EngineApiCalls;
@@ -1,9 +1,22 @@
1
1
  import { AxiosInstance } from 'axios';
2
- export declare let tokens: null | {
3
- token: string;
4
- refreshToken: string;
5
- };
6
- export declare let loggedIn: boolean;
7
- export declare const getApiClient: (protocol: 'http' | 'https', host: string, username: string, password: string) => AxiosInstance;
8
- export declare const setLoggedIn: (value: boolean) => void;
9
- export declare const closeApiClient: () => void;
2
+ import { EngineWebSocket } from './engine-websocket';
3
+ import { EngineApiCalls } from './engine-api-calls';
4
+ export declare class EngineApiClient extends EngineApiCalls {
5
+ private reloginInterval;
6
+ client: AxiosInstance | null;
7
+ private refreshLoop;
8
+ tokens: null | {
9
+ token: string;
10
+ refreshToken: string;
11
+ };
12
+ loggedIn: boolean;
13
+ private username;
14
+ private password;
15
+ EngineWebSocket: EngineWebSocket;
16
+ private hostname;
17
+ private protocol;
18
+ constructor(protocol: 'http' | 'https', host: string, username: string, password: string);
19
+ private login;
20
+ private refresh;
21
+ close: () => void;
22
+ }