@theotherwillembotha/node-red-plugincore 0.0.50 → 0.0.52
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 +155 -23
- package/build/GenerateNodes.js +3 -0
- package/build/Nodes.html +174 -250
- package/build/Nodes.js +2 -0
- package/build/core/NodeConstructor.d.ts +4 -2
- package/build/core/NodeConstructor.d.ts.map +1 -1
- package/build/core/NodeConstructor.js +5 -3
- package/build/core/NodeGenerator.js +8 -8
- package/build/core/logger/node/ConsoleLoggerConfigNode.html +20 -61
- package/build/core/logger/node/LokiLoggerConfigNode.d.ts +1 -1
- package/build/core/logger/node/LokiLoggerConfigNode.html +37 -73
- package/build/core/logger/node/LokiLoggerConfigNode.js +1 -1
- package/build/core/logger/node/RestLoggerConfigNode.html +51 -77
- package/build/core/logger/node/RestLoggerConfigNode.js +1 -1
- package/build/core/logger/service/LoggerService.d.ts +1 -1
- package/build/core/logger/service/LoggerService.d.ts.map +1 -1
- package/build/core/logger/service/LoggerService.js +2 -3
- package/build/core/logger/template/LoggerTemplate.d.ts.map +1 -1
- package/build/core/logger/template/LoggerTemplate.html +15 -12
- package/build/core/logger/template/LoggerTemplate.js +1 -2
- package/build/core/metrics/MetricsDecorator.js +2 -2
- package/build/core/metrics/node/CounterMetricConfigNode.html +2 -2
- package/build/core/metrics/node/GaugeMetricConfigNode.html +2 -2
- package/build/core/metrics/node/GaugeMetricConfigNode.js +2 -2
- package/build/core/metrics/node/MetricsConfigNode.html +1 -1
- package/build/core/metrics/node/TimerMetricConfigNode.html +13 -13
- package/build/core/metrics/service/MetricsService.d.ts +1 -1
- package/build/core/metrics/service/MetricsService.js +6 -6
- package/build/core/metrics/template/CounterMetricTemplate.html +1 -1
- package/build/core/metrics/template/GaugeMetricTemplate.html +1 -1
- package/build/core/metrics/template/TimerMetricTemplate.html +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts +57 -0
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts.map +1 -0
- package/build/core/other/node/DelegatedConfigReferenceNode.html +1 -0
- package/build/core/other/node/DelegatedConfigReferenceNode.js +79 -0
- package/build/core/tagging/NodeDescriptionDecorator.js +1 -1
- package/build/core/tagging/service/NodeTypeService.js +1 -1
- package/build/core/ui/template/UIHelperTemplate.d.ts +5 -0
- package/build/core/ui/template/UIHelperTemplate.d.ts.map +1 -0
- package/build/core/ui/template/UIHelperTemplate.html +229 -0
- package/build/core/ui/template/UIHelperTemplate.js +11 -0
- package/build/core/webhook/node/WebhookServerConfigNode.html +5 -5
- package/build/core/webhook/template/WebhookTemplate.html +18 -10
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -1
- package/documentation/ConsoleLoggerConfigNode.png +0 -0
- package/documentation/CounterMetricConfigNode.png +0 -0
- package/documentation/GaugeMetricConfigNode.png +0 -0
- package/documentation/LokiLoggerConfigNode.png +0 -0
- package/documentation/MetricsConfigNode.png +0 -0
- package/documentation/RestLoggerConfigNode.png +0 -0
- package/documentation/TimerMetricConfigNode.png +0 -0
- package/documentation/WebhookNode.png +0 -0
- package/package.json +20 -8
- package/src/GenerateNodes.ts +5 -2
- package/src/core/NodeConstructor.ts +7 -4
- package/src/core/NodeGenerator.ts +8 -8
- package/src/core/logger/node/ConsoleLoggerConfigNode.html +20 -61
- package/src/core/logger/node/LokiLoggerConfigNode.html +37 -73
- package/src/core/logger/node/LokiLoggerConfigNode.ts +2 -2
- package/src/core/logger/node/RestLoggerConfigNode.html +51 -77
- package/src/core/logger/node/RestLoggerConfigNode.ts +1 -1
- package/src/core/logger/service/LoggerService.ts +3 -4
- package/src/core/logger/template/LoggerTemplate.html +15 -12
- package/src/core/logger/template/LoggerTemplate.ts +1 -2
- package/src/core/metrics/MetricsDecorator.ts +2 -2
- package/src/core/metrics/node/CounterMetricConfigNode.html +2 -2
- package/src/core/metrics/node/GaugeMetricConfigNode.html +2 -2
- package/src/core/metrics/node/GaugeMetricConfigNode.ts +2 -2
- package/src/core/metrics/node/MetricsConfigNode.html +1 -1
- package/src/core/metrics/node/MetricsConfigNode.ts +1 -1
- package/src/core/metrics/node/TimerMetricConfigNode.html +13 -13
- package/src/core/metrics/service/MetricsService.ts +6 -6
- package/src/core/metrics/template/CounterMetricTemplate.html +1 -1
- package/src/core/metrics/template/GaugeMetricTemplate.html +1 -1
- package/src/core/metrics/template/TimerMetricTemplate.html +1 -1
- package/src/core/other/node/DelegatedConfigReferenceNode.html +1 -0
- package/src/core/other/node/DelegatedConfigReferenceNode.ts +70 -0
- package/src/core/tagging/NodeDescriptionDecorator.ts +1 -1
- package/src/core/tagging/service/NodeTypeService.ts +1 -1
- package/src/core/ui/template/UIHelperTemplate.html +229 -0
- package/src/core/ui/template/UIHelperTemplate.ts +14 -0
- package/src/core/webhook/node/WebhookServerConfigNode.html +5 -5
- package/src/core/webhook/template/WebhookTemplate.html +18 -10
- package/src/index.ts +3 -1
- package/build/core/logger/node/LoggerConfigNode.d.ts +0 -30
- package/build/core/logger/node/LoggerConfigNode.d.ts.map +0 -1
- package/build/core/logger/node/LoggerConfigNode.html +0 -307
- package/build/core/logger/node/LoggerConfigNode.js +0 -60
- package/src/core/logger/node/LoggerConfigNode.html +0 -307
- package/src/core/logger/node/LoggerConfigNode.ts +0 -95
package/README.md
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
# @theotherwillembotha/node-red-plugincore
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A TypeScript framework for building production-grade Node-RED plugins with built-in support for structured logging, Prometheus metrics, webhook servers, and reusable UI components.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package has two roles:
|
|
6
|
+
|
|
7
|
+
1. **Config nodes** — a set of shared configuration nodes (loggers, metric collectors, webhook server) that are installed into Node-RED and referenced by other nodes in a flow.
|
|
8
|
+
2. **Developer framework** — a TypeScript base library that plugin authors extend to build their own Node-RED nodes, with decorators and templates that wire in logging, metrics, webhooks, and editor UI automatically.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Plugin ecosystem
|
|
13
|
+
|
|
14
|
+
This framework is the foundation for a growing set of Node-RED plugins. The following plugins are currently available:
|
|
15
|
+
|
|
16
|
+
| Plugin | Description |
|
|
17
|
+
|--------|-------------|
|
|
18
|
+
| [@theotherwillembotha/node-red-telemetry](https://github.com/theotherwillembotha/nodered_telemetry) | Ready-to-use flow nodes for structured logging and Prometheus metrics — Logger, Counter, Gauge, and Timer nodes that attach to the config nodes provided by this package. |
|
|
19
|
+
| [@theotherwillembotha/node-red-nginxproxymanager](https://github.com/theotherwillembotha/nodered_nginxproxymanager) | Node-RED nodes for managing Nginx Proxy Manager hosts directly from your flows. Includes a config node that registers as a reverse proxy provider, an Update Host node for creating and updating proxy entries, and a Get Hosts node for retrieving the current host list. |
|
|
20
|
+
|
|
21
|
+
Additional plugins will be listed here as they are published.
|
|
6
22
|
|
|
7
23
|
---
|
|
8
24
|
|
|
@@ -10,41 +26,65 @@ A core framework for building production-grade Node-RED plugins, with built-in s
|
|
|
10
26
|
|
|
11
27
|
### Installation
|
|
12
28
|
|
|
13
|
-
Either use the **Manage Palette** option in the Node-RED editor, or run the following
|
|
29
|
+
Either use the **Manage Palette** option in the Node-RED editor, or run the following in your Node-RED user directory (typically `~/.node-red`):
|
|
14
30
|
|
|
15
31
|
```bash
|
|
16
32
|
npm install @theotherwillembotha/node-red-plugincore
|
|
17
33
|
```
|
|
18
34
|
|
|
35
|
+
This installs the config nodes below and makes them available in your palette. Typically you would also install a plugin such as [node-red-telemetry](https://github.com/theotherwillembotha/nodered_telemetry) to get the actual flow nodes that reference them.
|
|
36
|
+
|
|
19
37
|
### Config nodes
|
|
20
38
|
|
|
21
|
-
|
|
39
|
+
Config nodes are shared resources configured once and referenced across your flow. They appear under their own groups in the palette sidebar.
|
|
22
40
|
|
|
23
41
|
#### Logging
|
|
24
42
|
|
|
25
|
-
Three logger
|
|
43
|
+
Three logger backends are supported. All expose the same interface and are interchangeable — any node built with the `@Logger` decorator can use any of them.
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
**Console Logger** — writes structured log output to stdout via Winston. Ideal for development and containerised deployments that forward stdout to a log aggregator.
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+
**REST Logger** — ships log entries to a remote HTTP/HTTPS endpoint. Supports Basic and API Key authentication.
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
**Loki Logger** — pushes log entries to a Grafana Loki instance via the Loki HTTP API. Supports multi-tenant deployments via the Tenant ID field.
|
|
54
|
+
|
|
55
|
+

|
|
56
|
+
|
|
57
|
+
All three loggers share a **Level** selector (debug, info, warn, error) and a **Template** field — a Handlebars template that controls the shape of each log entry. The default `message:{{msg}}` passes the raw message through; you can customise it to include only the fields you care about.
|
|
32
58
|
|
|
33
59
|
#### Metrics
|
|
34
60
|
|
|
35
|
-
Prometheus-compatible metric collectors. A
|
|
61
|
+
Prometheus-compatible metric collectors. A scrape endpoint (`/metrics`) is provided automatically once any metric node is deployed.
|
|
36
62
|
|
|
37
63
|
| Node | Description |
|
|
38
64
|
|------|-------------|
|
|
65
|
+
| **Metrics Config** | Top-level Prometheus registry. One per deployment. |
|
|
39
66
|
| **Counter Metric** | An ever-increasing counter (e.g. messages processed, errors). |
|
|
40
67
|
| **Gauge Metric** | A value that goes up and down (e.g. queue depth, active connections). |
|
|
41
|
-
| **Timer Metric** | A histogram for measuring durations (e.g. processing time per message). |
|
|
68
|
+
| **Timer Metric** | A histogram or summary for measuring durations (e.g. processing time per message). |
|
|
69
|
+
|
|
70
|
+

|
|
71
|
+
|
|
72
|
+
**Counter** and **Gauge** share the same layout — a name, a description, and an optional reset-on-deploy toggle:
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+

|
|
76
|
+
|
|
77
|
+
The **Timer** config adds a metric type selector (Histogram or Summary) with configurable bucket or percentile strategies:
|
|
78
|
+
|
|
79
|
+

|
|
42
80
|
|
|
43
81
|
#### Webhook Server
|
|
44
82
|
|
|
45
83
|
| Node | Description |
|
|
46
84
|
|------|-------------|
|
|
47
|
-
| **Webhook Server** | Runs an Express v5 HTTP server on a configurable port. Supports reverse proxy configuration
|
|
85
|
+
| **Webhook Server** | Runs an Express v5 HTTP server on a configurable local port. Supports optional reverse proxy configuration so that registered webhook paths know their publicly-visible address. |
|
|
86
|
+
|
|
87
|
+

|
|
48
88
|
|
|
49
89
|
---
|
|
50
90
|
|
|
@@ -53,7 +93,7 @@ Prometheus-compatible metric collectors. A running Prometheus scrape endpoint is
|
|
|
53
93
|
### Prerequisites
|
|
54
94
|
|
|
55
95
|
- Node.js 18+
|
|
56
|
-
- Node-RED
|
|
96
|
+
- Node-RED 4+
|
|
57
97
|
- TypeScript 5+ with `experimentalDecorators` and `emitDecoratorMetadata` enabled
|
|
58
98
|
|
|
59
99
|
### Installation
|
|
@@ -75,7 +115,7 @@ Your `tsconfig.json` must include:
|
|
|
75
115
|
|
|
76
116
|
### Defining a node
|
|
77
117
|
|
|
78
|
-
Extend `BaseNode` and annotate the class with `@NodeDescription`. The decorator registers the node type, its editor HTML file, the palette group it appears in, and any shared templates it
|
|
118
|
+
Extend `BaseNode` (or `ConfigNode` for config nodes) and annotate the class with `@NodeDescription`. The decorator registers the node type, its editor HTML file, the palette group it appears in, and any shared templates it composes in.
|
|
79
119
|
|
|
80
120
|
```typescript
|
|
81
121
|
import {
|
|
@@ -115,30 +155,119 @@ class MyNode extends BaseNode<MyNodeConfig> {
|
|
|
115
155
|
}
|
|
116
156
|
```
|
|
117
157
|
|
|
158
|
+
The `LoggerTemplate` fragment is automatically composed into the node's editor panel, giving the user a logger selector and optional message template override with no additional HTML required.
|
|
159
|
+
|
|
118
160
|
### Available decorators
|
|
119
161
|
|
|
120
162
|
| Decorator | Property type | What it injects |
|
|
121
163
|
|-----------|--------------|-----------------|
|
|
122
164
|
| `@Logger()` | `Log` | Winston logger wired to a user-selected logger config node |
|
|
123
165
|
| `@Metrics({...})` | `CounterMetric` / `GaugeMetric` / `HistogramMetric` | Prometheus metric collector |
|
|
124
|
-
| `@Webhook()` | — | Registers the node with the webhook server |
|
|
125
|
-
| `@onInput()` | method | Wires the method as the Node-RED input message handler |
|
|
166
|
+
| `@Webhook()` | — | Registers the node's routes with the webhook server |
|
|
167
|
+
| `@onInput()` | method | Wires the method as the Node-RED `input` message handler |
|
|
126
168
|
|
|
127
169
|
### Templates
|
|
128
170
|
|
|
129
|
-
Templates bundle reusable UI fragments that compose into any node's editor panel.
|
|
171
|
+
Templates bundle reusable UI fragments that compose into any node's editor panel. Include them in the `templates` array of `@NodeDescription`.
|
|
130
172
|
|
|
131
173
|
| Template | Adds to editor |
|
|
132
174
|
|----------|---------------|
|
|
133
|
-
| `LoggerTemplate` | Logger
|
|
134
|
-
| `MetricsTemplate` | Metrics
|
|
135
|
-
| `
|
|
175
|
+
| `LoggerTemplate` | Logger backend selector and optional message template override |
|
|
176
|
+
| `MetricsTemplate` | Metrics enable toggle and collector reference |
|
|
177
|
+
| `CounterMetricTemplate` | Counter config node reference |
|
|
178
|
+
| `GaugeMetricTemplate` | Gauge config node reference |
|
|
179
|
+
| `TimerMetricTemplate` | Timer config node reference |
|
|
180
|
+
| `WebhookTemplate` | Webhook server reference, path, auth, and reverse proxy config |
|
|
181
|
+
| `UIHelperTemplate` | Global `PluginCore.dialog()` and `PluginCore.table()` UI factories (see below) |
|
|
136
182
|
| `SettingsTemplate` | General settings section |
|
|
137
183
|
| `BasicTemplate` | Base styles shared by all nodes |
|
|
138
184
|
|
|
185
|
+
### UI helpers
|
|
186
|
+
|
|
187
|
+
Including `UIHelperTemplate` in a node's `templates` list injects two client-side factory functions into the Node-RED editor page. Both are available globally as `PluginCore.dialog(...)` and `PluginCore.table(...)` and are styled to match Node-RED's own editor aesthetic.
|
|
188
|
+
|
|
189
|
+
#### `PluginCore.dialog(options)`
|
|
190
|
+
|
|
191
|
+
Opens a modal overlay with a title bar and one or more tabs. Closes on the close button, an overlay click, or Escape.
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
PluginCore.dialog({
|
|
195
|
+
title: "My Plugin — Status",
|
|
196
|
+
tabs: [
|
|
197
|
+
{
|
|
198
|
+
label: "Proxy Hosts",
|
|
199
|
+
render: function($container) {
|
|
200
|
+
$container.append(
|
|
201
|
+
PluginCore.table({
|
|
202
|
+
columns: [
|
|
203
|
+
{ key: "id", label: "ID" },
|
|
204
|
+
{ key: "name", label: "Name" },
|
|
205
|
+
{ key: "enabled", label: "Enabled",
|
|
206
|
+
render: function(v) {
|
|
207
|
+
return $("<span>")
|
|
208
|
+
.addClass(v ? "plugincore-status-enabled"
|
|
209
|
+
: "plugincore-status-disabled")
|
|
210
|
+
.text(v ? "✔ Enabled" : "✘ Disabled");
|
|
211
|
+
}}
|
|
212
|
+
],
|
|
213
|
+
rows: data
|
|
214
|
+
})
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Options:**
|
|
223
|
+
|
|
224
|
+
| Field | Type | Description |
|
|
225
|
+
|-------|------|-------------|
|
|
226
|
+
| `title` | `string` | Heading shown in the dialog title bar |
|
|
227
|
+
| `tabs` | `array` | One or more tab definitions |
|
|
228
|
+
| `tabs[].label` | `string` | Tab heading |
|
|
229
|
+
| `tabs[].render` | `function($container)` | Called with a jQuery element; append content into it |
|
|
230
|
+
|
|
231
|
+
**Returns:** `{ close() }` — call `close()` to dismiss the dialog programmatically.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
#### `PluginCore.table(config)`
|
|
236
|
+
|
|
237
|
+
Returns a styled jQuery `<table>` element ready to append into any container.
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
var $table = PluginCore.table({
|
|
241
|
+
columns: [
|
|
242
|
+
{ key: "id", label: "ID" },
|
|
243
|
+
{ key: "domain", label: "Domain",
|
|
244
|
+
render: function(value, row) { return value.join(", "); } }
|
|
245
|
+
],
|
|
246
|
+
rows: arrayOfObjects
|
|
247
|
+
});
|
|
248
|
+
$container.append($table);
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Config:**
|
|
252
|
+
|
|
253
|
+
| Field | Type | Description |
|
|
254
|
+
|-------|------|-------------|
|
|
255
|
+
| `columns` | `array` | Column definitions |
|
|
256
|
+
| `columns[].key` | `string` | Property name on each row object |
|
|
257
|
+
| `columns[].label` | `string` | Column header text |
|
|
258
|
+
| `columns[].render` | `function(value, row)` | Optional. Return a string or jQuery element for custom cell rendering |
|
|
259
|
+
| `rows` | `object[]` | Data rows |
|
|
260
|
+
|
|
261
|
+
**CSS classes available for cell content:**
|
|
262
|
+
|
|
263
|
+
| Class | Colour | Intended use |
|
|
264
|
+
|-------|--------|-------------|
|
|
265
|
+
| `plugincore-status-enabled` | Green | Enabled / active state |
|
|
266
|
+
| `plugincore-status-disabled` | Red | Disabled / inactive state |
|
|
267
|
+
|
|
139
268
|
### Registering nodes for generation
|
|
140
269
|
|
|
141
|
-
Create a `GenerateNodes.ts` at the root of your `src/` directory. This is the composition root — register every service, template, and node, then call `.generate()` to emit the Node-RED entry files.
|
|
270
|
+
Create a `GenerateNodes.ts` at the root of your `src/` directory. This is the composition root — register every service, template, and node, then call `.generate()` to emit the two Node-RED entry files (`Nodes.js` and `Plugins.js`).
|
|
142
271
|
|
|
143
272
|
```typescript
|
|
144
273
|
import { NodeGenerator } from "@theotherwillembotha/node-red-plugincore";
|
|
@@ -160,11 +289,14 @@ new NodeGenerator("./src/")
|
|
|
160
289
|
process.exit(0);
|
|
161
290
|
```
|
|
162
291
|
|
|
292
|
+
Only register the services and config nodes your plugin actually depends on. You do not need to re-register nodes from this package if your plugin does not expose them directly.
|
|
293
|
+
|
|
163
294
|
### Wiring up package.json
|
|
164
295
|
|
|
165
296
|
```json
|
|
166
297
|
{
|
|
167
298
|
"node-red": {
|
|
299
|
+
"version": ">=4.0.0",
|
|
168
300
|
"nodes": { "my-plugin": "./build/Nodes.js" },
|
|
169
301
|
"plugins": { "my-plugin": "./build/Plugins.js" }
|
|
170
302
|
}
|
|
@@ -174,7 +306,7 @@ process.exit(0);
|
|
|
174
306
|
### Build
|
|
175
307
|
|
|
176
308
|
```bash
|
|
177
|
-
npm run build # clean → tsc →
|
|
309
|
+
npm run build # clean → tsc → generate node files → copy icons
|
|
178
310
|
npm run clean # remove build/
|
|
179
311
|
```
|
|
180
312
|
|
package/build/GenerateNodes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const DelegatedConfigReferenceNode_js_1 = require("./core/other/node/DelegatedConfigReferenceNode.js");
|
|
3
4
|
const NodeTypeService_js_1 = require("./core/tagging/service/NodeTypeService.js");
|
|
4
5
|
const index_js_1 = require("./index.js");
|
|
5
6
|
const index_js_2 = require("./index.js");
|
|
@@ -22,7 +23,9 @@ new index_js_1.NodeGenerator("./src/core/")
|
|
|
22
23
|
.registerTemplate(index_js_4.GaugeMetricTemplate)
|
|
23
24
|
.registerTemplate(index_js_1.TimerMetricTemplate)
|
|
24
25
|
.registerTemplate(index_js_2.WebhookTemplate)
|
|
26
|
+
.registerTemplate(index_js_1.UIHelperTemplate)
|
|
25
27
|
// nodes
|
|
28
|
+
.registerNode(DelegatedConfigReferenceNode_js_1.DelegatedConfigReferenceNode)
|
|
26
29
|
.registerNode(index_js_1.ConsoleLoggerConfigNode)
|
|
27
30
|
.registerNode(index_js_1.RestLoggerConfigNode)
|
|
28
31
|
.registerNode(index_js_1.LokiLoggerConfigNode)
|