@node-red/runtime 3.0.2 → 3.1.0-beta.1

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.
@@ -89,10 +89,16 @@ var api = module.exports = {
89
89
 
90
90
  if (!runtime.settings.disableEditor) {
91
91
  safeSettings.context = runtime.nodes.listContextStores();
92
- if (runtime.settings.editorTheme && runtime.settings.editorTheme.codeEditor) {
93
- safeSettings.codeEditor = runtime.settings.editorTheme.codeEditor || {};
94
- safeSettings.codeEditor.lib = safeSettings.codeEditor.lib || "monaco";
95
- safeSettings.codeEditor.options = safeSettings.codeEditor.options || {};
92
+ if (runtime.settings.editorTheme) {
93
+ if (runtime.settings.editorTheme.codeEditor) {
94
+ safeSettings.codeEditor = runtime.settings.editorTheme.codeEditor || {};
95
+ safeSettings.codeEditor.lib = safeSettings.codeEditor.lib || "monaco";
96
+ safeSettings.codeEditor.options = safeSettings.codeEditor.options || {};
97
+ }
98
+ if (runtime.settings.editorTheme.markdownEditor) {
99
+ safeSettings.markdownEditor = runtime.settings.editorTheme.markdownEditor || {};
100
+ safeSettings.markdownEditor.mermaid = safeSettings.markdownEditor.mermaid || { enabled: true };
101
+ }
96
102
  }
97
103
  safeSettings.libraries = runtime.library.getLibraries();
98
104
  if (util.isArray(runtime.settings.paletteCategories)) {
@@ -641,6 +641,7 @@ function getFlow(id) {
641
641
  if (node.type === 'link out') {
642
642
  delete node.wires;
643
643
  }
644
+ delete node.credentials;
644
645
  return node;
645
646
  })
646
647
  }
@@ -648,7 +649,10 @@ function getFlow(id) {
648
649
  if (flow.configs) {
649
650
  var configIds = Object.keys(flow.configs);
650
651
  result.configs = configIds.map(function(configId) {
651
- return clone(flow.configs[configId]);
652
+ const node = clone(flow.configs[configId]);
653
+ delete node.credentials;
654
+ return node
655
+
652
656
  })
653
657
  if (result.configs.length === 0) {
654
658
  delete result.configs;
@@ -660,12 +664,16 @@ function getFlow(id) {
660
664
  var subflow = clone(flow.subflows[subflowId]);
661
665
  var nodeIds = Object.keys(subflow.nodes);
662
666
  subflow.nodes = nodeIds.map(function(id) {
663
- return subflow.nodes[id];
667
+ const node = clone(subflow.nodes[id])
668
+ delete node.credentials
669
+ return node
664
670
  });
665
671
  if (subflow.configs) {
666
672
  var configIds = Object.keys(subflow.configs);
667
673
  subflow.configs = configIds.map(function(id) {
668
- return subflow.configs[id];
674
+ const node = clone(subflow.configs[id])
675
+ delete node.credentials
676
+ return node
669
677
  })
670
678
  }
671
679
  delete subflow.instances;
@@ -777,6 +785,16 @@ const flowAPI = {
777
785
  }
778
786
 
779
787
 
788
+ function getGlobalConfig() {
789
+ let gconf = null;
790
+ eachNode((n) => {
791
+ if (n.type === "global-config") {
792
+ gconf = n;
793
+ }
794
+ });
795
+ return gconf;
796
+ }
797
+
780
798
  module.exports = {
781
799
  init: init,
782
800
 
@@ -790,6 +808,9 @@ module.exports = {
790
808
  get:getNode,
791
809
  eachNode: eachNode,
792
810
 
811
+
812
+ getGlobalConfig: getGlobalConfig,
813
+
793
814
  /**
794
815
  * Gets the current flow configuration
795
816
  */
package/lib/flows/util.js CHANGED
@@ -18,7 +18,9 @@ var redUtil = require("@node-red/util").util;
18
18
  var Log = require("@node-red/util").log;
19
19
  var subflowInstanceRE = /^subflow:(.+)$/;
20
20
  var typeRegistry = require("@node-red/registry");
21
+ const credentials = require("../nodes/credentials");
21
22
 
23
+ let _runtime = null;
22
24
 
23
25
  var envVarExcludes = {};
24
26
 
@@ -265,15 +267,55 @@ function parseConfig(config) {
265
267
  return flow;
266
268
  }
267
269
 
270
+ function getGlobalEnv(name) {
271
+ const nodes = _runtime.nodes;
272
+ if (!nodes) {
273
+ return null;
274
+ }
275
+ const gconf = nodes.getGlobalConfig();
276
+ const env = gconf ? gconf.env : null;
277
+
278
+ if (env) {
279
+ const cred = (gconf ? credentials.get(gconf.id) : null) || {
280
+ map: {}
281
+ };
282
+ const map = cred.map;
283
+
284
+ for (let i = 0; i < env.length; i++) {
285
+ const item = env[i];
286
+ if (item.name === name) {
287
+ if (item.type === "cred") {
288
+ return {
289
+ name: name,
290
+ value: map[name],
291
+ type: "cred"
292
+ };
293
+ }
294
+ return item;
295
+ }
296
+ }
297
+ }
298
+ return null;
299
+ }
300
+
268
301
  module.exports = {
269
302
  init: function(runtime) {
303
+ _runtime = runtime;
270
304
  envVarExcludes = {};
271
305
  if (runtime.settings.hasOwnProperty('envVarExcludes') && Array.isArray(runtime.settings.envVarExcludes)) {
272
306
  runtime.settings.envVarExcludes.forEach(v => envVarExcludes[v] = true);
273
307
  }
274
308
  },
275
309
  getEnvVar: function(k) {
276
- return !envVarExcludes[k]?process.env[k]:undefined
310
+ if (!envVarExcludes[k]) {
311
+ const item = getGlobalEnv(k);
312
+ if (item) {
313
+ const val = redUtil.evaluateNodeProperty(item.value, item.type, null, null, null);
314
+ return val;
315
+ }
316
+ return process.env[k];
317
+ }
318
+ return undefined;
277
319
  },
278
320
  diffNodes: diffNodes,
279
321
  mapEnvVarProperties: mapEnvVarProperties,
package/lib/index.js CHANGED
@@ -161,6 +161,8 @@ function start() {
161
161
  for (i=0;i<nodeErrors.length;i+=1) {
162
162
  if (nodeErrors[i].err.code === "type_already_registered") {
163
163
  log.warn("["+nodeErrors[i].id+"] "+log._("server.type-already-registered",{type:nodeErrors[i].err.details.type,module: nodeErrors[i].err.details.moduleA}));
164
+ } else if (nodeErrors[i].err.code === "set_has_no_types") {
165
+ log.warn("["+nodeErrors[i].id+"] "+log._("server.set-has-no-types", nodeErrors[i].err.details));
164
166
  } else {
165
167
  log.warn("["+nodeErrors[i].id+"] "+nodeErrors[i].err);
166
168
  }
package/lib/nodes/Node.js CHANGED
@@ -373,6 +373,11 @@ Node.prototype.send = function(msg) {
373
373
  if (msg === null || typeof msg === "undefined") {
374
374
  return;
375
375
  } else if (!util.isArray(msg)) {
376
+ // A single message has been passed in
377
+ if (typeof msg !== 'object') {
378
+ this.error(Log._("nodes.flow.non-message-returned", { type: typeof msg }));
379
+ return
380
+ }
376
381
  if (this._wire) {
377
382
  // A single message and a single wire on output 0
378
383
  // TODO: pre-load flows.get calls - cannot do in constructor
@@ -425,27 +430,31 @@ Node.prototype.send = function(msg) {
425
430
  for (k = 0; k < msgs.length; k++) {
426
431
  var m = msgs[k];
427
432
  if (m !== null && m !== undefined) {
428
- if (!m._msgid) {
429
- hasMissingIds = true;
430
- }
431
- /* istanbul ignore else */
432
- if (!sentMessageId) {
433
- sentMessageId = m._msgid;
433
+ if (typeof m !== 'object') {
434
+ this.error(Log._("nodes.flow.non-message-returned", { type: typeof m }));
435
+ } else {
436
+ if (!m._msgid) {
437
+ hasMissingIds = true;
438
+ }
439
+ /* istanbul ignore else */
440
+ if (!sentMessageId) {
441
+ sentMessageId = m._msgid;
442
+ }
443
+ sendEvents.push({
444
+ msg: m,
445
+ source: {
446
+ id: this.id,
447
+ node: this,
448
+ port: i
449
+ },
450
+ destination: {
451
+ id: wires[j],
452
+ node: undefined
453
+ },
454
+ cloneMessage: msgSent
455
+ });
456
+ msgSent = true;
434
457
  }
435
- sendEvents.push({
436
- msg: m,
437
- source: {
438
- id: this.id,
439
- node: this,
440
- port: i
441
- },
442
- destination: {
443
- id: wires[j],
444
- node: undefined
445
- },
446
- cloneMessage: msgSent
447
- });
448
- msgSent = true;
449
458
  }
450
459
  }
451
460
  }
@@ -383,6 +383,11 @@ var api = module.exports = {
383
383
  }
384
384
  }
385
385
  }
386
+ } else if (nodeType === "global-config") {
387
+ if (JSON.stringify(savedCredentials.map) !== JSON.stringify(newCreds.map)) {
388
+ savedCredentials.map = newCreds.map;
389
+ dirty = true;
390
+ }
386
391
  } else {
387
392
  var dashedType = nodeType.replace(/\s+/g, '-');
388
393
  var definition = credentialsDef[dashedType];
@@ -205,6 +205,7 @@ module.exports = {
205
205
  getNode: flows.get,
206
206
  eachNode: flows.eachNode,
207
207
  getContext: context.get,
208
+ getGlobalConfig: flows.getGlobalConfig,
208
209
 
209
210
  clearContext: context.clear,
210
211
 
@@ -18,7 +18,7 @@ var i18n = require("@node-red/util").i18n;
18
18
 
19
19
  module.exports = {
20
20
  "package.json": function(project) {
21
- var package = {
21
+ var packageDetails = {
22
22
  "name": project.name,
23
23
  "description": project.summary||i18n._("storage.localfilesystem.projects.summary"),
24
24
  "version": "0.0.1",
@@ -30,11 +30,11 @@ module.exports = {
30
30
  };
31
31
  if (project.files) {
32
32
  if (project.files.flow) {
33
- package['node-red'].settings.flowFile = project.files.flow;
34
- package['node-red'].settings.credentialsFile = project.files.credentials;
33
+ packageDetails['node-red'].settings.flowFile = project.files.flow;
34
+ packageDetails['node-red'].settings.credentialsFile = project.files.credentials;
35
35
  }
36
36
  }
37
- return JSON.stringify(package,"",4);
37
+ return JSON.stringify(packageDetails,"",4);
38
38
  },
39
39
  "README.md": function(project) {
40
40
  var content = project.name+"\n"+("=".repeat(project.name.length))+"\n\n";
@@ -71,6 +71,8 @@ function runGitCommand(args,cwd,env,emit) {
71
71
  err.code = "git_missing_user";
72
72
  } else if (/name consists only of disallowed characters/i.test(stderr)) {
73
73
  err.code = "git_missing_user";
74
+ } else if (/nothing (add )?to commit/i.test(stdout)) {
75
+ return stdout;
74
76
  }
75
77
  throw err;
76
78
  })
@@ -106,7 +108,7 @@ function runGitCommandWithSSHCommand(args,cwd,auth,emit) {
106
108
  commandEnv.GIT_SSH = path.join(__dirname,"node-red-ssh.sh");
107
109
  commandEnv.NODE_RED_KEY_FILE=auth.key_path;
108
110
  // GIT_SSH_COMMAND - added in git 2.3.0
109
- commandEnv.GIT_SSH_COMMAND = "ssh -i " + auth.key_path + " -F /dev/null";
111
+ commandEnv.GIT_SSH_COMMAND = "ssh -i \"" + auth.key_path + "\" -F /dev/null";
110
112
  // console.log('commandEnv:', commandEnv);
111
113
  return runGitCommand(args,cwd,commandEnv,emit).then( result => {
112
114
  rs.close();
@@ -419,7 +421,10 @@ module.exports = {
419
421
  });
420
422
  },
421
423
  initRepo: function(cwd) {
422
- return runGitCommand(["init"],cwd);
424
+ var args = ["init", "--initial-branch", "main"];
425
+ return runGitCommand(args, cwd).catch(function () {
426
+ return runGitCommand(["init"], cwd);
427
+ });
423
428
  },
424
429
  setUpstream: function(cwd,remoteBranch) {
425
430
  var args = ["branch","--set-upstream-to",remoteBranch];
File without changes
@@ -20,6 +20,7 @@
20
20
  "errors-help": "Run with -v for details",
21
21
  "missing-modules": "Missing node modules:",
22
22
  "node-version-mismatch": "Node module cannot be loaded on this version. Requires: __version__ ",
23
+ "set-has-no-types": "Set does not have any types. name: '__name__', module: '__module__', file: '__file__'",
23
24
  "type-already-registered": "'__type__' already registered by module __module__",
24
25
  "removing-modules": "Removing modules from config",
25
26
  "added-types": "Added node types:",
@@ -134,7 +135,8 @@
134
135
  "flow": {
135
136
  "unknown-type": "Unknown type: __type__",
136
137
  "missing-types": "missing types",
137
- "error-loop": "Message exceeded maximum number of catches"
138
+ "error-loop": "Message exceeded maximum number of catches",
139
+ "non-message-returned": "Node tried to send a message of type __type__"
138
140
  },
139
141
  "index": {
140
142
  "unrecognised-id": "Unrecognised id: __id__",
@@ -20,6 +20,7 @@
20
20
  "errors-help": "詳細は -v を指定して実行してください",
21
21
  "missing-modules": "不足しているノードモジュール:",
22
22
  "node-version-mismatch": "ノードモジュールはこのバージョンではロードできません。必要なバージョン: __version__ ",
23
+ "set-has-no-types": "セットに型がありません。 名前: '__name__', モジュール: '__module__', ファイル: '__file__'",
23
24
  "type-already-registered": "'__type__' はモジュール __module__ で登録済みです",
24
25
  "removing-modules": "設定からモジュールを削除します",
25
26
  "added-types": "追加したノード:",
@@ -134,7 +135,8 @@
134
135
  "flow": {
135
136
  "unknown-type": "不明なノード: __type__",
136
137
  "missing-types": "欠落したノード",
137
- "error-loop": "メッセージの例外補足回数が最大値を超えました"
138
+ "error-loop": "メッセージの例外補足回数が最大値を超えました",
139
+ "non-message-returned": "ノードが __type__ 型のメッセージの送信を試みました"
138
140
  },
139
141
  "index": {
140
142
  "unrecognised-id": "不明なID: __id__",
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/runtime",
3
- "version": "3.0.2",
3
+ "version": "3.1.0-beta.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./lib/index.js",
6
6
  "repository": {
@@ -16,11 +16,11 @@
16
16
  }
17
17
  ],
18
18
  "dependencies": {
19
- "@node-red/registry": "3.0.2",
20
- "@node-red/util": "3.0.2",
21
- "async-mutex": "0.3.2",
19
+ "@node-red/registry": "3.1.0-beta.1",
20
+ "@node-red/util": "3.1.0-beta.1",
21
+ "async-mutex": "0.4.0",
22
22
  "clone": "2.1.2",
23
- "express": "4.18.1",
23
+ "express": "4.18.2",
24
24
  "fs-extra": "10.1.0",
25
25
  "json-stringify-safe": "5.0.1"
26
26
  }
package/restart.js DELETED
File without changes