node-red-contrib-unifi-ultimate 1.0.3 → 1.0.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.
package/README.md CHANGED
@@ -52,6 +52,10 @@ In Node-RED:
52
52
  > **Tip:** For most actions, the incoming message is just a trigger — the node uses the device and action you configured in the editor.
53
53
  > The only exception is **Control POE** with the *POE controlled by incoming message* action: send `true` to turn PoE on and `false` to turn it off.
54
54
 
55
+ > **Custom port:** Each config node has an optional **Port** field. Leave it empty to use the default (`443` for Network/Protect, `12445` for Access). Set it when your controller listens on a custom port — for example a **UniFi OS server** that uses `11443`. A port written directly in the controller address (`host:port`) takes precedence over this field.
56
+
57
+ > **Self-signed certificates:** Each config node has an **Allow self-signed certificate** option, enabled by default. UniFi controllers almost always present a self-signed certificate, so keep it checked for UniFi OS / UXG setups. Uncheck it only if your controller uses a certificate signed by a trusted certificate authority and you want strict verification.
58
+
55
59
  <br/>
56
60
  <br/>
57
61
  <p align="left">
@@ -6,6 +6,16 @@
6
6
  defaults: {
7
7
  name: { value: "Unifi Access Config" },
8
8
  host: { value: "", required: true },
9
+ port: {
10
+ value: "",
11
+ required: false,
12
+ validate: function (value) {
13
+ if (value === undefined || value === null || value === "") {
14
+ return true;
15
+ }
16
+ return /^\d+$/.test(String(value)) && Number(value) >= 1 && Number(value) <= 65535;
17
+ }
18
+ },
9
19
  rejectUnauthorized: { value: false }
10
20
  },
11
21
  credentials: {
@@ -17,14 +27,23 @@
17
27
  oneditprepare: function () {
18
28
  const node = this;
19
29
  const $hostInput = $("#node-config-input-host");
30
+ const $port = $("#node-config-input-port");
20
31
  const $apiToken = $("#node-config-input-apiToken");
21
- const $rejectUnauthorized = $("#node-config-input-rejectUnauthorized");
32
+ const $allowSelfSigned = $("#node-config-input-allowSelfSigned");
33
+ const $portRow = $port.closest(".form-row");
22
34
  const $apiTokenRow = $apiToken.closest(".form-row");
23
- const $securityRow = $rejectUnauthorized.closest(".form-row");
35
+ const $securityRow = $allowSelfSigned.closest(".form-row");
24
36
  const $advancedRow = $("#node-config-row-advanced");
25
37
 
38
+ // The stored field is rejectUnauthorized, but the checkbox is shown as
39
+ // its inverse ("Allow self-signed certificate") because UniFi
40
+ // controllers almost always use self-signed certificates. Default to
41
+ // allowing them when no explicit strict value was saved.
42
+ $allowSelfSigned.prop("checked", node.rejectUnauthorized !== true && node.rejectUnauthorized !== "true");
43
+
26
44
  function syncProgressiveRows() {
27
45
  const hasHost = String($hostInput.val() || node.host || "").trim() !== "";
46
+ $portRow.toggle(hasHost);
28
47
  $apiTokenRow.toggle(hasHost);
29
48
  $securityRow.toggle(hasHost);
30
49
  $advancedRow.toggle(hasHost);
@@ -42,6 +61,10 @@
42
61
  $hostInput.on("change input", function () {
43
62
  syncProgressiveRows();
44
63
  });
64
+ },
65
+ oneditsave: function () {
66
+ // Persist the inverse of the "Allow self-signed certificate" checkbox.
67
+ this.rejectUnauthorized = !$("#node-config-input-allowSelfSigned").prop("checked");
45
68
  }
46
69
  });
47
70
  </script>
@@ -60,14 +83,18 @@
60
83
  <label for="node-config-input-host"><i class="fa fa-globe"></i> Controller</label>
61
84
  <input type="text" id="node-config-input-host" placeholder="192.168.1.10 or access.local:12445">
62
85
  </div>
86
+ <div class="form-row">
87
+ <label for="node-config-input-port"><i class="fa fa-plug"></i> Port</label>
88
+ <input type="text" id="node-config-input-port" placeholder="12445 (default)">
89
+ </div>
63
90
  <div class="form-row">
64
91
  <label for="node-config-input-apiToken"><i class="fa fa-key"></i> API Token</label>
65
92
  <input type="password" id="node-config-input-apiToken" placeholder="Paste your UniFi Access token">
66
93
  </div>
67
94
  <div class="form-row">
68
- <label for="node-config-input-rejectUnauthorized"><i class="fa fa-lock"></i> Security</label>
69
- <input type="checkbox" id="node-config-input-rejectUnauthorized" style="display:inline-block; width:auto; vertical-align:top;">
70
- <span style="margin-left:8px;">Secure connection only</span>
95
+ <label for="node-config-input-allowSelfSigned"><i class="fa fa-lock"></i> Security</label>
96
+ <input type="checkbox" id="node-config-input-allowSelfSigned" style="display:inline-block; width:auto; vertical-align:top;">
97
+ <span style="margin-left:8px;">Allow self-signed certificate</span>
71
98
  </div>
72
99
  <div id="node-config-row-advanced" class="unifi-ultimate-advanced">
73
100
  <div class="form-row">
@@ -84,8 +111,9 @@
84
111
 
85
112
  <h3>Configuration</h3>
86
113
  <p><b>Controller</b> accepts the UniFi Access host or <code>host:port</code>. If you omit the port, the node uses the default UniFi Access port automatically.</p>
114
+ <p><b>Port</b> is optional. Leave it empty to use the default <code>12445</code>. Set it when your UniFi Access controller listens on a custom port. A port embedded directly in the Controller field (<code>host:port</code>) takes precedence over this field.</p>
87
115
  <p><b>API Token</b> is the bearer token used for authentication.</p>
88
- <p><b>Security</b> controls certificate verification. Disable it only when your controller uses a self-signed certificate.</p>
116
+ <p><b>Security</b> &mdash; <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 Access setups. Uncheck it only if your controller serves a certificate signed by a trusted certificate authority and you want strict verification.</p>
89
117
  <p><b>Name</b> is the config node name shown in the editor.</p>
90
118
 
91
119
  <h3>Usage</h3>
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {
4
4
  buildBaseUrlFromHost,
5
+ normalizePort,
5
6
  buildQueryString,
6
7
  doRequest,
7
8
  buildRequestHeaders,
@@ -67,8 +68,11 @@ module.exports = function(RED) {
67
68
  const node = this;
68
69
  node.name = config.name;
69
70
  node.host = String(config.host || "").trim();
70
- node.baseUrl = buildBaseUrlFromHost(node.host);
71
- node.rejectUnauthorized = config.rejectUnauthorized !== false && config.rejectUnauthorized !== "false";
71
+ node.port = normalizePort(config.port);
72
+ node.baseUrl = buildBaseUrlFromHost(node.host, node.port);
73
+ // UniFi controllers almost always use self-signed certificates, so accept
74
+ // them unless the user explicitly opted into strict verification.
75
+ node.rejectUnauthorized = config.rejectUnauthorized === true || config.rejectUnauthorized === "true";
72
76
  node.nodeClients = [];
73
77
  node.wsNotifications = null;
74
78
  node.reconnectTimer = null;
@@ -7,6 +7,16 @@
7
7
  defaults: {
8
8
  name: { value: "Unifi Network Config" },
9
9
  host: { value: "", required: true },
10
+ port: {
11
+ value: "",
12
+ required: false,
13
+ validate: function (value) {
14
+ if (value === undefined || value === null || value === "") {
15
+ return true;
16
+ }
17
+ return /^\d+$/.test(String(value)) && Number(value) >= 1 && Number(value) <= 65535;
18
+ }
19
+ },
10
20
  rejectUnauthorized: { value: false },
11
21
  powerObservationIntervalSeconds: {
12
22
  value: 15,
@@ -28,16 +38,25 @@
28
38
  oneditprepare: function () {
29
39
  const node = this;
30
40
  const $hostInput = $("#node-config-input-host");
41
+ const $port = $("#node-config-input-port");
31
42
  const $apiKey = $("#node-config-input-apiKey");
32
- const $rejectUnauthorized = $("#node-config-input-rejectUnauthorized");
43
+ const $allowSelfSigned = $("#node-config-input-allowSelfSigned");
33
44
  const $powerObservationIntervalSeconds = $("#node-config-input-powerObservationIntervalSeconds");
45
+ const $portRow = $port.closest(".form-row");
34
46
  const $apiKeyRow = $apiKey.closest(".form-row");
35
- const $securityRow = $rejectUnauthorized.closest(".form-row");
47
+ const $securityRow = $allowSelfSigned.closest(".form-row");
36
48
  const $powerObservationRow = $powerObservationIntervalSeconds.closest(".form-row");
37
49
  const $advancedRow = $("#node-config-row-advanced");
38
50
 
51
+ // The stored field is rejectUnauthorized, but the checkbox is shown as
52
+ // its inverse ("Allow self-signed certificate") because UniFi
53
+ // controllers almost always use self-signed certificates. Default to
54
+ // allowing them when no explicit strict value was saved.
55
+ $allowSelfSigned.prop("checked", node.rejectUnauthorized !== true && node.rejectUnauthorized !== "true");
56
+
39
57
  function syncProgressiveRows() {
40
58
  const hasHost = String($hostInput.val() || node.host || "").trim() !== "";
59
+ $portRow.toggle(hasHost);
41
60
  $apiKeyRow.toggle(hasHost);
42
61
  $securityRow.toggle(hasHost);
43
62
  $powerObservationRow.toggle(hasHost);
@@ -55,6 +74,10 @@
55
74
  $hostInput.on("change input", function () {
56
75
  syncProgressiveRows();
57
76
  });
77
+ },
78
+ oneditsave: function () {
79
+ // Persist the inverse of the "Allow self-signed certificate" checkbox.
80
+ this.rejectUnauthorized = !$("#node-config-input-allowSelfSigned").prop("checked");
58
81
  }
59
82
  });
60
83
  </script>
@@ -73,14 +96,18 @@
73
96
  <label for="node-config-input-host"><i class="fa fa-globe"></i> Controller</label>
74
97
  <input type="text" id="node-config-input-host" placeholder="192.168.1.10">
75
98
  </div>
99
+ <div class="form-row">
100
+ <label for="node-config-input-port"><i class="fa fa-plug"></i> Port</label>
101
+ <input type="text" id="node-config-input-port" placeholder="443 (default)">
102
+ </div>
76
103
  <div class="form-row">
77
104
  <label for="node-config-input-apiKey"><i class="fa fa-key"></i> API Key</label>
78
105
  <input type="password" id="node-config-input-apiKey" placeholder="Paste your UniFi Network API key">
79
106
  </div>
80
107
  <div class="form-row">
81
- <label for="node-config-input-rejectUnauthorized"><i class="fa fa-lock"></i> Security</label>
82
- <input type="checkbox" id="node-config-input-rejectUnauthorized" style="display:inline-block; width:auto; vertical-align:top;">
83
- <span style="margin-left:8px;">Secure connection only</span>
108
+ <label for="node-config-input-allowSelfSigned"><i class="fa fa-lock"></i> Security</label>
109
+ <input type="checkbox" id="node-config-input-allowSelfSigned" style="display:inline-block; width:auto; vertical-align:top;">
110
+ <span style="margin-left:8px;">Allow self-signed certificate</span>
84
111
  </div>
85
112
  <div class="form-row">
86
113
  <label for="node-config-input-powerObservationIntervalSeconds"><i class="fa fa-repeat"></i> Power Poll (s)</label>
@@ -101,8 +128,9 @@
101
128
 
102
129
  <h3>Configuration</h3>
103
130
  <p><b>Controller</b> accepts the UniFi OS host or IP address. The node builds the local UniFi Network proxy URL automatically.</p>
131
+ <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>
104
132
  <p><b>API Key</b> is required for authentication and is sent as <code>X-API-Key</code>.</p>
105
- <p><b>Security</b> controls certificate verification. Disable it only when your controller uses a self-signed certificate.</p>
133
+ <p><b>Security</b> &mdash; <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 / UXG setups. Uncheck it only if your controller serves a certificate signed by a trusted certificate authority and you want strict verification.</p>
106
134
  <p><b>Power Poll (s)</b> is the global polling interval used by all <code>Control POE</code> nodes when action is <code>Emit Power Consumption</code>. It is optional and defaults to 15 seconds.</p>
107
135
  <p><b>Name</b> is the config node name shown in the editor.</p>
108
136
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  const {
4
4
  buildBaseUrlFromHost,
5
+ normalizePort,
6
+ applyPortToHost,
5
7
  buildQueryString,
6
8
  doRequest,
7
9
  buildRequestHeaders,
@@ -75,8 +77,11 @@ module.exports = function(RED) {
75
77
  const node = this;
76
78
  node.name = config.name;
77
79
  node.host = String(config.host || "").trim();
78
- node.baseUrl = buildBaseUrlFromHost(node.host);
79
- node.rejectUnauthorized = config.rejectUnauthorized !== false && config.rejectUnauthorized !== "false";
80
+ node.port = normalizePort(config.port);
81
+ node.baseUrl = buildBaseUrlFromHost(node.host, node.port);
82
+ // UniFi controllers almost always use self-signed certificates, so accept
83
+ // them unless the user explicitly opted into strict verification.
84
+ node.rejectUnauthorized = config.rejectUnauthorized === true || config.rejectUnauthorized === "true";
80
85
  node.powerObservationIntervalSeconds = normalizePowerObserverIntervalSeconds(config.powerObservationIntervalSeconds);
81
86
  node.nodeClients = [];
82
87
  node.wsNetworkEvents = null;
@@ -642,10 +647,13 @@ module.exports = function(RED) {
642
647
  };
643
648
 
644
649
  node.buildUnofficialNetworkWebSocketUrl = () => {
645
- const normalizedHost = String(node.host || "")
646
- .trim()
647
- .replace(/^https?:\/\//i, "")
648
- .replace(/\/.*$/, "");
650
+ const normalizedHost = applyPortToHost(
651
+ String(node.host || "")
652
+ .trim()
653
+ .replace(/^https?:\/\//i, "")
654
+ .replace(/\/.*$/, ""),
655
+ node.port
656
+ );
649
657
  if (!normalizedHost) {
650
658
  throw new Error("The configured host is empty or invalid.");
651
659
  }
@@ -7,6 +7,16 @@
7
7
  defaults: {
8
8
  name: { value: "Unifi Protect Config" },
9
9
  host: { value: "", required: true },
10
+ port: {
11
+ value: "",
12
+ required: false,
13
+ validate: function (value) {
14
+ if (value === undefined || value === null || value === "") {
15
+ return true;
16
+ }
17
+ return /^\d+$/.test(String(value)) && Number(value) >= 1 && Number(value) <= 65535;
18
+ }
19
+ },
10
20
  authHeader: { value: "X-API-Key", required: true },
11
21
  rejectUnauthorized: { value: false }
12
22
  },
@@ -19,14 +29,23 @@
19
29
  oneditprepare: function () {
20
30
  const node = this;
21
31
  const $hostInput = $("#node-config-input-host");
32
+ const $port = $("#node-config-input-port");
22
33
  const $apiKey = $("#node-config-input-apiKey");
23
- const $rejectUnauthorized = $("#node-config-input-rejectUnauthorized");
34
+ const $allowSelfSigned = $("#node-config-input-allowSelfSigned");
35
+ const $portRow = $port.closest(".form-row");
24
36
  const $apiKeyRow = $apiKey.closest(".form-row");
25
- const $securityRow = $rejectUnauthorized.closest(".form-row");
37
+ const $securityRow = $allowSelfSigned.closest(".form-row");
26
38
  const $advancedRow = $("#node-config-row-advanced");
27
39
 
40
+ // The stored field is rejectUnauthorized, but the checkbox is shown as
41
+ // its inverse ("Allow self-signed certificate") because UniFi
42
+ // controllers almost always use self-signed certificates. Default to
43
+ // allowing them when no explicit strict value was saved.
44
+ $allowSelfSigned.prop("checked", node.rejectUnauthorized !== true && node.rejectUnauthorized !== "true");
45
+
28
46
  function syncProgressiveRows() {
29
47
  const hasHost = String($hostInput.val() || node.host || "").trim() !== "";
48
+ $portRow.toggle(hasHost);
30
49
  $apiKeyRow.toggle(hasHost);
31
50
  $securityRow.toggle(hasHost);
32
51
  $advancedRow.toggle(hasHost);
@@ -45,6 +64,10 @@
45
64
  syncProgressiveRows();
46
65
  });
47
66
 
67
+ },
68
+ oneditsave: function () {
69
+ // Persist the inverse of the "Allow self-signed certificate" checkbox.
70
+ this.rejectUnauthorized = !$("#node-config-input-allowSelfSigned").prop("checked");
48
71
  }
49
72
  });
50
73
  </script>
@@ -63,14 +86,18 @@
63
86
  <label for="node-config-input-host"><i class="fa fa-globe"></i> Controller</label>
64
87
  <input type="text" id="node-config-input-host" placeholder="192.168.1.10">
65
88
  </div>
89
+ <div class="form-row">
90
+ <label for="node-config-input-port"><i class="fa fa-plug"></i> Port</label>
91
+ <input type="text" id="node-config-input-port" placeholder="443 (default)">
92
+ </div>
66
93
  <div class="form-row">
67
94
  <label for="node-config-input-apiKey"><i class="fa fa-key"></i> API Key</label>
68
95
  <input type="password" id="node-config-input-apiKey" placeholder="Paste your UniFi Protect API key">
69
96
  </div>
70
97
  <div class="form-row">
71
- <label for="node-config-input-rejectUnauthorized"><i class="fa fa-lock"></i> Security</label>
72
- <input type="checkbox" id="node-config-input-rejectUnauthorized" style="display:inline-block; width:auto; vertical-align:top;">
73
- <span style="margin-left:8px;">Secure connection only</span>
98
+ <label for="node-config-input-allowSelfSigned"><i class="fa fa-lock"></i> Security</label>
99
+ <input type="checkbox" id="node-config-input-allowSelfSigned" style="display:inline-block; width:auto; vertical-align:top;">
100
+ <span style="margin-left:8px;">Allow self-signed certificate</span>
74
101
  </div>
75
102
  <div id="node-config-row-advanced" class="unifi-ultimate-advanced">
76
103
  <div class="form-row">
@@ -91,8 +118,9 @@
91
118
 
92
119
  <h3>Configuration</h3>
93
120
  <p><b>Controller</b> accepts the UniFi OS host or IP address. The node builds the Protect integration URL automatically.</p>
121
+ <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>
94
122
  <p><b>API Key</b> is required for authentication.</p>
95
- <p><b>Security</b> controls certificate verification. Disable it only when your controller uses a self-signed certificate.</p>
123
+ <p><b>Security</b> &mdash; <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>
96
124
  <p><b>Name</b> is the config node name shown in the editor.</p>
97
125
  <p><b>API Header</b> is an advanced field. Leave the default value unless your UniFi Protect setup expects a different header name.</p>
98
126
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {
4
4
  buildBaseUrlFromHost,
5
+ normalizePort,
5
6
  buildQueryString,
6
7
  doRequest,
7
8
  buildRequestHeaders,
@@ -24,9 +25,12 @@ module.exports = function(RED) {
24
25
  const node = this;
25
26
  node.name = config.name;
26
27
  node.host = String(config.host || "").trim();
27
- node.baseUrl = buildBaseUrlFromHost(node.host);
28
+ node.port = normalizePort(config.port);
29
+ node.baseUrl = buildBaseUrlFromHost(node.host, node.port);
28
30
  node.authHeader = (config.authHeader || "X-API-Key").trim() || "X-API-Key";
29
- node.rejectUnauthorized = config.rejectUnauthorized !== false && config.rejectUnauthorized !== "false";
31
+ // UniFi controllers almost always use self-signed certificates, so accept
32
+ // them unless the user explicitly opted into strict verification.
33
+ node.rejectUnauthorized = config.rejectUnauthorized === true || config.rejectUnauthorized === "true";
30
34
  node.nodeClients = [];
31
35
  node.wsDevices = null;
32
36
  node.wsEvents = null;
@@ -12,6 +12,57 @@ function parseIntervalSeconds(value, fallback) {
12
12
  return Math.trunc(numeric);
13
13
  }
14
14
 
15
+ function normalizePort(value) {
16
+ // Accept a TCP port from the editor and reduce it to a clean "1".."65535"
17
+ // string, or empty when missing/invalid so callers can fall back to defaults.
18
+ if (value === undefined || value === null) {
19
+ return "";
20
+ }
21
+
22
+ const str = String(value).trim();
23
+ if (!str || !/^\d+$/.test(str)) {
24
+ return "";
25
+ }
26
+
27
+ const num = Number(str);
28
+ if (!Number.isInteger(num) || num < 1 || num > 65535) {
29
+ return "";
30
+ }
31
+
32
+ return String(num);
33
+ }
34
+
35
+ function hostHasExplicitPort(host) {
36
+ if (!host) {
37
+ return false;
38
+ }
39
+
40
+ if (host.startsWith("[")) {
41
+ // IPv6 literal: a port is only present when "]:" appears (e.g. [::1]:443).
42
+ return host.includes("]:");
43
+ }
44
+
45
+ // Bare host or IPv4: a single trailing :<digits> is a port.
46
+ return (host.match(/:/g) || []).length === 1 && /:\d+$/.test(host);
47
+ }
48
+
49
+ function applyPortToHost(host, port) {
50
+ // Combine a normalized host with the dedicated port field. A port already
51
+ // embedded in the host string always wins, so the separate field only fills
52
+ // the gap when the host carries none.
53
+ const normalizedHost = String(host || "").trim();
54
+ if (!normalizedHost) {
55
+ return "";
56
+ }
57
+
58
+ const normalizedPort = normalizePort(port);
59
+ if (!normalizedPort || hostHasExplicitPort(normalizedHost)) {
60
+ return normalizedHost;
61
+ }
62
+
63
+ return `${normalizedHost}:${normalizedPort}`;
64
+ }
65
+
15
66
  function buildStatusTimestampText() {
16
67
  const now = new Date();
17
68
  const time = now.toTimeString().split(" ")[0];
@@ -93,6 +144,8 @@ function buildErrorOutputMessage(error, nodeName) {
93
144
  module.exports = {
94
145
  parseBoolean,
95
146
  parseIntervalSeconds,
147
+ normalizePort,
148
+ applyPortToHost,
96
149
  buildStatusTimestampText,
97
150
  appendStatusTimestamp,
98
151
  resolveNodeName,
@@ -3,10 +3,13 @@
3
3
  const http = require("http");
4
4
  const https = require("https");
5
5
  const { maybeParseBody } = require("./http-response-utils");
6
+ const { normalizePort, applyPortToHost } = require("./common-utils");
6
7
 
7
- function normalizeHost(value) {
8
+ function normalizeHost(value, port) {
8
9
  // Access controllers usually live on port 12445. Accept bare hosts, host:port
9
- // pairs and IPv6 literals, then normalize everything to one safe form.
10
+ // pairs and IPv6 literals, then normalize everything to one safe form. The
11
+ // dedicated port field (when set) fills in a missing port before the 12445
12
+ // default is applied.
10
13
  let host = String(value || "").trim();
11
14
  if (!host) {
12
15
  return "";
@@ -20,6 +23,8 @@ function normalizeHost(value) {
20
23
  return "";
21
24
  }
22
25
 
26
+ host = applyPortToHost(host, port);
27
+
23
28
  if (host.startsWith("[") && host.includes("]")) {
24
29
  return host.includes("]:") ? host : `${host}:12445`;
25
30
  }
@@ -36,8 +41,8 @@ function normalizeHost(value) {
36
41
  return host;
37
42
  }
38
43
 
39
- function buildBaseUrlFromHost(value) {
40
- const host = normalizeHost(value);
44
+ function buildBaseUrlFromHost(value, port) {
45
+ const host = normalizeHost(value, port);
41
46
  if (!host) {
42
47
  return "";
43
48
  }
@@ -174,6 +179,8 @@ function normalizeAccessCollection(payload) {
174
179
 
175
180
  module.exports = {
176
181
  buildBaseUrlFromHost,
182
+ normalizePort,
183
+ applyPortToHost,
177
184
  buildQueryString,
178
185
  doRequest,
179
186
  buildRequestHeaders,
@@ -3,6 +3,7 @@
3
3
  const http = require("http");
4
4
  const https = require("https");
5
5
  const { maybeParseBody } = require("./http-response-utils");
6
+ const { normalizePort, applyPortToHost } = require("./common-utils");
6
7
 
7
8
  function normalizeHost(value) {
8
9
  // Accept either a bare host or a full URL from the editor and reduce it to
@@ -17,8 +18,8 @@ function normalizeHost(value) {
17
18
  return host.trim().replace(/\/+$/, "");
18
19
  }
19
20
 
20
- function buildBaseUrlFromHost(value) {
21
- const host = normalizeHost(value);
21
+ function buildBaseUrlFromHost(value, port) {
22
+ const host = applyPortToHost(normalizeHost(value), port);
22
23
  if (!host) {
23
24
  return "";
24
25
  }
@@ -156,6 +157,8 @@ function normalizeNetworkCollection(payload) {
156
157
 
157
158
  module.exports = {
158
159
  buildBaseUrlFromHost,
160
+ normalizePort,
161
+ applyPortToHost,
159
162
  buildQueryString,
160
163
  doRequest,
161
164
  buildRequestHeaders,
@@ -3,6 +3,7 @@
3
3
  const http = require("http");
4
4
  const https = require("https");
5
5
  const { maybeParseBody } = require("./http-response-utils");
6
+ const { normalizePort, applyPortToHost } = require("./common-utils");
6
7
 
7
8
  function normalizeHost(value) {
8
9
  // Protect editor fields may contain a host or a full URL; strip everything
@@ -17,8 +18,8 @@ function normalizeHost(value) {
17
18
  return host.trim().replace(/\/+$/, "");
18
19
  }
19
20
 
20
- function buildBaseUrlFromHost(value) {
21
- const host = normalizeHost(value);
21
+ function buildBaseUrlFromHost(value, port) {
22
+ const host = applyPortToHost(normalizeHost(value), port);
22
23
  if (!host) {
23
24
  return "";
24
25
  }
@@ -131,6 +132,8 @@ function buildRequestBody(headers, method, payload) {
131
132
 
132
133
  module.exports = {
133
134
  buildBaseUrlFromHost,
135
+ normalizePort,
136
+ applyPortToHost,
134
137
  buildQueryString,
135
138
  doRequest,
136
139
  buildRequestHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-unifi-ultimate",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Node-RED nodes for Ubiquiti UniFi integrations, including UniFi Protect, UniFi Access, and UniFi Network.",
5
5
  "files": [
6
6
  "nodes/",