@soundworks/core 3.1.0-beta.3 → 3.1.0-beta.6
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/common/ParameterBag.js +1 -6
- package/common/SharedState.js +13 -2
- package/common/SharedStatePrivate.js +7 -1
- package/package.json +1 -1
- package/server/Server.js +41 -3
- package/server/utils/logger.js +24 -8
package/common/ParameterBag.js
CHANGED
|
@@ -488,12 +488,7 @@ class ParameterBag {
|
|
|
488
488
|
|
|
489
489
|
const currentValue = this._values[name];
|
|
490
490
|
const updated = !(0, _fastDeepEqual.default)(currentValue, value);
|
|
491
|
-
this._values[name] = value;
|
|
492
|
-
|
|
493
|
-
if (def.event === true) {
|
|
494
|
-
this._values[name] = null;
|
|
495
|
-
} // return tuple so that the state manager can handle the `filterChange` option
|
|
496
|
-
|
|
491
|
+
this._values[name] = value; // return tuple so that the state manager can handle the `filterChange` option
|
|
497
492
|
|
|
498
493
|
return [value, updated];
|
|
499
494
|
}
|
package/common/SharedState.js
CHANGED
|
@@ -187,7 +187,18 @@ ${JSON.stringify(initValues, null, 2)}`);
|
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
await Promise.all(promises);
|
|
190
|
+
await Promise.all(promises); // reset events to null after propagation of all listeners
|
|
191
|
+
|
|
192
|
+
for (let name in newValues) {
|
|
193
|
+
const {
|
|
194
|
+
event
|
|
195
|
+
} = this._parameters.getSchema(name);
|
|
196
|
+
|
|
197
|
+
if (event) {
|
|
198
|
+
this._parameters.set(name, null);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
191
202
|
return newValues;
|
|
192
203
|
}
|
|
193
204
|
/**
|
|
@@ -255,7 +266,7 @@ ${JSON.stringify(initValues, null, 2)}`);
|
|
|
255
266
|
|
|
256
267
|
const [newValue, changed] = this._parameters.set(name, updates[name]);
|
|
257
268
|
|
|
258
|
-
if (changed || filterChange === false) {
|
|
269
|
+
if (changed || filterChange === false || event) {
|
|
259
270
|
immediateOldValues[name] = oldValue;
|
|
260
271
|
immediateNewValues[name] = newValue;
|
|
261
272
|
propagateNow = true;
|
|
@@ -81,8 +81,14 @@ class SharedStatePrivate {
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
const {
|
|
84
|
+
event,
|
|
84
85
|
filterChange
|
|
85
|
-
} = this._parameters.getSchema(name);
|
|
86
|
+
} = this._parameters.getSchema(name); // if event type reset internal value to null
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if (event) {
|
|
90
|
+
this._parameters.set(name, null);
|
|
91
|
+
}
|
|
86
92
|
|
|
87
93
|
if (filterChange && changed || !filterChange) {
|
|
88
94
|
filteredUpdates[name] = newValue;
|
package/package.json
CHANGED
package/server/Server.js
CHANGED
|
@@ -264,7 +264,37 @@ class Server {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
this._clientConfigFunction = clientConfigFunction;
|
|
267
|
+
this._clientConfigFunction = clientConfigFunction; // basic http authentication
|
|
268
|
+
|
|
269
|
+
if (this.config.env.auth) {
|
|
270
|
+
this.router.use((req, res, next) => {
|
|
271
|
+
const isProtected = this.config.env.auth.clients.map(type => req.path.endsWith(`/${type}`)).reduce((acc, value) => acc || value, false);
|
|
272
|
+
|
|
273
|
+
if (isProtected) {
|
|
274
|
+
// authentication middleware
|
|
275
|
+
const auth = this.config.env.auth; // parse login and password from headers
|
|
276
|
+
|
|
277
|
+
const b64auth = (req.headers.authorization || '').split(' ')[1] || '';
|
|
278
|
+
const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':'); // verify login and password are set and correct
|
|
279
|
+
|
|
280
|
+
if (login && password && login === auth.login && password === auth.password) {
|
|
281
|
+
// -> access granted...
|
|
282
|
+
return next();
|
|
283
|
+
} // -> access denied...
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
res.writeHead(401, {
|
|
287
|
+
'WWW-Authenticate': 'Basic',
|
|
288
|
+
'Content-Type': 'text/plain'
|
|
289
|
+
});
|
|
290
|
+
res.end('Authentication required.');
|
|
291
|
+
} else {
|
|
292
|
+
// route not protected
|
|
293
|
+
return next();
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
268
298
|
return Promise.resolve();
|
|
269
299
|
}
|
|
270
300
|
/**
|
|
@@ -414,7 +444,7 @@ class Server {
|
|
|
414
444
|
}
|
|
415
445
|
}
|
|
416
446
|
|
|
417
|
-
_logger.default.clientConfigAndRouting(routes, this.config
|
|
447
|
+
_logger.default.clientConfigAndRouting(routes, this.config);
|
|
418
448
|
|
|
419
449
|
return Promise.resolve();
|
|
420
450
|
}).then(() => {
|
|
@@ -512,8 +542,16 @@ class Server {
|
|
|
512
542
|
|
|
513
543
|
if (this.config.env.subpath && !data.env.subpath) {
|
|
514
544
|
data.env.subpath = this.config.env.subpath;
|
|
515
|
-
}
|
|
545
|
+
} // cors / coop / coep headers for `crossOriginIsolated pages, enables
|
|
546
|
+
// sharedArrayBuffers and high precision timers
|
|
547
|
+
// cf. https://web.dev/why-coop-coep/
|
|
548
|
+
|
|
516
549
|
|
|
550
|
+
res.writeHead(200, {
|
|
551
|
+
'Cross-Origin-Resource-Policy': 'same-origin',
|
|
552
|
+
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
553
|
+
'Cross-Origin-Opener-Policy': 'same-origin'
|
|
554
|
+
});
|
|
517
555
|
const appIndex = tmpl(data);
|
|
518
556
|
res.end(appIndex);
|
|
519
557
|
}); // return route infos for logging on server start
|
package/server/utils/logger.js
CHANGED
|
@@ -19,7 +19,10 @@ const logger = {
|
|
|
19
19
|
console.log(_chalk.default.cyan(`+ ${msg}`));
|
|
20
20
|
},
|
|
21
21
|
|
|
22
|
-
clientConfigAndRouting(routes,
|
|
22
|
+
clientConfigAndRouting(routes, config) {
|
|
23
|
+
const clientsConfig = config.app.clients;
|
|
24
|
+
const serverIp = config.env.serverIp;
|
|
25
|
+
const auth = config.env.auth;
|
|
23
26
|
const table = [];
|
|
24
27
|
|
|
25
28
|
for (let clientType in clientsConfig) {
|
|
@@ -27,18 +30,20 @@ const logger = {
|
|
|
27
30
|
|
|
28
31
|
if (client.target === 'node') {
|
|
29
32
|
const line = {
|
|
30
|
-
|
|
33
|
+
client_type: `> ${clientType}`,
|
|
31
34
|
target: _chalk.default.red(client.target),
|
|
32
35
|
path: `server ip: ${_chalk.default.green(serverIp)}`,
|
|
33
|
-
default: undefined
|
|
36
|
+
default: undefined,
|
|
37
|
+
auth: undefined
|
|
34
38
|
};
|
|
35
39
|
table.push(line);
|
|
36
40
|
} else if (client.target === 'browser') {
|
|
37
41
|
const line = {
|
|
38
|
-
|
|
42
|
+
client_type: `> ${clientType}`,
|
|
39
43
|
target: _chalk.default.red(client.target),
|
|
40
44
|
path: routes.find(r => r.clientType === clientType) ? _chalk.default.green(routes.find(r => r.clientType === clientType).path) : _chalk.default.red('no route defined'),
|
|
41
|
-
default: client.default ? '
|
|
45
|
+
default: client.default ? 'x' : undefined,
|
|
46
|
+
auth: auth && auth.clients.indexOf(clientType) !== -1 ? 'x' : undefined
|
|
42
47
|
};
|
|
43
48
|
table.push(line);
|
|
44
49
|
} else {
|
|
@@ -46,10 +51,21 @@ const logger = {
|
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
|
|
54
|
+
console.log(``);
|
|
49
55
|
console.log((0, _columnify.default)(table, {
|
|
50
|
-
showHeaders:
|
|
51
|
-
minWidth:
|
|
52
|
-
|
|
56
|
+
showHeaders: true,
|
|
57
|
+
minWidth: 6,
|
|
58
|
+
columnSplitter: ' | ',
|
|
59
|
+
config: {
|
|
60
|
+
default: {
|
|
61
|
+
align: 'center'
|
|
62
|
+
},
|
|
63
|
+
auth: {
|
|
64
|
+
align: 'center'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
console.log(``); // check if a route is defined but not in config
|
|
53
69
|
|
|
54
70
|
const configClientTypes = Object.keys(clientsConfig);
|
|
55
71
|
routes.forEach(r => {
|