From 3f604e9d93d8c0e08580d728a8761268360d5e8f Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 21 Jun 2023 14:20:23 +0100 Subject: [PATCH 1/2] Adds optional callback to env.get in function node --- .../node_modules/@node-red/nodes/core/function/10-function.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/10-function.js b/packages/node_modules/@node-red/nodes/core/function/10-function.js index b84ee8571..b69f6eeed 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-function.js +++ b/packages/node_modules/@node-red/nodes/core/function/10-function.js @@ -235,8 +235,8 @@ module.exports = function(RED) { } }, env: { - get: function(envVar) { - return RED.util.getSetting(node, envVar); + get: function(envVar, callback) { + return RED.util.getSetting(node, envVar, node._flow, callback); } }, setTimeout: function () { From 4d9fcaeebfb3fb3e8e60f1feea7b7e042c2323e1 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 21 Jun 2023 15:00:27 +0100 Subject: [PATCH 2/2] Update env.get type hint --- .../editor-client/src/types/node-red/func.d.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts b/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts index 59f8a8bd7..8544439d9 100644 --- a/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts +++ b/packages/node_modules/@node-red/editor-client/src/types/node-red/func.d.ts @@ -281,4 +281,21 @@ declare class env { * ```const flowName = env.get("NR_FLOW_NAME");``` */ static get(name:string) :any; + /** + * Get an environment variable value (asynchronous). + * + * Predefined node-red variables... + * * `NR_NODE_ID` - the ID of the node + * * `NR_NODE_NAME` - the Name of the node + * * `NR_NODE_PATH` - the Path of the node + * * `NR_GROUP_ID` - the ID of the containing group + * * `NR_GROUP_NAME` - the Name of the containing group + * * `NR_FLOW_ID` - the ID of the flow the node is on + * * `NR_FLOW_NAME` - the Name of the flow the node is on + * @param name Name of the environment variable to get + * @param callback Callback function (`(err,value) => {}`) + * @example + * ```const flowName = env.get("NR_FLOW_NAME");``` + */ + static get(name:string, callback: Function) :void; }