node-red-contrib-mobius-flow-base 2.5.91 → 3.0.0-beta.13
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/.github/ISSUE_TEMPLATE/bug_report.md +16 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +16 -0
- package/.github/ISSUE_TEMPLATE/general.md +7 -0
- package/.github/workflows/build_publish.yml +80 -0
- package/README.md +4 -10
- package/dist/engine-api-calls.d.ts +19 -0
- package/dist/engine-api-calls.js +235 -0
- package/dist/engine-api-client.d.ts +8 -0
- package/dist/engine-api-client.js +106 -0
- package/dist/engine-websocket.d.ts +60 -0
- package/dist/engine-websocket.js +264 -0
- package/dist/node-red-ui-funcs.js +180 -0
- package/dist/nodes/common/mobsearch.js +602 -0
- package/dist/nodes/mobius-change-admin-password.d.ts +26 -0
- package/dist/nodes/mobius-change-admin-password.html +98 -0
- package/dist/nodes/mobius-change-admin-password.js +87 -0
- package/dist/nodes/mobius-clear-resource.html +37 -12
- package/dist/nodes/mobius-clear-resource.js +17 -13
- package/dist/nodes/mobius-connection-interface.d.ts +45 -0
- package/dist/nodes/mobius-connection-interface.js +2 -0
- package/dist/nodes/mobius-connection.html +30 -8
- package/dist/nodes/mobius-connection.js +216 -85
- package/dist/nodes/mobius-discover-object-list.html +185 -126
- package/dist/nodes/mobius-discover-object-list.js +24 -5
- package/dist/nodes/mobius-discover.js +7 -7
- package/dist/nodes/mobius-filter-by-rid-value.html +62 -42
- package/dist/nodes/mobius-filter-by-rid-value.js +38 -31
- package/dist/nodes/mobius-flow-inject.html +32 -2
- package/dist/nodes/mobius-get-multi-object.html +39 -5
- package/dist/nodes/mobius-get-multi-resource.html +37 -4
- package/dist/nodes/mobius-get-multi-resource.js +13 -12
- package/dist/nodes/mobius-get-object.html +39 -11
- package/dist/nodes/mobius-get-object.js +12 -9
- package/dist/nodes/mobius-get-resource.html +41 -12
- package/dist/nodes/mobius-get-resource.js +17 -12
- package/dist/nodes/mobius-object-cov.html +40 -11
- package/dist/nodes/mobius-object-cov.js +9 -6
- package/dist/nodes/mobius-resource-cov.html +37 -11
- package/dist/nodes/mobius-resource-cov.js +5 -5
- package/dist/nodes/mobius-set-multi-resource.html +39 -12
- package/dist/nodes/mobius-set-multi-resource.js +9 -11
- package/dist/nodes/mobius-set-resource.html +38 -11
- package/package.json +15 -8
- package/dist/nodes/node-red-ui-discover-devices.js +0 -103
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: 🐞 Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: '🐞 [Bug]: '
|
|
5
|
+
labels: 'bug'
|
|
6
|
+
assignees: ''
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
**Remember to include**
|
|
10
|
+
|
|
11
|
+
- Customer
|
|
12
|
+
- Software version
|
|
13
|
+
- Where it was running (Cloud, balena, customer's own infra etc)
|
|
14
|
+
- A good description of the bug and how to reproduce it
|
|
15
|
+
- An estimate of the time to fix
|
|
16
|
+
- Any other repos that may be affected
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ✨ Feature request
|
|
3
|
+
about: Suggest an idea for this project
|
|
4
|
+
title: '✨ [Feature]: '
|
|
5
|
+
labels: 'enhancement'
|
|
6
|
+
assignees: ''
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
**Remember to include**
|
|
10
|
+
|
|
11
|
+
- Customer
|
|
12
|
+
- The reason for the new feature
|
|
13
|
+
- A good description of the new feature
|
|
14
|
+
- Any alternatives you have considered
|
|
15
|
+
- An estimate of the time to fix
|
|
16
|
+
- Any other repos that may be affected
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
name: Build and Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- v*.*.*
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
build-and-publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v3
|
|
14
|
+
|
|
15
|
+
- name: Get tag
|
|
16
|
+
id: source_tag
|
|
17
|
+
run: |
|
|
18
|
+
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
|
19
|
+
|
|
20
|
+
- name: Get package version
|
|
21
|
+
id: source_ver
|
|
22
|
+
run: |
|
|
23
|
+
echo "SOURCE_VER=v$(grep version ./package.json | sed -n 's/^.*"\([0-9][^"]*\)".*$/\1/p')" >> $GITHUB_OUTPUT
|
|
24
|
+
|
|
25
|
+
- name: Do tag and version match?
|
|
26
|
+
if: steps.source_tag.outputs.SOURCE_TAG != steps.source_ver.outputs.SOURCE_VER
|
|
27
|
+
run: |
|
|
28
|
+
echo ${{ steps.source_tag.outputs.SOURCE_TAG }}
|
|
29
|
+
echo ${{ steps.source_ver.outputs.SOURCE_VER }}
|
|
30
|
+
echo "::error Tag does not match version"
|
|
31
|
+
exit -1
|
|
32
|
+
|
|
33
|
+
- name: Setup node
|
|
34
|
+
uses: actions/setup-node@v3
|
|
35
|
+
with:
|
|
36
|
+
node-version: '16.x'
|
|
37
|
+
registry-url: 'https://registry.npmjs.org'
|
|
38
|
+
always-auth: true
|
|
39
|
+
|
|
40
|
+
- name: Build
|
|
41
|
+
run: |
|
|
42
|
+
npm install -g yarn
|
|
43
|
+
yarn install
|
|
44
|
+
tsc && mkdir -p dist/nodes
|
|
45
|
+
cp src/nodes/*.js dist/nodes/
|
|
46
|
+
cp src/nodes/*.html dist/nodes/
|
|
47
|
+
cp -r src/nodes/icons dist/nodes/
|
|
48
|
+
mkdir -p dist/nodes/common
|
|
49
|
+
cp src/mobsearch.js dist/nodes/common/
|
|
50
|
+
cp src/node-red-ui-funcs.js dist/
|
|
51
|
+
env:
|
|
52
|
+
GH_PKG_READ_TOKEN: ${{ secrets.GH_PKG_READ_TOKEN }}
|
|
53
|
+
|
|
54
|
+
- name: Publish package
|
|
55
|
+
run: |
|
|
56
|
+
npm publish
|
|
57
|
+
env:
|
|
58
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_WRITE_TOKEN }}
|
|
59
|
+
|
|
60
|
+
- name: Create release
|
|
61
|
+
env:
|
|
62
|
+
RELEASE_TYPE: ${{ contains(steps.source_ver.outputs.SOURCE_VER, '-') }}
|
|
63
|
+
RELEASE_TAG: ${{ steps.source_ver.outputs.SOURCE_VER }}
|
|
64
|
+
uses: actions/github-script@v6
|
|
65
|
+
with:
|
|
66
|
+
github-token: ${{ secrets.MOBIUS_ACTION_TOKEN }}
|
|
67
|
+
script: |
|
|
68
|
+
try {
|
|
69
|
+
await github.rest.repos.createRelease({
|
|
70
|
+
draft: false,
|
|
71
|
+
generate_release_notes: true,
|
|
72
|
+
name: process.env.RELEASE_TAG,
|
|
73
|
+
owner: context.repo.owner,
|
|
74
|
+
prerelease: process.env.RELEASE_TYPE === 'true',
|
|
75
|
+
repo: context.repo.repo,
|
|
76
|
+
tag_name: process.env.RELEASE_TAG,
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
core.setFailed(error.message);
|
|
80
|
+
}
|
package/README.md
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
# node-red-contrib-mobius-flow-base
|
|
2
|
-

|
|
3
2
|
|
|
4
|
-
Copyright 2016 [
|
|
3
|
+
Copyright 2016 [iaconnects](http://www.iaconnects.co.uk).
|
|
5
4
|
|
|
6
|
-
[Node-RED](http://nodered.org) nodes to interact with
|
|
5
|
+
[Node-RED](http://nodered.org) nodes to interact with MOBiUSFlow.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
Run the following command in the root directory of your Node-RED install:
|
|
10
|
-
|
|
11
|
-
```npm install node-red-contrib-mobius-flow-base```
|
|
12
|
-
|
|
13
|
-
This module currently requires access to Interior Automation's private NPM repository. This will be made public in the future once MOBiUS Flow is ready for public release.
|
|
7
|
+
This module currently requires access to the iaconnects private NPM repository.
|
|
14
8
|
|
|
15
9
|
## Nodes
|
|
16
10
|
|
|
@@ -33,4 +27,4 @@ Clears the specified priority of resource.
|
|
|
33
27
|
Subscribe to change of value events for an object
|
|
34
28
|
|
|
35
29
|
### Resource COV Node
|
|
36
|
-
Subscribe to change of value events for a resource
|
|
30
|
+
Subscribe to change of value events for a resource
|
|
@@ -0,0 +1,19 @@
|
|
|
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>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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: 'post',
|
|
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
|
+
console.log(uri);
|
|
123
|
+
try {
|
|
124
|
+
const response = await apiClient({
|
|
125
|
+
method: 'get',
|
|
126
|
+
url: `/mobius/service/config/${uri}`,
|
|
127
|
+
});
|
|
128
|
+
callback(null, response.data);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
callback(err);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
exports.getServiceConfig = getServiceConfig;
|
|
135
|
+
const updateObject = async (apiClient, uri, config, callback) => {
|
|
136
|
+
try {
|
|
137
|
+
const response = await apiClient({
|
|
138
|
+
method: 'post',
|
|
139
|
+
url: `/mobius/object/config/${uri}`,
|
|
140
|
+
data: config,
|
|
141
|
+
});
|
|
142
|
+
callback(null, response.data);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
callback(err);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
exports.updateObject = updateObject;
|
|
149
|
+
const filterObjectsByRIDValue = async (apiClient, uri, pids, rid, limit, func, callback) => {
|
|
150
|
+
try {
|
|
151
|
+
const discoveries = [];
|
|
152
|
+
for (let pid of pids) {
|
|
153
|
+
discoveries.push(apiClient({
|
|
154
|
+
method: 'get',
|
|
155
|
+
url: `/mobius/discover/${uri}/${pid}`,
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
const pidGroups = (await Promise.all(discoveries)).map((response) => ({
|
|
159
|
+
uri: response.data.uri,
|
|
160
|
+
inss: response.data.data,
|
|
161
|
+
}));
|
|
162
|
+
const objectUris = [];
|
|
163
|
+
for (let pidGroup of pidGroups) {
|
|
164
|
+
for (let ins of pidGroup.inss) {
|
|
165
|
+
objectUris.push(`${pidGroup.uri}/${ins}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const objects = [];
|
|
169
|
+
for (let objectUri of objectUris) {
|
|
170
|
+
const object = await apiClient({
|
|
171
|
+
method: 'get',
|
|
172
|
+
url: `/mobius/object/${objectUri}`,
|
|
173
|
+
});
|
|
174
|
+
const resource = object.data.data.resources.find((r) => r.rid === rid);
|
|
175
|
+
if (func(resource?.pv)) {
|
|
176
|
+
objects.push(object.data.data);
|
|
177
|
+
}
|
|
178
|
+
if (objects.length >= limit) {
|
|
179
|
+
return callback(null, { uri, ts: new Date().toISOString(), value: objects });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return callback(null, { uri, ts: new Date().toISOString(), value: objects });
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
callback(err);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
exports.filterObjectsByRIDValue = filterObjectsByRIDValue;
|
|
189
|
+
const getHubId = async (apiClient, callback) => {
|
|
190
|
+
try {
|
|
191
|
+
const response = await apiClient({
|
|
192
|
+
method: 'get',
|
|
193
|
+
url: `/mobius/admin/settings`,
|
|
194
|
+
});
|
|
195
|
+
callback(null, response.data.data.mobiusFlow.hubID.runtime);
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
callback(err);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
exports.getHubId = getHubId;
|
|
202
|
+
const getNodeConfig = async (apiClient, uri, callback) => {
|
|
203
|
+
try {
|
|
204
|
+
const response = await apiClient({
|
|
205
|
+
method: 'get',
|
|
206
|
+
url: `/mobius/node/config/${uri}`,
|
|
207
|
+
});
|
|
208
|
+
callback(null, response.data);
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
callback(err);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
exports.getNodeConfig = getNodeConfig;
|
|
215
|
+
const changeAdminPassword = async (apiClient, password, callback) => {
|
|
216
|
+
try {
|
|
217
|
+
const response = await apiClient({
|
|
218
|
+
method: 'get',
|
|
219
|
+
url: `/auth/user/admin`,
|
|
220
|
+
});
|
|
221
|
+
const adminUserId = response.data;
|
|
222
|
+
await apiClient({
|
|
223
|
+
method: 'patch',
|
|
224
|
+
url: `/auth/user/password/${adminUserId}`,
|
|
225
|
+
data: {
|
|
226
|
+
password,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
callback(null, 'Ok');
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
callback(err);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
exports.changeAdminPassword = changeAdminPassword;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare let tokens: null | {
|
|
2
|
+
token: string;
|
|
3
|
+
refreshToken: string;
|
|
4
|
+
};
|
|
5
|
+
export declare let loggedIn: boolean;
|
|
6
|
+
export declare const getApiClient: (protocol: 'http' | 'https', host: string, port: number, username: string, password: string) => import("axios").AxiosInstance;
|
|
7
|
+
export declare const setLoggedIn: (value: boolean) => void;
|
|
8
|
+
export declare const closeApiClient: () => void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.closeApiClient = exports.setLoggedIn = exports.getApiClient = exports.loggedIn = exports.tokens = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const engine_websocket_1 = require("./engine-websocket");
|
|
9
|
+
exports.tokens = null;
|
|
10
|
+
exports.loggedIn = false;
|
|
11
|
+
let reloginInterval = null;
|
|
12
|
+
const getApiClient = (protocol, host, port, username, password) => {
|
|
13
|
+
(0, engine_websocket_1.setWebSocketConnectParams)(host, port, protocol);
|
|
14
|
+
//const baseURL = `http://localhost:8443/api/v1`;
|
|
15
|
+
const baseURL = `${protocol}://${host}:${port}/api/v1`;
|
|
16
|
+
const client = axios_1.default.create({
|
|
17
|
+
baseURL: baseURL,
|
|
18
|
+
headers: {
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
reloginInterval = setInterval(() => {
|
|
23
|
+
if (!exports.loggedIn) {
|
|
24
|
+
login();
|
|
25
|
+
}
|
|
26
|
+
}, 30000);
|
|
27
|
+
// Add auth headers to all axios calls
|
|
28
|
+
client.interceptors.request.use((config) => {
|
|
29
|
+
if (!config.url?.endsWith('/auth/login')) {
|
|
30
|
+
if (exports.tokens && config.headers) {
|
|
31
|
+
config.headers['Authorization'] = `Bearer ${exports.tokens.token}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return config;
|
|
35
|
+
}, (error) => {
|
|
36
|
+
Promise.reject(error);
|
|
37
|
+
});
|
|
38
|
+
const login = async () => {
|
|
39
|
+
console.log('Attempting Mobius Engine API Login');
|
|
40
|
+
try {
|
|
41
|
+
const response = await client({
|
|
42
|
+
method: 'post',
|
|
43
|
+
url: '/auth/login',
|
|
44
|
+
data: {
|
|
45
|
+
username,
|
|
46
|
+
password,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
exports.tokens = response.data;
|
|
50
|
+
exports.loggedIn = true;
|
|
51
|
+
console.log('Logged in to Mobius Engine API');
|
|
52
|
+
(0, engine_websocket_1.connectToWebSocket)();
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
exports.loggedIn = false;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
login();
|
|
59
|
+
const refresh = async () => {
|
|
60
|
+
if (!exports.tokens) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const response = await client({
|
|
65
|
+
method: 'post',
|
|
66
|
+
url: '/auth/refresh',
|
|
67
|
+
data: {
|
|
68
|
+
refreshToken: exports.tokens.refreshToken,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
exports.tokens = response.data;
|
|
72
|
+
exports.loggedIn = true;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
exports.loggedIn = false;
|
|
76
|
+
login();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
setInterval(refresh, 1000 * 60 * 5);
|
|
80
|
+
client.interceptors.response.use((res) => {
|
|
81
|
+
return res;
|
|
82
|
+
}, async (error) => {
|
|
83
|
+
if (!error.response) {
|
|
84
|
+
// notify
|
|
85
|
+
}
|
|
86
|
+
if (!error.config.url?.endsWith('/auth/login')) {
|
|
87
|
+
console.log(`Logged Out: ${JSON.stringify(error.response)}`);
|
|
88
|
+
exports.loggedIn = false;
|
|
89
|
+
exports.tokens = null;
|
|
90
|
+
login();
|
|
91
|
+
}
|
|
92
|
+
return Promise.reject(error);
|
|
93
|
+
});
|
|
94
|
+
return client;
|
|
95
|
+
};
|
|
96
|
+
exports.getApiClient = getApiClient;
|
|
97
|
+
const setLoggedIn = (value) => {
|
|
98
|
+
exports.loggedIn = value;
|
|
99
|
+
};
|
|
100
|
+
exports.setLoggedIn = setLoggedIn;
|
|
101
|
+
const closeApiClient = () => {
|
|
102
|
+
if (reloginInterval) {
|
|
103
|
+
clearInterval(reloginInterval);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
exports.closeApiClient = closeApiClient;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
type WebSocketTopics = 'authorize' | 'subscribe' | 'unsubscribe' | 'connected' | 'authorized' | 'object-cov' | 'resource-cov' | 'service-status' | 'broadcast-command' | 'error' | 'ping' | 'pong';
|
|
2
|
+
type Events = 'connected' | 'disconnected';
|
|
3
|
+
export declare const setWebSocketConnectParams: (hostname: string, port: number, protocol: 'http' | 'https') => void;
|
|
4
|
+
export declare const on: (eventName: Events, callback: Function) => void;
|
|
5
|
+
export declare function registerCallback(topic: WebSocketTopics, callback: Function): void;
|
|
6
|
+
export declare function clearAllCallbacks(): void;
|
|
7
|
+
export declare const killWebSocket: () => void;
|
|
8
|
+
/**
|
|
9
|
+
* Connect to the Mobius WebSocket API
|
|
10
|
+
* This method will connect to the Mobius WebSocket API and authenticate with the API token
|
|
11
|
+
*/
|
|
12
|
+
export declare const connectToWebSocket: () => void;
|
|
13
|
+
/**
|
|
14
|
+
* Disconnect from the Mobius WebSocket API - Using this will not stop socket from attempting to reconnect
|
|
15
|
+
* This method will close the connection to the Mobius WebSocket API
|
|
16
|
+
*/
|
|
17
|
+
export declare const disconnectFromWebSocket: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to an object's COV
|
|
20
|
+
* This method will subscribe to an object's COV
|
|
21
|
+
* @param uri The URI of the object to subscribe to
|
|
22
|
+
* @param listener The listener to dispatch the event to
|
|
23
|
+
*/
|
|
24
|
+
export declare const subscribeToObjectCOV: (uri: string) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Unsubscribe from an object's COV
|
|
27
|
+
* This method will unsubscribe from an object's COV
|
|
28
|
+
* @param uri The URI of the object to unsubscribe from
|
|
29
|
+
* @param listener The listener to remove
|
|
30
|
+
*/
|
|
31
|
+
export declare const unsubscribeToObjectCOV: (uri: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to an object's COV
|
|
34
|
+
* This method will subscribe to an object's COV
|
|
35
|
+
* @param uri The URI of the object to subscribe to
|
|
36
|
+
* @param listener The listener to dispatch the event to
|
|
37
|
+
*/
|
|
38
|
+
export declare const subscribeToResourceCOV: (uri: string) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Unsubscribe from an object's COV
|
|
41
|
+
* This method will unsubscribe from an object's COV
|
|
42
|
+
* @param uri The URI of the object to unsubscribe from
|
|
43
|
+
* @param listener The listener to remove
|
|
44
|
+
*/
|
|
45
|
+
export declare const unsubscribeToResourceCOV: (uri: string) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Subscribe to a BCMD event
|
|
48
|
+
* This method will subscribe to a BCMD event
|
|
49
|
+
* @param uri The URI of the object to subscribe to
|
|
50
|
+
* @param listener The listener to dispatch the event to
|
|
51
|
+
*/
|
|
52
|
+
export declare const subscribeToBCMD: (uri: string) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Unsubscribe from a BCMD event
|
|
55
|
+
* This method will unsubscribe from a BCMD event
|
|
56
|
+
* @param uri The URI of the object to unsubscribe from
|
|
57
|
+
* @param listener The listener to remove
|
|
58
|
+
*/
|
|
59
|
+
export declare const unsubscribeToBCMD: (uri: string) => void;
|
|
60
|
+
export {};
|