node-red-contrib-unifi-ultimate 1.1.4 → 1.1.6
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/LICENSE +1 -1
- package/examples/unifi-protect-camera-actions.json +0 -1
- package/examples/unifi-protect-info.json +0 -1
- package/examples/unifi-protect-sensor-observe.json +0 -1
- package/nodes/unifi-network-config.js +3 -7
- package/nodes/unifi-protect-config.html +2 -8
- package/nodes/unifi-protect-config.js +2 -3
- package/nodes/utils/unifi-network-utils.js +6 -4
- package/nodes/utils/unifi-protect-utils.js +6 -4
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2026 Massimo Saccani
|
|
3
|
+
Copyright (c) 2026 Massimo Saccani (maxsupergiovane@icloud.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -32,7 +32,6 @@ const {
|
|
|
32
32
|
} = require("./utils/unifi-network-presence-utils");
|
|
33
33
|
|
|
34
34
|
module.exports = function(RED) {
|
|
35
|
-
const API_KEY_HEADER = "X-API-Key";
|
|
36
35
|
const MIN_POWER_OBSERVER_INTERVAL_SECONDS = 5;
|
|
37
36
|
const DEFAULT_POWER_OBSERVER_INTERVAL_SECONDS = 15;
|
|
38
37
|
const POWER_OBSERVER_SCHEDULER_TICK_MS = 1000;
|
|
@@ -317,7 +316,7 @@ module.exports = function(RED) {
|
|
|
317
316
|
const normalizedPath = String(path || "").startsWith("/") ? String(path || "") : `/${String(path || "")}`;
|
|
318
317
|
const requestUrl = new URL(`${node.baseUrl}${normalizedPath}${queryString}`);
|
|
319
318
|
const requestMethod = String(method || "GET").toUpperCase();
|
|
320
|
-
const requestHeaders = buildRequestHeaders(
|
|
319
|
+
const requestHeaders = buildRequestHeaders(apiKey, headers);
|
|
321
320
|
const requestBody = buildRequestBody(requestHeaders, requestMethod, payload);
|
|
322
321
|
|
|
323
322
|
return doRequest(
|
|
@@ -357,7 +356,7 @@ module.exports = function(RED) {
|
|
|
357
356
|
const legacyBaseUrl = node.baseUrl.replace(/\/integration\/?$/, "");
|
|
358
357
|
const requestUrl = new URL(`${legacyBaseUrl}${normalizedPath}${queryString}`);
|
|
359
358
|
const requestMethod = String(method || "GET").toUpperCase();
|
|
360
|
-
const requestHeaders = buildRequestHeaders(
|
|
359
|
+
const requestHeaders = buildRequestHeaders(apiKey, headers);
|
|
361
360
|
const requestBody = buildRequestBody(requestHeaders, requestMethod, payload);
|
|
362
361
|
|
|
363
362
|
return doRequest(
|
|
@@ -908,10 +907,7 @@ module.exports = function(RED) {
|
|
|
908
907
|
let ws;
|
|
909
908
|
try {
|
|
910
909
|
ws = new WebSocket(node.buildUnofficialNetworkWebSocketUrl(), {
|
|
911
|
-
headers:
|
|
912
|
-
[API_KEY_HEADER]: apiKey,
|
|
913
|
-
Accept: "application/json"
|
|
914
|
-
},
|
|
910
|
+
headers: buildRequestHeaders(apiKey),
|
|
915
911
|
rejectUnauthorized: node.rejectUnauthorized
|
|
916
912
|
});
|
|
917
913
|
} catch (error) {
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
return /^\d+$/.test(String(value)) && Number(value) >= 1 && Number(value) <= 65535;
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
authHeader: { value: "X-API-Key", required: true },
|
|
22
21
|
rejectUnauthorized: { value: false }
|
|
23
22
|
},
|
|
24
23
|
credentials: {
|
|
@@ -105,10 +104,6 @@
|
|
|
105
104
|
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
106
105
|
<input type="text" id="node-config-input-name" placeholder="Node name">
|
|
107
106
|
</div>
|
|
108
|
-
<div class="form-row">
|
|
109
|
-
<label for="node-config-input-authHeader"><i class="fa fa-header"></i> API Header</label>
|
|
110
|
-
<input type="text" id="node-config-input-authHeader" placeholder="X-API-Key">
|
|
111
|
-
</div>
|
|
112
107
|
</div>
|
|
113
108
|
</script>
|
|
114
109
|
|
|
@@ -120,12 +115,11 @@
|
|
|
120
115
|
<h3>Configuration</h3>
|
|
121
116
|
<p><b>Controller</b> accepts the UniFi OS host or IP address. The node builds the Protect integration URL automatically.</p>
|
|
122
117
|
<p><b>Port</b> is optional. Leave it empty to use the default <code>443</code>. Set it when your UniFi OS server listens on a custom port (for example <code>11443</code>). A port embedded directly in the Controller field (<code>host:port</code>) takes precedence over this field.</p>
|
|
123
|
-
<p><b>API Key</b> is required for authentication
|
|
118
|
+
<p><b>API Key</b> is required for authentication and is sent automatically as <code>X-API-Key</code>.</p>
|
|
124
119
|
<p><b>Security</b> — <b>Allow self-signed certificate</b> is enabled by default because UniFi controllers almost always present a self-signed certificate. Leave it checked for UniFi OS setups. Uncheck it only if your controller serves a certificate signed by a trusted certificate authority and you want strict verification.</p>
|
|
125
120
|
<p><b>Name</b> is the config node name shown in the editor.</p>
|
|
126
|
-
<p><b>API Header</b> is an advanced field. Leave the default value unless your UniFi Protect setup expects a different header name.</p>
|
|
127
121
|
|
|
128
122
|
<h3>Usage</h3>
|
|
129
123
|
<p>This config node is used by UniFi Protect Device nodes for API requests and live device/event updates.</p>
|
|
130
124
|
<p>All Protect API calls and websocket streams are managed by this config node. Runtime nodes subscribe through <code>addClient/removeClient</code> and receive broadcast updates.</p>
|
|
131
|
-
</script>
|
|
125
|
+
</script>
|
|
@@ -27,7 +27,6 @@ module.exports = function(RED) {
|
|
|
27
27
|
node.host = String(config.host || "").trim();
|
|
28
28
|
node.port = normalizePort(config.port);
|
|
29
29
|
node.baseUrl = buildBaseUrlFromHost(node.host, node.port);
|
|
30
|
-
node.authHeader = (config.authHeader || "X-API-Key").trim() || "X-API-Key";
|
|
31
30
|
// UniFi controllers almost always use self-signed certificates, so accept
|
|
32
31
|
// them unless the user explicitly opted into strict verification.
|
|
33
32
|
node.rejectUnauthorized = config.rejectUnauthorized === true || config.rejectUnauthorized === "true";
|
|
@@ -62,7 +61,7 @@ module.exports = function(RED) {
|
|
|
62
61
|
const normalizedPath = String(path || "").startsWith("/") ? String(path || "") : `/${String(path || "")}`;
|
|
63
62
|
const requestUrl = new URL(`${node.baseUrl}${normalizedPath}${queryString}`);
|
|
64
63
|
const requestMethod = String(method || "GET").toUpperCase();
|
|
65
|
-
const requestHeaders = buildRequestHeaders(
|
|
64
|
+
const requestHeaders = buildRequestHeaders(apiKey, headers);
|
|
66
65
|
const requestBody = buildRequestBody(requestHeaders, requestMethod, payload);
|
|
67
66
|
|
|
68
67
|
return doRequest(
|
|
@@ -220,7 +219,7 @@ module.exports = function(RED) {
|
|
|
220
219
|
try {
|
|
221
220
|
ws = new WebSocket(node.buildWebSocketUrl(path), {
|
|
222
221
|
headers: {
|
|
223
|
-
|
|
222
|
+
"X-API-Key": apiKey,
|
|
224
223
|
Accept: "application/json"
|
|
225
224
|
},
|
|
226
225
|
rejectUnauthorized: node.rejectUnauthorized
|
|
@@ -95,13 +95,15 @@ function doRequest(url, options, body) {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
function buildRequestHeaders(
|
|
98
|
+
function buildRequestHeaders(apiKey, msgHeaders) {
|
|
99
99
|
return Object.assign(
|
|
100
100
|
{
|
|
101
|
-
Accept: "application/json"
|
|
102
|
-
[authHeader]: apiKey
|
|
101
|
+
Accept: "application/json"
|
|
103
102
|
},
|
|
104
|
-
msgHeaders && typeof msgHeaders === "object" ? msgHeaders : {}
|
|
103
|
+
msgHeaders && typeof msgHeaders === "object" ? msgHeaders : {},
|
|
104
|
+
{
|
|
105
|
+
"X-API-Key": apiKey
|
|
106
|
+
}
|
|
105
107
|
);
|
|
106
108
|
}
|
|
107
109
|
|
|
@@ -91,13 +91,15 @@ function doRequest(url, options, body) {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
function buildRequestHeaders(
|
|
94
|
+
function buildRequestHeaders(apiKey, msgHeaders) {
|
|
95
95
|
return Object.assign(
|
|
96
96
|
{
|
|
97
|
-
Accept: "application/json"
|
|
98
|
-
[authHeader]: apiKey
|
|
97
|
+
Accept: "application/json"
|
|
99
98
|
},
|
|
100
|
-
msgHeaders && typeof msgHeaders === "object" ? msgHeaders : {}
|
|
99
|
+
msgHeaders && typeof msgHeaders === "object" ? msgHeaders : {},
|
|
100
|
+
{
|
|
101
|
+
"X-API-Key": apiKey
|
|
102
|
+
}
|
|
101
103
|
);
|
|
102
104
|
}
|
|
103
105
|
|
package/package.json
CHANGED