node-red-contrib-uos-nats 0.1.5 → 0.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.
- package/README.md +3 -3
- package/nodes/datahub-input.html +61 -24
- package/nodes/uos-config.html +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,8 +38,8 @@ The config node automatically fetches tokens via Client Credentials flow and exp
|
|
|
38
38
|
|
|
39
39
|
## DataHub Input Node
|
|
40
40
|
|
|
41
|
-
- Select the u-OS config node, then choose one of the discovered providers from the dropdown (the node queries `/datahub/v1/providers` for you).
|
|
42
|
-
- Pick the variables you need from the multi-select list. Leave it empty to receive all variables from the provider.
|
|
41
|
+
- Select the u-OS config node, then choose one of the discovered providers from the dropdown (the node queries `/datahub/v1/providers` for you). If your OAuth client lacks read-only scope, the dropdown is disabled and you can type the provider ID manually.
|
|
42
|
+
- Pick the variables you need from the multi-select list. Leave it empty to receive all variables from the provider. (When manual provider input is used the list may stay empty, because it also requires the read-only permission.)
|
|
43
43
|
- The node outputs messages with the structure:
|
|
44
44
|
```json
|
|
45
45
|
{
|
|
@@ -68,7 +68,7 @@ The config node automatically fetches tokens via Client Credentials flow and exp
|
|
|
68
68
|
## Example Flow
|
|
69
69
|
|
|
70
70
|
1. Drop a **u-OS Config** node, fill in host/port and OAuth credentials from the Control Center.
|
|
71
|
-
2. Add a **DataHub Input** node, select the config,
|
|
71
|
+
2. Add a **DataHub Input** node, select the config, choose the provider from the dropdown (or type the provider ID if the API access is restricted) and pick the variables you care about. Connect the output to a Debug node.
|
|
72
72
|
3. Add a **DataHub Output** node, leave provider ID = `nodered` and send structured JSON (e.g. from a Function node). The values instantly appear in the Data Hub under the provider `nodered`.
|
|
73
73
|
|
|
74
74
|
> Tip: Because both nodes rely on the Control Center HTTP API for metadata they inherit the same permissions as your OAuth client. Make sure the client has at least `hub.variables.readonly` for the input node and `hub.variables.provide hub.variables.readwrite` for the output node.
|
package/nodes/datahub-input.html
CHANGED
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
oneditprepare: function() {
|
|
15
15
|
const node = this;
|
|
16
16
|
const $config = $('#node-input-connection');
|
|
17
|
-
const $
|
|
17
|
+
const $providerHidden = $('#node-input-providerId');
|
|
18
|
+
const $providerSelect = $('#datahub-provider-select');
|
|
19
|
+
const $providerManual = $('#datahub-provider-manual');
|
|
18
20
|
const $providerStatus = $('#datahub-provider-status');
|
|
19
21
|
const $variablesHidden = $('#node-input-variablesText');
|
|
20
22
|
const $variables = $('#datahub-input-variables');
|
|
21
23
|
const $variablesStatus = $('#datahub-variables-status');
|
|
22
24
|
|
|
23
|
-
const initialProvider =
|
|
25
|
+
const initialProvider = $providerHidden.val() || '';
|
|
24
26
|
const initialVars = ($variablesHidden.val() || '')
|
|
25
27
|
.split(',')
|
|
26
28
|
.map((entry) => entry.trim())
|
|
@@ -68,6 +70,24 @@
|
|
|
68
70
|
const setProviderStatus = (text) => $providerStatus.text(text || '');
|
|
69
71
|
const setVariableStatus = (text) => $variablesStatus.text(text || '');
|
|
70
72
|
|
|
73
|
+
const setProviderValue = (value) => {
|
|
74
|
+
$providerHidden.val(value || '');
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getProviderValue = () => $providerHidden.val() || '';
|
|
78
|
+
|
|
79
|
+
const showManualProvider = (message) => {
|
|
80
|
+
$providerSelect.hide().prop('disabled', true);
|
|
81
|
+
$providerManual.show().prop('disabled', false);
|
|
82
|
+
$providerManual.val(getProviderValue());
|
|
83
|
+
setProviderStatus(message || 'Enter the provider ID manually.');
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const showSelectProvider = () => {
|
|
87
|
+
$providerManual.hide().prop('disabled', true);
|
|
88
|
+
$providerSelect.show().prop('disabled', false);
|
|
89
|
+
};
|
|
90
|
+
|
|
71
91
|
const loadVariables = (providerId, keepSelection = false) => {
|
|
72
92
|
const configId = $config.val();
|
|
73
93
|
if (!configId || !providerId) {
|
|
@@ -121,10 +141,10 @@
|
|
|
121
141
|
const loadProviders = () => {
|
|
122
142
|
const configId = $config.val();
|
|
123
143
|
if (!configId) {
|
|
124
|
-
$
|
|
125
|
-
$
|
|
126
|
-
$
|
|
127
|
-
|
|
144
|
+
$providerSelect.empty();
|
|
145
|
+
$providerSelect.append('<option value="">Select a u-OS config first</option>');
|
|
146
|
+
$providerSelect.prop('disabled', true);
|
|
147
|
+
showManualProvider('Pick or create a u-OS config node before selecting a provider.');
|
|
128
148
|
setVariableStatus('');
|
|
129
149
|
$variables.empty();
|
|
130
150
|
$variables.prop('disabled', true);
|
|
@@ -132,18 +152,20 @@
|
|
|
132
152
|
}
|
|
133
153
|
const seq = ++providerRequest;
|
|
134
154
|
setProviderStatus('Loading providers…');
|
|
135
|
-
$
|
|
155
|
+
$providerSelect.prop('disabled', true);
|
|
156
|
+
showSelectProvider();
|
|
136
157
|
$.getJSON(`uos/providers/${configId}`)
|
|
137
158
|
.done((payload) => {
|
|
138
159
|
if (seq !== providerRequest) {
|
|
139
160
|
return;
|
|
140
161
|
}
|
|
141
162
|
const list = normalizeProviders(payload);
|
|
142
|
-
$
|
|
163
|
+
$providerSelect.empty();
|
|
143
164
|
if (!list.length) {
|
|
144
|
-
$
|
|
165
|
+
$providerSelect.append('<option value="">No providers available</option>');
|
|
166
|
+
$providerSelect.prop('disabled', true);
|
|
145
167
|
setProviderStatus('No providers returned. Verify Data Hub access.');
|
|
146
|
-
|
|
168
|
+
showManualProvider('No providers returned. Enter the ID manually if you know it.');
|
|
147
169
|
return;
|
|
148
170
|
}
|
|
149
171
|
list.forEach((prov) => {
|
|
@@ -154,24 +176,23 @@
|
|
|
154
176
|
const option = $('<option></option>')
|
|
155
177
|
.attr('value', value)
|
|
156
178
|
.text(providerLabel(prov));
|
|
157
|
-
$
|
|
179
|
+
$providerSelect.append(option);
|
|
158
180
|
});
|
|
159
|
-
$
|
|
181
|
+
$providerSelect.prop('disabled', false);
|
|
160
182
|
if (initialProvider) {
|
|
161
|
-
$
|
|
183
|
+
$providerSelect.val(initialProvider);
|
|
162
184
|
}
|
|
163
|
-
if (!$
|
|
164
|
-
$
|
|
185
|
+
if (!$providerSelect.val()) {
|
|
186
|
+
$providerSelect.val($providerSelect.find('option:first').attr('value'));
|
|
165
187
|
}
|
|
188
|
+
const selected = $providerSelect.val();
|
|
189
|
+
setProviderValue(selected);
|
|
166
190
|
setProviderStatus('Choose the provider you want to subscribe to.');
|
|
167
|
-
loadVariables(
|
|
191
|
+
loadVariables(selected);
|
|
168
192
|
})
|
|
169
193
|
.fail((xhr) => {
|
|
170
194
|
const msg = xhr?.responseJSON?.error || xhr.statusText || 'Failed to load providers.';
|
|
171
|
-
$provider.
|
|
172
|
-
$provider.append('<option value="">Unable to load providers</option>');
|
|
173
|
-
$provider.prop('disabled', true);
|
|
174
|
-
setProviderStatus(msg);
|
|
195
|
+
showManualProvider(`Provider list failed (${msg}). Enter the provider ID manually or grant hub.variables.readonly.`);
|
|
175
196
|
});
|
|
176
197
|
};
|
|
177
198
|
|
|
@@ -179,10 +200,22 @@
|
|
|
179
200
|
syncVariablesField();
|
|
180
201
|
});
|
|
181
202
|
|
|
182
|
-
$
|
|
203
|
+
$providerSelect.on('change', () => {
|
|
204
|
+
const value = $providerSelect.val();
|
|
205
|
+
setProviderValue(value);
|
|
183
206
|
$variablesHidden.val('');
|
|
184
207
|
syncVariablesField();
|
|
185
|
-
loadVariables(
|
|
208
|
+
loadVariables(value, false);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
$providerManual.on('change keyup paste', () => {
|
|
212
|
+
const value = $providerManual.val();
|
|
213
|
+
setProviderValue(value);
|
|
214
|
+
$variablesHidden.val('');
|
|
215
|
+
syncVariablesField();
|
|
216
|
+
if (value) {
|
|
217
|
+
loadVariables(value, false);
|
|
218
|
+
}
|
|
186
219
|
});
|
|
187
220
|
|
|
188
221
|
$config.on('change', () => {
|
|
@@ -212,8 +245,12 @@
|
|
|
212
245
|
<input type="text" id="node-input-connection">
|
|
213
246
|
</div>
|
|
214
247
|
<div class="form-row">
|
|
215
|
-
<label
|
|
216
|
-
<
|
|
248
|
+
<label><i class="fa fa-id-badge"></i> Provider</label>
|
|
249
|
+
<div style="flex:1;">
|
|
250
|
+
<select id="datahub-provider-select" style="width:100%;"></select>
|
|
251
|
+
<input type="text" id="datahub-provider-manual" placeholder="provider id" style="width:100%; display:none;">
|
|
252
|
+
<input type="hidden" id="node-input-providerId">
|
|
253
|
+
</div>
|
|
217
254
|
</div>
|
|
218
255
|
<div class="form-row">
|
|
219
256
|
<label></label>
|
package/nodes/uos-config.html
CHANGED
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
<li><strong>Host / Port</strong> – IP and NATS port of the controller (default <code>127.0.0.1:49360</code>).</li>
|
|
103
103
|
<li><strong>Client Name</strong> – Friendly identifier used in NATS connection logs.</li>
|
|
104
104
|
<li><strong>Client ID / Secret</strong> – OAuth credentials from your u-OS Control Center client.</li>
|
|
105
|
-
<li><strong>Token URL</strong> – Optional; defaults to <code>https://<Host>/oauth2/token</code> if left empty.</li>
|
|
106
105
|
<li><strong>Scope</strong> – Space separated scopes; e.g. <code>hub.variables.provide hub.variables.readwrite</code>.</li>
|
|
106
|
+
<li><strong>Granted scopes</strong> – Click <em>Refresh</em> to show what the token endpoint actually returns for this client.</li>
|
|
107
107
|
</ul>
|
|
108
108
|
</script>
|