@nr-connect/node-red 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NR Connect
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,151 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @nr-connect/node-red
2
+
3
+ **Zero-config remote access, FlowFuse Dashboard 2.0 multi-user authentication & page-level RBAC, public webhooks, and push notifications for self-hosted Node-RED (`>= 3.0.0`).**
4
+
5
+ Connect your local Node-RED in 60 seconds with **zero edits to `settings.js`**, **zero port-forwarding**, and **zero reverse-proxy maintenance**.
6
+
7
+ ---
8
+
9
+ ## Why `@nr-connect/node-red`?
10
+
11
+ Exposing a self-hosted Node-RED instance usually means choosing between an all-or-nothing VPN or exposing your entire Flow Editor (`:1880`) alongside your dashboard. **NR Connect** gives self-hosted Node-RED split-perimeter security right from the Palette Manager:
12
+
13
+ | Capability | Plain Reverse Proxy / VPN | `@nr-connect/node-red` |
14
+ | :--- | :--- | :--- |
15
+ | **Remote HTTPS & WebSockets** | Manual DNS, certs & proxy rules | **Turnkey** — paste one connection code in the Node-RED sidebar |
16
+ | **Editor vs. Dashboard Split** | Same port (`:1880`); anyone on the network reaches `/red` | **Split-Perimeter RBAC** — `Admin` gets Flow Editor + Dashboard; `Operator` is confined to `/dashboard` |
17
+ | **Dashboard 2.0 Page Permissions** | All users see every page & widget | **Per-User Page Filtering** — restricts `_setup`, Socket.IO `ui-config`, live broadcasts, and widget actions per `ui-page` |
18
+ | **User Identity in Flows (`msg._client.user`)** | Anonymous or static basic auth | **Signed User Identity** — automatically populates `msg._client.user` (`userId`, `email`, `name`, `role`) on Dashboard 2.0 events |
19
+ | **Webhooks (`HTTP In` nodes)** | Must expose full Node-RED server | **Granular Public Webhook/API Routes** — expose specific `/webhook/*` paths with optional Bearer token verification |
20
+ | **Push Notifications** | Requires 3rd-party apps or API keys | **Native Web Push** — built-in `nrc notify` node & `nrc profile` Dashboard 2.0 widget |
21
+
22
+ ---
23
+
24
+ ## 60-Second Quickstart
25
+
26
+ ### 1. Install from the Node-RED Palette Manager
27
+ 1. In the Node-RED Editor, open the top-right menu -> **Manage palette** -> **Install**.
28
+ 2. Search for `@nr-connect/node-red` and click **Install**.
29
+ 3. *(Optional CLI install)*:
30
+ ```bash
31
+ cd ~/.node-red
32
+ npm install @nr-connect/node-red
33
+ ```
34
+
35
+ ### 2. Paste Your Connection Code
36
+ 1. Sign in to [nr-connect.com](https://nr-connect.com) and click **Add instance** to generate your connection code (`NR_CONNECT_TOKEN`).
37
+ 2. In the Node-RED Editor sidebar, open the **NR Connect** tab.
38
+ 3. Paste your connection code and click **Connect**.
39
+
40
+ That's it! The plugin automatically downloads and supervises the outbound connector binary in `<userDir>/bin/`, discovers your FlowFuse Dashboard 2.0 `ui-page` nodes, and brings your secure HTTPS address online.
41
+
42
+ > **Try the Built-in Example Flow:** In Node-RED, open **Menu -> Import -> Examples -> `@nr-connect/node-red` -> `starter-demo`** for a ready-to-run multi-page Dashboard 2.0 layout demonstrating `msg._client.user`, role-based controls, and push notifications.
43
+
44
+ ---
45
+
46
+ ## Core Features & Included Nodes
47
+
48
+ ### 1. Runtime Plugin (Zero Flow Nodes Required)
49
+ - **Automatic Connector Setup & Supervision:** Downloads and SHA-256 verifies the platform-specific NR Connect connector into `<userDir>/bin/` on startup if missing and supervises the outbound connection automatically.
50
+ - **Signed Request Verification:** Verifies cryptographically signed NR Connect identity and page-permission headers on remote requests within a `+/- 2-minute` replay window.
51
+ - **FlowFuse Dashboard 2.0 Page-Level RBAC:**
52
+ - Automatically discovers `ui-page` nodes on `flows:started` and syncs them with NR Connect on deploy and every 60 seconds.
53
+ - Enforces page-level access rules across FlowFuse Dashboard 2.0 Socket.IO connections (`ui-config`, live `msg-input` / `widget-sync` / `widget-load` broadcasts, and incoming `widget-action` / `widget-change` / `widget-send` / `widget-load` events) as well as `_setup` and `_debug` store endpoints.
54
+ - Registers `node-red-dashboard-2` auth hooks (`nr-connect-d2-auth`) to populate `msg._client.user` on incoming widget and connection events.
55
+ - **NR Connect Editor Sidebar:** Live `RED.comms` status pill, last check-in timestamp with **Check in now**, one-click **Copy** / **Open** for your secure URL, **Require secure access** state, discovered **Dashboard pages**, and one-click **Copy diagnostics**.
56
+ - **Require Secure Access (Portal-Managed):** When enabled in your instance settings, direct LAN browser navigation to port `1880` redirects to your secure HTTPS address and unsigned direct requests across `RED.httpNode`, `RED.httpAdmin`, and `RED.server` WebSocket `upgrade` connections are blocked (while preserving `127.0.0.1` loopback and `.nr-connect-unlock` recovery).
57
+
58
+ ### 2. Dashboard 2.0 `msg._client.user` Injection
59
+ When a signed-in user interacts with any FlowFuse Dashboard 2.0 widget through NR Connect, the plugin populates `msg._client.user` on Socket.IO events:
60
+
61
+ ```json
62
+ {
63
+ "userId": "user_123",
64
+ "email": "operator@example.com",
65
+ "name": "Operator",
66
+ "role": "operator"
67
+ }
68
+ ```
69
+
70
+ Use a standard Node-RED `switch` or `function` node to audit who clicked a button or block non-admin writes:
71
+
72
+ ```javascript
73
+ // Example inside a Node-RED function node
74
+ if (msg._client?.user?.role !== "admin") {
75
+ node.warn(`Blocked write attempt by ${msg._client?.user?.email}`);
76
+ return null;
77
+ }
78
+ return msg;
79
+ ```
80
+
81
+ ### 3. Dashboard 2.0 Profile & Push Widget (`ui-nr-connect-profile`)
82
+ Found in the **`dashboard 2`** palette category as **`nrc profile`**, this widget displays the signed-in NR Connect user (name, email, role badge, and profile photo with initials fallback), an integrated **Push Notifications** toggle, and a **Sign out** button:
83
+
84
+ - **Two Placement Modes:**
85
+ - **In group:** Renders a compact profile card inside any Dashboard 2.0 `ui-group`.
86
+ - **App bar (top-right):** Renders an avatar menu button in Dashboard 2.0's `#app-bar-actions` slot across every page (requires the dashboard title bar to be visible).
87
+ - **Per-User Identity Endpoint (`GET /{basePath}/_nrc/me`):** Fetches the current user's profile from `/dashboard/_nrc/me` (or `/ui/_nrc/me`) with `Cache-Control: no-store`. Direct local/LAN sessions return `{ user: null, local: true, signOutBaseUrl: null }` and render a neutral `"Local access"` state.
88
+ - **Integrated Web Push Toggle:** Signed-in users can subscribe or unsubscribe their browser/mobile PWA to OS push notifications in one click. Toggle and foreground events (`push`, `push_subscribed`, `push_unsubscribed`) emit on the node's output port.
89
+ - **Clean Sign Out:** Unregisters active browser push subscriptions and navigates to the portal's `/signout?redirect=<dashboard url>` endpoint.
90
+
91
+ ### 4. Push Notification Node (`nr-connect-notify`)
92
+ Found in the **`network`** palette category as **`nrc notify`**, this node sends targeted Web Push notifications to users subscribed via your Dashboard 2.0 instance:
93
+
94
+ - **Dynamic Targeting:** Send to **All instance members**, **Admins & owner only** (`target: "admins"`), or specific **Email addresses** (`emails`), optionally combined with a **Dashboard 2.0 Page Scope** (`pageId`—restricts delivery to users permitted to view that page and opens it on click).
95
+ - **Typed Inputs, Overrides & Output:** Configure `title` and `body` via `str`, `msg`, `flow`, or `global` properties (blank `title` falls back to `msg.topic`, then `"Node-RED Alert"`). Override per message via `msg.pageId`, `msg.recipients`, or `msg.notification` (`title`, `body`, `pageId`, `target`, `emails`, `url`, `tag`, `icon`, `image`, `urgency`, `requireInteraction`, `ttlSeconds`, `data`). Delivery counts are attached to the output message in `msg.pushResult`.
96
+
97
+ ---
98
+
99
+ ## Configuration Options
100
+
101
+ ### Option A: NR Connect Sidebar (Recommended)
102
+ 1. Create an instance in the NR Connect Portal to receive a connection code (`NR_CONNECT_TOKEN`).
103
+ 2. Open the **NR Connect** tab in the Node-RED Editor sidebar.
104
+ 3. Paste your connection code and click **Connect**. The plugin verifies the code with the portal before saving `<userDir>/.nr-connect.json` (`0600`), starts the connector, and syncs discovered `ui-page` nodes.
105
+ 4. **Require secure access** is managed from your instance settings in the NR Connect Portal and updates in Node-RED on the next check-in (within 60 seconds, or immediately via **Check in now**).
106
+ 5. To switch codes or remove the connection, use **Use a different code** or **Disconnect** in the sidebar footer. Disconnecting stops the connector, deletes `<userDir>/.nr-connect.json`, and turns off Require secure access immediately.
107
+
108
+ ### Option B: Environment Variables (Headless / Docker / Balena)
109
+ For stateless or containerized deployments, set:
110
+
111
+ ```bash
112
+ NR_CONNECT_TOKEN=<your-connection-code>
113
+ NR_CONNECT_REQUIRE_SECURE_ACCESS=true # optional initial setting before portal sync overrides it
114
+ ```
115
+
116
+ When `NR_CONNECT_TOKEN` is set in the environment, the **NR Connect** sidebar displays `"This connection is set by the server environment."`, hides **Disconnect** and **Use a different code**, and admin connect/disconnect endpoints return `409`. Portal check-ins still refresh `requireSecureAccess` in memory.
117
+
118
+ ---
119
+
120
+ ## Local Recovery Escape Hatch (`.nr-connect-unlock`)
121
+
122
+ When **Require secure access** (`requireSecureAccess`) is enabled in NR Connect, direct browser requests to port `1880` redirect to your secure address and unsigned API/WebSocket requests receive `403 Forbidden`. Two built-in escape hatches guarantee you can never lock yourself out locally:
123
+
124
+ 1. **Loopback Access:** Requests originating from `127.0.0.1`, `::1`, or `::ffff:127.0.0.1` (e.g., a local browser on the host or SSH port-forwarding `ssh -L 1880:127.0.0.1:1880 pi@host`) are always permitted.
125
+ 2. **Unlock Sentinel File:** Creating an empty `.nr-connect-unlock` file inside your Node-RED `userDir` (for example `touch ~/.node-red/.nr-connect-unlock`) immediately bypasses direct-access restrictions without restarting Node-RED. Remove the file once recovery is complete.
126
+
127
+ ---
128
+
129
+ ## Deployment Environments (Linux, Raspberry Pi, Docker, LXC)
130
+
131
+ - **Requirements:** Node.js `>=18.0.0`, outbound HTTPS (`TCP 443`) and connector egress (`UDP/TCP 7844`), NTP-synced clock (`+/- 2-minute` signature replay window), and Node-RED listening over HTTP on `127.0.0.1:1880` (default; configurable in Portal instance settings).
132
+ - **Linux & Raspberry Pi:** Supports `x64`, `arm64`, `arm`, and `ia32`. Runs without root or `systemd`; downloads a SHA-256 verified connector binary to `<userDir>/bin/` if not pre-installed on the host.
133
+ - **Docker:** Use `NR_CONNECT_TOKEN` for stateless containers, or mount `userDir` (`/data`) for persistent `.nr-connect.json` and connector files. Note that host requests over `-p 1880:1880` arrive via the Docker bridge IP (not `127.0.0.1`), so `requireSecureAccess` will redirect or block them unless `.nr-connect-unlock` is present.
134
+ - **Proxmox LXC:** Works out of the box in unprivileged LXC containers without `CAP_NET_ADMIN` or TUN/TAP devices.
135
+
136
+ ---
137
+
138
+ ## Updates (Plugin & Connector)
139
+
140
+ - **Plugin Updates:** Heartbeat check-ins report the installed `pluginVersion` and receive `latest` / `minimum` plugin advisories. When an update is available, the **NR Connect** sidebar and Portal Instance page notify you to update via **Manage palette** (or container image rebuild) and restart Node-RED.
141
+ - **Connector Updates:**
142
+ - **Managed (`<userDir>/bin/`):** Downloads are verified against pinned SHA-256 digests and smoke-tested in a staging directory before stopping and atomically swapping the running binary. Update anytime via the **Update connector** button in the **NR Connect** sidebar, or set `NR_CONNECT_AUTO_UPDATE_CONNECTOR=true` for automatic background updates (required updates below `minimum` also auto-apply).
143
+ - **Host-managed (`PATH`):** When the connector binary is pre-installed by the host or container image, the plugin never mutates it and displays a host-managed update notice instead.
144
+
145
+ ---
146
+
147
+ ## Support & Community
148
+
149
+ - **Documentation & Troubleshooting:** Visit the NR Connect Portal (`/docs/troubleshooting`) for guides on Docker networking, Require secure access recovery, NTP clock sync, and connector updates.
150
+ - **Diagnostics:** Open the **NR Connect** sidebar tab in Node-RED and click **Copy diagnostics** to copy a redacted JSON block (Node.js, Node-RED, plugin, and connector versions — zero connection codes or secrets) when filing a bug report.
151
+ - **Bug Reports, Q&A & Private Support:** Open the **Support & docs** link in the sidebar footer (or visit `https://nr-connect.com/support`) to report issues, join community discussions, or contact `support@nr-connect.com`.