@flowfuse/nr-assistant 0.12.0 → 0.12.1-2f8cedb-202604150858.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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@flowfuse/nr-assistant",
3
- "version": "0.12.0",
3
+ "version": "0.12.1-2f8cedb-202604150858.0",
4
4
  "description": "FlowFuse Node-RED Expert plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "mocha --exit \"test/**/*.test.js\"",
8
- "lint": "eslint -c .eslintrc --ext js,html \"*.js\" \"*.html\"",
9
- "lint:fix": "eslint -c .eslintrc --ext js,html \"*.js\" \"*.html\" --fix",
8
+ "lint": "eslint -c .eslintrc --ext js,html \"**/*.js\" \"**/*.html\"",
9
+ "lint:fix": "eslint -c .eslintrc --ext js,html \"**/*.js\" \"**/*.html\" --fix",
10
10
  "test:cov": "npx nyc mocha \"test/**/*.test.js\" && npx nyc report --reporter=html",
11
11
  "test:cov:view": "npx open-cli coverage/index.html"
12
12
  },
@@ -6,9 +6,12 @@ const GET_NODES = 'automation/get-nodes'
6
6
  const EDIT_NODE = 'automation/open-node-edit'
7
7
  const SEARCH = 'automation/search'
8
8
  const ADD_FLOW_TAB = 'automation/add-flow-tab'
9
+ const UPDATE_NODE = 'automation/update-node'
10
+ const SHOW_WORKSPACE = 'automation/show-workspace'
11
+ const GET_FLOW = 'automation/get-workspace-nodes'
9
12
 
10
13
  /**
11
- * @typedef {SELECT_NODES|GET_NODES|EDIT_NODE|SEARCH|ADD_FLOW_TAB} ExpertAutomationsActionsEnum
14
+ * @typedef {SELECT_NODES|GET_NODES|EDIT_NODE|SEARCH|ADD_FLOW_TAB|UPDATE_NODE|SHOW_WORKSPACE|GET_FLOW} ExpertAutomationsActionsEnum
12
15
  */
13
16
 
14
17
  export class ExpertAutomations extends ExpertActionsInterface {
@@ -97,6 +100,28 @@ export class ExpertAutomations extends ExpertActionsInterface {
97
100
  }
98
101
  }
99
102
  }
103
+ },
104
+ [UPDATE_NODE]: {
105
+ params: {
106
+ type: 'object',
107
+ properties: {
108
+ id: { type: 'string', description: 'ID of the node to update' },
109
+ properties: { type: 'object', description: 'Key-value pairs to merge into the node object' }
110
+ },
111
+ required: ['id', 'properties']
112
+ }
113
+ },
114
+ [SHOW_WORKSPACE]: {
115
+ params: {
116
+ type: 'object',
117
+ properties: {
118
+ id: { type: 'string', description: 'ID of the flow tab or subflow to navigate to' }
119
+ },
120
+ required: ['id']
121
+ }
122
+ },
123
+ [GET_FLOW]: {
124
+ params: null
100
125
  }
101
126
  })
102
127
 
@@ -229,6 +254,51 @@ export class ExpertAutomations extends ExpertActionsInterface {
229
254
  return newTab
230
255
  }
231
256
 
257
+ /**
258
+ * Update properties of an existing node in place.
259
+ * @param {string} id - node ID
260
+ * @param {Object} properties - key-value pairs to merge into the node
261
+ */
262
+ updateNode (id, properties) {
263
+ const node = this.RED.nodes.node(id)
264
+ if (!node) throw new Error(`Node ${id} not found`)
265
+ const changes = {}
266
+ for (const key in properties) {
267
+ if (Object.prototype.hasOwnProperty.call(properties, key)) {
268
+ changes[key] = node[key]
269
+ }
270
+ }
271
+ const wasChanged = node.changed
272
+ Object.assign(node, properties)
273
+ this.RED.history.push({ t: 'edit', node, changes, changed: wasChanged, dirty: this.RED.nodes.dirty() })
274
+ node.changed = true
275
+ node.dirty = true
276
+ this.RED.nodes.dirty(true)
277
+ if (this.RED.editor?.validateNode) {
278
+ this.RED.editor.validateNode(node)
279
+ }
280
+ this.RED.view.redraw()
281
+ }
282
+
283
+ /**
284
+ * Read the live canvas state (including undeployed edits) and return it.
285
+ * Uses Node-RED's built-in export to get the complete node set.
286
+ * @returns {Object[]} full flows array (tabs + nodes + config nodes)
287
+ */
288
+ getFlow () {
289
+ return this.RED.nodes.createCompleteNodeSet({ credentials: false })
290
+ }
291
+
292
+ /**
293
+ * Navigate to a workspace tab, validating it exists first.
294
+ * @param {string} id - workspace ID to show
295
+ */
296
+ showWorkspace (id) {
297
+ const ws = this.RED.nodes.workspace(id)
298
+ if (!ws) throw new Error(`Workspace ${id} not found`)
299
+ this.RED.workspaces.show(id)
300
+ }
301
+
232
302
  get supportedActions () {
233
303
  return this.actions
234
304
  }
@@ -300,6 +370,20 @@ export class ExpertAutomations extends ExpertActionsInterface {
300
370
  }
301
371
  break
302
372
 
373
+ case UPDATE_NODE:
374
+ this.updateNode(params.id, params.properties)
375
+ result.success = true
376
+ break
377
+
378
+ case SHOW_WORKSPACE:
379
+ this.showWorkspace(params.id)
380
+ result.success = true
381
+ break
382
+
383
+ case GET_FLOW:
384
+ result.flows = this.getFlow()
385
+ result.success = true
386
+ break
303
387
  default:
304
388
  result.handled = false
305
389
  result.success = false