@node-red/editor-api 4.0.0-beta.1 → 4.0.0-beta.3

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.
@@ -91,6 +91,7 @@ module.exports = {
91
91
  // Plugins
92
92
  adminApp.get("/plugins", needsPermission("plugins.read"), plugins.getAll, apiUtil.errorHandler);
93
93
  adminApp.get("/plugins/messages", needsPermission("plugins.read"), plugins.getCatalogs, apiUtil.errorHandler);
94
+ adminApp.get(/^\/plugins\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,needsPermission("plugins.read"),plugins.getConfig,apiUtil.errorHandler);
94
95
 
95
96
  adminApp.get("/diagnostics", needsPermission("diagnostics.read"), diagnostics.getReport, apiUtil.errorHandler);
96
97
 
@@ -40,5 +40,31 @@ module.exports = {
40
40
  console.log(err.stack);
41
41
  apiUtils.rejectHandler(req,res,err);
42
42
  })
43
+ },
44
+ getConfig: function(req, res) {
45
+
46
+ let opts = {
47
+ user: req.user,
48
+ module: req.params[0],
49
+ req: apiUtils.getRequestLogObject(req)
50
+ }
51
+
52
+ if (req.get("accept") === "application/json") {
53
+ runtimeAPI.nodes.getNodeInfo(opts.module).then(function(result) {
54
+ res.send(result);
55
+ }).catch(function(err) {
56
+ apiUtils.rejectHandler(req,res,err);
57
+ })
58
+ } else {
59
+ opts.lang = apiUtils.determineLangFromHeaders(req.acceptsLanguages());
60
+ if (/[^0-9a-z=\-\*]/i.test(opts.lang)) {
61
+ opts.lang = "en-US";
62
+ }
63
+ runtimeAPI.plugins.getPluginConfig(opts).then(function(result) {
64
+ return res.send(result);
65
+ }).catch(function(err) {
66
+ apiUtils.rejectHandler(req,res,err);
67
+ })
68
+ }
43
69
  }
44
70
  };
package/lib/auth/index.js CHANGED
@@ -205,9 +205,10 @@ function genericStrategy(adminApp,strategy) {
205
205
  passport.use(new strategy.strategy(options, verify));
206
206
 
207
207
  adminApp.get('/auth/strategy',
208
- passport.authenticate(strategy.name, {session:false,
208
+ passport.authenticate(strategy.name, {
209
+ session:false,
209
210
  failureMessage: true,
210
- failureRedirect: settings.httpAdminRoot
211
+ failureRedirect: settings.httpAdminRoot + '?session_message=Login Failed'
211
212
  }),
212
213
  completeGenerateStrategyAuth,
213
214
  handleStrategyError
@@ -221,7 +222,7 @@ function genericStrategy(adminApp,strategy) {
221
222
  passport.authenticate(strategy.name, {
222
223
  session:false,
223
224
  failureMessage: true,
224
- failureRedirect: settings.httpAdminRoot
225
+ failureRedirect: settings.httpAdminRoot + '?session_message=Login Failed'
225
226
  }),
226
227
  completeGenerateStrategyAuth,
227
228
  handleStrategyError
@@ -77,6 +77,53 @@ function CommsConnection(ws, user) {
77
77
  log.trace("comms.close "+self.session);
78
78
  removeActiveConnection(self);
79
79
  });
80
+
81
+ const handleAuthPacket = function(msg) {
82
+ Tokens.get(msg.auth).then(function(client) {
83
+ if (client) {
84
+ Users.get(client.user).then(function(user) {
85
+ if (user) {
86
+ self.user = user;
87
+ log.audit({event: "comms.auth",user:self.user});
88
+ completeConnection(msg, client.scope,msg.auth,true);
89
+ } else {
90
+ log.audit({event: "comms.auth.fail"});
91
+ completeConnection(msg, null,null,false);
92
+ }
93
+ });
94
+ } else {
95
+ Users.tokens(msg.auth).then(function(user) {
96
+ if (user) {
97
+ self.user = user;
98
+ log.audit({event: "comms.auth",user:self.user});
99
+ completeConnection(msg, user.permissions,msg.auth,true);
100
+ } else {
101
+ log.audit({event: "comms.auth.fail"});
102
+ completeConnection(msg, null,null,false);
103
+ }
104
+ });
105
+ }
106
+ });
107
+ }
108
+ const completeConnection = function(msg, userScope, session, sendAck) {
109
+ try {
110
+ if (!userScope || !Permissions.hasPermission(userScope,"status.read")) {
111
+ ws.send(JSON.stringify({auth:"fail"}));
112
+ ws.close();
113
+ } else {
114
+ pendingAuth = false;
115
+ addActiveConnection(self);
116
+ self.token = msg.auth;
117
+ if (sendAck) {
118
+ ws.send(JSON.stringify({auth:"ok"}));
119
+ }
120
+ }
121
+ } catch(err) {
122
+ console.log(err.stack);
123
+ // Just in case the socket closes before we attempt
124
+ // to send anything.
125
+ }
126
+ }
80
127
  ws.on('message', function(data,flags) {
81
128
  var msg = null;
82
129
  try {
@@ -86,68 +133,34 @@ function CommsConnection(ws, user) {
86
133
  return;
87
134
  }
88
135
  if (!pendingAuth) {
89
- if (msg.subscribe) {
136
+ if (msg.auth) {
137
+ handleAuthPacket(msg)
138
+ } else if (msg.subscribe) {
90
139
  self.subscribe(msg.subscribe);
91
140
  // handleRemoteSubscription(ws,msg.subscribe);
141
+ } else if (msg.topic) {
142
+ runtimeAPI.comms.receive({
143
+ user: self.user,
144
+ client: self,
145
+ topic: msg.topic,
146
+ data: msg.data
147
+ })
92
148
  }
93
149
  } else {
94
- var completeConnection = function(userScope,session,sendAck) {
95
- try {
96
- if (!userScope || !Permissions.hasPermission(userScope,"status.read")) {
97
- ws.send(JSON.stringify({auth:"fail"}));
98
- ws.close();
99
- } else {
100
- pendingAuth = false;
101
- addActiveConnection(self);
102
- self.token = msg.auth;
103
- if (sendAck) {
104
- ws.send(JSON.stringify({auth:"ok"}));
105
- }
106
- }
107
- } catch(err) {
108
- console.log(err.stack);
109
- // Just in case the socket closes before we attempt
110
- // to send anything.
111
- }
112
- }
113
150
  if (msg.auth) {
114
- Tokens.get(msg.auth).then(function(client) {
115
- if (client) {
116
- Users.get(client.user).then(function(user) {
117
- if (user) {
118
- self.user = user;
119
- log.audit({event: "comms.auth",user:self.user});
120
- completeConnection(client.scope,msg.auth,true);
121
- } else {
122
- log.audit({event: "comms.auth.fail"});
123
- completeConnection(null,null,false);
124
- }
125
- });
126
- } else {
127
- Users.tokens(msg.auth).then(function(user) {
128
- if (user) {
129
- self.user = user;
130
- log.audit({event: "comms.auth",user:self.user});
131
- completeConnection(user.permissions,msg.auth,true);
132
- } else {
133
- log.audit({event: "comms.auth.fail"});
134
- completeConnection(null,null,false);
135
- }
136
- });
137
- }
138
- });
151
+ handleAuthPacket(msg)
139
152
  } else {
140
153
  if (anonymousUser) {
141
154
  log.audit({event: "comms.auth",user:anonymousUser});
142
155
  self.user = anonymousUser;
143
- completeConnection(anonymousUser.permissions,null,false);
156
+ completeConnection(msg, anonymousUser.permissions, null, false);
144
157
  //TODO: duplicated code - pull non-auth message handling out
145
158
  if (msg.subscribe) {
146
159
  self.subscribe(msg.subscribe);
147
160
  }
148
161
  } else {
149
162
  log.audit({event: "comms.auth.fail"});
150
- completeConnection(null,null,false);
163
+ completeConnection(msg, null,null,false);
151
164
  }
152
165
  }
153
166
  }
@@ -233,6 +233,10 @@ module.exports = {
233
233
  themeSettings.projects = theme.projects;
234
234
  }
235
235
 
236
+ if (theme.hasOwnProperty("multiplayer")) {
237
+ themeSettings.multiplayer = theme.multiplayer;
238
+ }
239
+
236
240
  if (theme.hasOwnProperty("keymap")) {
237
241
  themeSettings.keymap = theme.keymap;
238
242
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/editor-api",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./lib/index.js",
6
6
  "repository": {
@@ -16,14 +16,14 @@
16
16
  }
17
17
  ],
18
18
  "dependencies": {
19
- "@node-red/util": "4.0.0-beta.1",
20
- "@node-red/editor-client": "4.0.0-beta.1",
19
+ "@node-red/util": "4.0.0-beta.3",
20
+ "@node-red/editor-client": "4.0.0-beta.3",
21
21
  "bcryptjs": "2.4.3",
22
22
  "body-parser": "1.20.2",
23
23
  "clone": "2.1.2",
24
24
  "cors": "2.8.5",
25
25
  "express-session": "1.17.3",
26
- "express": "4.18.2",
26
+ "express": "4.19.2",
27
27
  "memorystore": "1.6.7",
28
28
  "mime": "3.0.0",
29
29
  "multer": "1.4.5-lts.1",