node-red-contrib-uos-nats 1.3.71 → 1.4.0
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/lib/payloads.js +15 -12
- package/nodes/datahub-input.js +11 -3
- package/nodes/icons/uos-api.svg +4 -0
- package/nodes/uos-config.html +18 -2
- package/nodes/uos-config.js +26 -1
- package/nodes/uos-http.html +150 -0
- package/nodes/uos-http.js +151 -0
- package/package.json +3 -2
package/lib/payloads.js
CHANGED
|
@@ -222,6 +222,13 @@ export function decodeVariableList(list, whitelistIds = null) {
|
|
|
222
222
|
if (!list)
|
|
223
223
|
return [];
|
|
224
224
|
const result = [];
|
|
225
|
+
|
|
226
|
+
// Optimization: Reuse holders to reduce GC pressure
|
|
227
|
+
const holderInt64 = new VariableValueInt64();
|
|
228
|
+
const holderFloat64 = new VariableValueFloat64();
|
|
229
|
+
const holderBoolean = new VariableValueBoolean();
|
|
230
|
+
const holderString = new VariableValueString();
|
|
231
|
+
|
|
225
232
|
for (let i = 0; i < list.itemsLength(); i += 1) {
|
|
226
233
|
const item = list.items(i);
|
|
227
234
|
if (!item)
|
|
@@ -236,27 +243,23 @@ export function decodeVariableList(list, whitelistIds = null) {
|
|
|
236
243
|
let decoded;
|
|
237
244
|
switch (item.valueType()) {
|
|
238
245
|
case VariableValue.Int64: {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
decoded = Number(holder.value());
|
|
246
|
+
item.value(holderInt64);
|
|
247
|
+
decoded = Number(holderInt64.value());
|
|
242
248
|
break;
|
|
243
249
|
}
|
|
244
250
|
case VariableValue.Float64: {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
decoded = holder.value();
|
|
251
|
+
item.value(holderFloat64);
|
|
252
|
+
decoded = holderFloat64.value();
|
|
248
253
|
break;
|
|
249
254
|
}
|
|
250
255
|
case VariableValue.Boolean: {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
decoded = holder.value();
|
|
256
|
+
item.value(holderBoolean);
|
|
257
|
+
decoded = holderBoolean.value();
|
|
254
258
|
break;
|
|
255
259
|
}
|
|
256
260
|
case VariableValue.String: {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
decoded = holder.value();
|
|
261
|
+
item.value(holderString);
|
|
262
|
+
decoded = holderString.value();
|
|
260
263
|
break;
|
|
261
264
|
}
|
|
262
265
|
default:
|
package/nodes/datahub-input.js
CHANGED
|
@@ -74,12 +74,14 @@ module.exports = function (RED) {
|
|
|
74
74
|
// Pre-populate raw map with manual definitions
|
|
75
75
|
this.manualDefs.forEach(d => defMap.set(d.id, { ...d, type: 'MANUAL', dataType: 'UNKNOWN', access: 'READ_ONLY' }));
|
|
76
76
|
|
|
77
|
+
// Optimization: Use Set for O(1) lookups
|
|
78
|
+
const variableSet = new Set(this.variables.map(v => normalizeKey(v)));
|
|
79
|
+
|
|
77
80
|
const shouldInclude = (key) => {
|
|
78
|
-
if (
|
|
81
|
+
if (variableSet.size === 0) {
|
|
79
82
|
return true;
|
|
80
83
|
}
|
|
81
|
-
|
|
82
|
-
return this.variables.includes(needle);
|
|
84
|
+
return variableSet.has(normalizeKey(key));
|
|
83
85
|
};
|
|
84
86
|
|
|
85
87
|
const processStates = (states) => {
|
|
@@ -101,6 +103,12 @@ module.exports = function (RED) {
|
|
|
101
103
|
this.warnOnce('Filtering active but Variable Definitions failed to load (API Error). Names cannot be resolved. Try using "Name:ID" format to manually map variables.');
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
// Optimization: redundant check removed if whitelist is active, but keeping as safeguard
|
|
107
|
+
// If we used a whitelist, we know we only have relevant IDs.
|
|
108
|
+
// However, keeping strict check is safer for "Name-based" consistency.
|
|
109
|
+
// But we can optimize: if mapped.length is same as whitelist size, we are good?
|
|
110
|
+
// Actually, let's keep it simple: Filter-on-Decode handles the heavy lifting (byte level).
|
|
111
|
+
// This JS filter is now cheap (O(1) lookup). We'll keep it for correctness in case of aliasing/manual IDs.
|
|
104
112
|
return mapped.filter((state) => shouldInclude(state.key));
|
|
105
113
|
};
|
|
106
114
|
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60" width="60" height="60">
|
|
2
|
+
<rect width="60" height="60" rx="6" ry="6" fill="#a6bbcf" />
|
|
3
|
+
<text x="50%" y="55%" dominant-baseline="middle" text-anchor="middle" font-family="sans-serif" font-weight="bold" font-size="24" fill="white">API</text>
|
|
4
|
+
</svg>
|
package/nodes/uos-config.html
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
RED.nodes.registerType('uos-config', {
|
|
4
4
|
category: 'config',
|
|
5
5
|
defaults: {
|
|
6
|
+
name: { value: "" },
|
|
6
7
|
host: { value: '127.0.0.1', required: true },
|
|
7
|
-
port: { value:
|
|
8
|
-
clientName: { value: ''
|
|
8
|
+
port: { value: 4222, required: true, validate: RED.validators.number() },
|
|
9
|
+
clientName: { value: 'nodered' },
|
|
9
10
|
scope: { value: FIXED_SCOPE, required: true },
|
|
11
|
+
enableSystemAdmin: { value: false },
|
|
12
|
+
customScopes: { value: "" }
|
|
10
13
|
},
|
|
11
14
|
credentials: {
|
|
12
15
|
clientId: { type: 'text', required: true },
|
|
@@ -141,6 +144,19 @@
|
|
|
141
144
|
<label for="node-config-input-clientSecret"><i class="fa fa-key"></i> Client Secret</label>
|
|
142
145
|
<input type="password" id="node-config-input-clientSecret">
|
|
143
146
|
</div>
|
|
147
|
+
|
|
148
|
+
<!-- Advanced Scopes Section -->
|
|
149
|
+
<div class="form-row">
|
|
150
|
+
<label for="node-config-input-enableSystemAdmin" style="width: auto;"><i class="fa fa-lock"></i> Enable System Admin Access</label>
|
|
151
|
+
<input type="checkbox" id="node-config-input-enableSystemAdmin" style="display: inline-block; width: auto; vertical-align: top;">
|
|
152
|
+
<div class="form-tips" style="margin-top: 5px;">
|
|
153
|
+
Grants permission to manage System, Network, Security, Logs, and Recovery.
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
<div class="form-row">
|
|
157
|
+
<label for="node-config-input-customScopes"><i class="fa fa-plus-circle"></i> Custom Scopes</label>
|
|
158
|
+
<input type="text" id="node-config-input-customScopes" placeholder="space-separated scopes">
|
|
159
|
+
</div>
|
|
144
160
|
<input type="hidden" id="node-config-input-scope">
|
|
145
161
|
<div class="form-row">
|
|
146
162
|
<label><i class="fa fa-list"></i> Scope</label>
|
package/nodes/uos-config.js
CHANGED
|
@@ -49,7 +49,32 @@ module.exports = function (RED) {
|
|
|
49
49
|
this.warn("Illegal Client Name 'u_os_sbm' detected! It conflicts with the system provider. Forcing rename to 'nodered'.");
|
|
50
50
|
this.clientName = 'nodered';
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
|
|
53
|
+
// Dynamic Scope Generation
|
|
54
|
+
this.enableSystemAdmin = config.enableSystemAdmin || false;
|
|
55
|
+
this.customScopes = config.customScopes || "";
|
|
56
|
+
|
|
57
|
+
const baseScopes = DEFAULT_SCOPE.split(' ');
|
|
58
|
+
const adminScopes = [
|
|
59
|
+
'u-os-adm.logging.readonly',
|
|
60
|
+
'u-os-adm.network.readwrite',
|
|
61
|
+
'u-os-adm.recovery.readwrite',
|
|
62
|
+
'u-os-adm.security.readwrite',
|
|
63
|
+
'u-os-adm.system.readwrite'
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
let finalScopes = [...baseScopes];
|
|
67
|
+
if (this.enableSystemAdmin) {
|
|
68
|
+
finalScopes.push(...adminScopes);
|
|
69
|
+
}
|
|
70
|
+
if (this.customScopes.trim()) {
|
|
71
|
+
const extras = this.customScopes.split(' ').map(s => s.trim()).filter(s => s);
|
|
72
|
+
finalScopes.push(...extras);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Deduplicate
|
|
76
|
+
this.scope = [...new Set(finalScopes)].join(' ');
|
|
77
|
+
|
|
53
78
|
this.clientId = this.credentials ? this.credentials.clientId : null;
|
|
54
79
|
this.clientSecret = this.credentials ? this.credentials.clientSecret : null;
|
|
55
80
|
this.tokenInfo = null;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('uos-http', {
|
|
3
|
+
category: 'Web Services',
|
|
4
|
+
color: '#a6bbcf',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: "" },
|
|
7
|
+
uosConfig: { type: "uos-config", required: true },
|
|
8
|
+
mode: { value: "datahub" },
|
|
9
|
+
|
|
10
|
+
// DataHub
|
|
11
|
+
dhAction: { value: "read" },
|
|
12
|
+
dhProvider: { value: "" },
|
|
13
|
+
dhVariable: { value: "" },
|
|
14
|
+
|
|
15
|
+
// System
|
|
16
|
+
sysCategory: { value: "system" },
|
|
17
|
+
sysAction: { value: "info" }
|
|
18
|
+
},
|
|
19
|
+
inputs: 1,
|
|
20
|
+
outputs: 1,
|
|
21
|
+
icon: "uos-api.svg",
|
|
22
|
+
label: function () {
|
|
23
|
+
return this.name || "u-OS API";
|
|
24
|
+
},
|
|
25
|
+
oneditprepare: function () {
|
|
26
|
+
$("#node-input-mode").on("change", function () {
|
|
27
|
+
var mode = $(this).val();
|
|
28
|
+
if (mode === "datahub") {
|
|
29
|
+
$(".uos-mode-datahub").show();
|
|
30
|
+
$(".uos-mode-system").hide();
|
|
31
|
+
} else {
|
|
32
|
+
$(".uos-mode-datahub").hide();
|
|
33
|
+
$(".uos-mode-system").show();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// System Action Dynamic Options
|
|
38
|
+
const sysActions = {
|
|
39
|
+
system: [
|
|
40
|
+
{ val: "info", label: "Get System Info" },
|
|
41
|
+
{ val: "nameplate", label: "Get Nameplate" },
|
|
42
|
+
{ val: "disks", label: "Get Disks" },
|
|
43
|
+
{ val: "reboot", label: "Reboot System (POST)" }
|
|
44
|
+
],
|
|
45
|
+
network: [
|
|
46
|
+
{ val: "get_state", label: "Get State" },
|
|
47
|
+
{ val: "get_config", label: "Get Config" },
|
|
48
|
+
{ val: "set_config", label: "Set Config (PUT)" },
|
|
49
|
+
{ val: "update_config", label: "Update Config (PATCH)" }
|
|
50
|
+
],
|
|
51
|
+
logging: [
|
|
52
|
+
{ val: "entries", label: "Get Entries" },
|
|
53
|
+
{ val: "sources", label: "Get Sources" },
|
|
54
|
+
{ val: "create_report", label: "Create Report" }
|
|
55
|
+
],
|
|
56
|
+
security: [
|
|
57
|
+
{ val: "get_config", label: "Get Config" },
|
|
58
|
+
{ val: "set_config", label: "Set Config (PUT)" }
|
|
59
|
+
],
|
|
60
|
+
recovery: [
|
|
61
|
+
{ val: "factory_reset", label: "Factory Reset" }
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
$("#node-input-sysCategory").on("change", function () {
|
|
66
|
+
var cat = $(this).val();
|
|
67
|
+
var actions = sysActions[cat] || [];
|
|
68
|
+
var select = $("#node-input-sysAction");
|
|
69
|
+
select.empty();
|
|
70
|
+
actions.forEach(function (a) {
|
|
71
|
+
select.append($("<option></option>").attr("value", a.val).text(a.label));
|
|
72
|
+
});
|
|
73
|
+
// Restore previous value if feasible, otherwise select first
|
|
74
|
+
// (Logic simplified here)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<script type="text/html" data-template-name="uos-http">
|
|
81
|
+
<div class="form-row">
|
|
82
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
83
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
84
|
+
</div>
|
|
85
|
+
<div class="form-row">
|
|
86
|
+
<label for="node-input-uosConfig"><i class="fa fa-cog"></i> u-OS Config</label>
|
|
87
|
+
<input type="text" id="node-input-uosConfig">
|
|
88
|
+
</div>
|
|
89
|
+
<div class="form-row">
|
|
90
|
+
<label for="node-input-mode"><i class="fa fa-sliders"></i> Mode</label>
|
|
91
|
+
<select id="node-input-mode">
|
|
92
|
+
<option value="datahub">DataHub Variables</option>
|
|
93
|
+
<option value="system">System Administration</option>
|
|
94
|
+
</select>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<!-- DataHub Mode -->
|
|
98
|
+
<div class="uos-mode-datahub">
|
|
99
|
+
<div class="form-row">
|
|
100
|
+
<label for="node-input-dhAction"><i class="fa fa-play"></i> Action</label>
|
|
101
|
+
<select id="node-input-dhAction">
|
|
102
|
+
<option value="read">Read Variable</option>
|
|
103
|
+
<option value="write">Write Variable</option>
|
|
104
|
+
<option value="list_providers">List Providers</option>
|
|
105
|
+
<option value="list_variables">List Variables</option>
|
|
106
|
+
</select>
|
|
107
|
+
</div>
|
|
108
|
+
<div class="form-row">
|
|
109
|
+
<label for="node-input-dhProvider"><i class="fa fa-server"></i> Provider</label>
|
|
110
|
+
<input type="text" id="node-input-dhProvider" placeholder="e.g. u_os_sbm">
|
|
111
|
+
</div>
|
|
112
|
+
<div class="form-row">
|
|
113
|
+
<label for="node-input-dhVariable"><i class="fa fa-tag"></i> Variable</label>
|
|
114
|
+
<input type="text" id="node-input-dhVariable" placeholder="e.g. digital_nameplate.software_version">
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<!-- System Mode -->
|
|
119
|
+
<div class="uos-mode-system" style="display:none;">
|
|
120
|
+
<div class="form-row">
|
|
121
|
+
<label for="node-input-sysCategory"><i class="fa fa-folder"></i> Category</label>
|
|
122
|
+
<select id="node-input-sysCategory">
|
|
123
|
+
<option value="system">System</option>
|
|
124
|
+
<option value="network">Network</option>
|
|
125
|
+
<option value="logging">Logging</option>
|
|
126
|
+
<option value="security">Security</option>
|
|
127
|
+
<option value="recovery">Recovery</option>
|
|
128
|
+
</select>
|
|
129
|
+
</div>
|
|
130
|
+
<div class="form-row">
|
|
131
|
+
<label for="node-input-sysAction"><i class="fa fa-bolt"></i> Action</label>
|
|
132
|
+
<select id="node-input-sysAction">
|
|
133
|
+
<!-- Populated dynamically -->
|
|
134
|
+
</select>
|
|
135
|
+
</div>
|
|
136
|
+
</div>
|
|
137
|
+
</script>
|
|
138
|
+
|
|
139
|
+
<script type="text/html" data-help-name="uos-http">
|
|
140
|
+
<p>A unified node for u-OS HTTP APIs.</p>
|
|
141
|
+
|
|
142
|
+
<h3>Modes</h3>
|
|
143
|
+
<dl class="message-properties">
|
|
144
|
+
<dt>DataHub Variables</dt>
|
|
145
|
+
<dd>Access values via the standard DataHub HTTP API. Use for devices that don't support NATS or simple polling.</dd>
|
|
146
|
+
|
|
147
|
+
<dt>System Administration</dt>
|
|
148
|
+
<dd>Manage the u-OS device: Network, Logs, Security, etc. Requires <b>Enable System Admin</b> in config.</dd>
|
|
149
|
+
</dl>
|
|
150
|
+
</script>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const fetch = require('node-fetch');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
|
|
4
|
+
module.exports = function (RED) {
|
|
5
|
+
function UosHttpNode(config) {
|
|
6
|
+
RED.nodes.createNode(this, config);
|
|
7
|
+
const node = this;
|
|
8
|
+
|
|
9
|
+
node.uosConfig = RED.nodes.getNode(config.uosConfig);
|
|
10
|
+
node.mode = config.mode; // 'datahub' or 'system'
|
|
11
|
+
|
|
12
|
+
// DataHub Config
|
|
13
|
+
node.dhAction = config.dhAction; // 'read', 'write', 'list_providers', 'list_variables'
|
|
14
|
+
node.dhProvider = config.dhProvider;
|
|
15
|
+
node.dhVariable = config.dhVariable;
|
|
16
|
+
|
|
17
|
+
// System Config
|
|
18
|
+
node.sysCategory = config.sysCategory; // 'logging', 'network', 'system', 'security', 'recovery'
|
|
19
|
+
node.sysAction = config.sysAction; // dynamic based on category
|
|
20
|
+
|
|
21
|
+
if (!node.uosConfig) {
|
|
22
|
+
node.error('No u-OS Configuration configured!');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const httpsAgent = new https.Agent({
|
|
27
|
+
rejectUnauthorized: false
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
node.on('input', async function (msg) {
|
|
31
|
+
const token = await node.uosConfig.getToken();
|
|
32
|
+
if (!token) {
|
|
33
|
+
node.error('Authentication failed (No Token)', msg);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let url = '';
|
|
38
|
+
let method = 'GET';
|
|
39
|
+
let body = null;
|
|
40
|
+
let baseUrl = `https://${node.uosConfig.host}:443`; // HTTPS Port 443 implies standard web server (nginx proxy)
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
if (node.mode === 'datahub') {
|
|
44
|
+
baseUrl += '/u-os-hub/api/v1';
|
|
45
|
+
|
|
46
|
+
// Allow override from msg for dynamic usage
|
|
47
|
+
const provider = msg.provider || node.dhProvider;
|
|
48
|
+
const variable = msg.variable || node.dhVariable;
|
|
49
|
+
|
|
50
|
+
switch (node.dhAction) {
|
|
51
|
+
case 'list_providers':
|
|
52
|
+
url = `${baseUrl}/providers`;
|
|
53
|
+
break;
|
|
54
|
+
case 'list_variables':
|
|
55
|
+
if (!provider) throw new Error('Provider ID required');
|
|
56
|
+
url = `${baseUrl}/providers/${provider}/variables`;
|
|
57
|
+
if (msg.payload && typeof msg.payload === 'object') {
|
|
58
|
+
// allow query params like prefixes
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case 'read':
|
|
62
|
+
if (!provider || !variable) throw new Error('Provider ID and Variable Key required');
|
|
63
|
+
url = `${baseUrl}/providers/${provider}/variables/${variable}`;
|
|
64
|
+
break;
|
|
65
|
+
case 'write':
|
|
66
|
+
if (!provider || !variable) throw new Error('Provider ID and Variable Key required');
|
|
67
|
+
url = `${baseUrl}/providers/${provider}/variables/${variable}`;
|
|
68
|
+
method = 'POST';
|
|
69
|
+
body = JSON.stringify({ key: variable, value: msg.payload });
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
throw new Error(`Unknown DataHub Action: ${node.dhAction}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} else if (node.mode === 'system') {
|
|
76
|
+
baseUrl += '/u-os-adm/api/v1';
|
|
77
|
+
|
|
78
|
+
switch (node.sysCategory) {
|
|
79
|
+
case 'system':
|
|
80
|
+
if (node.sysAction === 'info') url = `${baseUrl}/system/info`;
|
|
81
|
+
else if (node.sysAction === 'nameplate') url = `${baseUrl}/system/nameplate`;
|
|
82
|
+
else if (node.sysAction === 'disks') url = `${baseUrl}/system/disks`;
|
|
83
|
+
else if (node.sysAction === 'reboot') { url = `${baseUrl}/system:reboot`; method = 'POST'; }
|
|
84
|
+
break;
|
|
85
|
+
case 'network':
|
|
86
|
+
if (node.sysAction === 'get_state') url = `${baseUrl}/network/state`;
|
|
87
|
+
else if (node.sysAction === 'get_config') url = `${baseUrl}/network/config`;
|
|
88
|
+
else if (node.sysAction === 'set_config') { url = `${baseUrl}/network/config`; method = 'PUT'; body = JSON.stringify(msg.payload); }
|
|
89
|
+
else if (node.sysAction === 'update_config') { url = `${baseUrl}/network/config`; method = 'PATCH'; body = JSON.stringify(msg.payload); } // Content-Type merg-patch?
|
|
90
|
+
break;
|
|
91
|
+
case 'logging':
|
|
92
|
+
if (node.sysAction === 'entries') url = `${baseUrl}/logging/entries`;
|
|
93
|
+
else if (node.sysAction === 'sources') url = `${baseUrl}/logging/sources`;
|
|
94
|
+
else if (node.sysAction === 'create_report') { url = `${baseUrl}/logging/reports`; method = 'POST'; }
|
|
95
|
+
break;
|
|
96
|
+
case 'security':
|
|
97
|
+
if (node.sysAction === 'get_config') url = `${baseUrl}/security/config`;
|
|
98
|
+
else if (node.sysAction === 'set_config') { url = `${baseUrl}/security/config`; method = 'PUT'; body = JSON.stringify(msg.payload); }
|
|
99
|
+
break;
|
|
100
|
+
case 'recovery':
|
|
101
|
+
if (node.sysAction === 'factory_reset') { url = `${baseUrl}/recovery:factory-reset`; method = 'POST'; }
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
throw new Error(`Unknown System Category: ${node.sysCategory}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
node.status({ fill: 'blue', shape: 'dot', text: 'requesting...' });
|
|
109
|
+
|
|
110
|
+
const headers = {
|
|
111
|
+
'Authorization': `Bearer ${token}`,
|
|
112
|
+
'Content-Type': 'application/json'
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (node.mode === 'system' && node.sysCategory === 'network' && node.sysAction === 'update_config') {
|
|
116
|
+
headers['Content-Type'] = 'application/merge-patch+json';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const response = await fetch(url, {
|
|
120
|
+
method,
|
|
121
|
+
headers,
|
|
122
|
+
body,
|
|
123
|
+
agent: httpsAgent
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
const errorText = await response.text();
|
|
128
|
+
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Parse Response
|
|
132
|
+
const contentType = response.headers.get('content-type');
|
|
133
|
+
if (contentType && contentType.includes('application/json')) {
|
|
134
|
+
msg.payload = await response.json();
|
|
135
|
+
} else {
|
|
136
|
+
msg.payload = await response.text();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
msg.statusCode = response.status;
|
|
140
|
+
node.send(msg);
|
|
141
|
+
node.status({ fill: 'green', shape: 'dot', text: 'Ok' });
|
|
142
|
+
|
|
143
|
+
} catch (err) {
|
|
144
|
+
node.error(err, msg);
|
|
145
|
+
node.status({ fill: 'red', shape: 'ring', text: 'Error' });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
RED.nodes.registerType('uos-http', UosHttpNode);
|
|
151
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-uos-nats",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Node-RED nodes for Weidmüller u-OS Data Hub. Read, write, and provide variables via NATS protocol with OAuth2 authentication. Features: Variable Key resolution, custom icons, example flows, and provider definition caching.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "IoTUeli",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
"uos-config": "nodes/uos-config.js",
|
|
57
57
|
"datahub-input": "nodes/datahub-input.js",
|
|
58
58
|
"datahub-output": "nodes/datahub-output.js",
|
|
59
|
-
"datahub-write": "nodes/datahub-write.js"
|
|
59
|
+
"datahub-write": "nodes/datahub-write.js",
|
|
60
|
+
"uos-http": "nodes/uos-http.js"
|
|
60
61
|
}
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|