acebase-server 1.3.0 → 1.6.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 +7 -7
- package/src/acebase-server.js +311 -126
- package/src/index.d.ts +23 -1
- package/src/oauth-providers/dropbox.js +8 -1
- package/src/ts/oauth-providers/dropbox.ts +9 -2
- package/src/ts/oauth-providers/oauth-provider.ts +1 -1
- package/src/webmanager/index.html +18 -2
- package/src/webmanager/index.js +4 -2
- package/tsconfig.json +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "acebase-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "AceBase realtime database server (webserver endpoint to allow remote connections)",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"start": "node src/acebase-server.js start default 0.0.0.0 3000",
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"compile": "tsc
|
|
11
|
+
"compile": "tsc"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"database",
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"author": "Ewout Stortenbeker <me@appy.one> (http://appy.one)",
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"acebase": "^1.
|
|
48
|
-
"acebase-core": "^1.
|
|
49
|
-
"express": "^4.
|
|
50
|
-
"socket.io": "^2.
|
|
47
|
+
"acebase": "^1.11.0",
|
|
48
|
+
"acebase-core": "^1.10.0",
|
|
49
|
+
"express": "^4.17.1",
|
|
50
|
+
"socket.io": "^2.4.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/express": "^4.17.
|
|
53
|
+
"@types/express": "^4.17.13",
|
|
54
54
|
"@types/node": "^14.0.14"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/acebase-server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const express = require('express');
|
|
2
2
|
const { EventEmitter } = require('events');
|
|
3
3
|
const { AceBase, SchemaValidationError } = require('acebase');
|
|
4
4
|
const { ID, Transport, DataSnapshot, PathInfo, Utils, DebugLogger, ColorStyle } = require('acebase-core');
|
|
@@ -50,7 +50,7 @@ class AceBaseServerAuthenticationSettings {
|
|
|
50
50
|
* @param {number} [settings.tokensExpire=0] how many minutes before access tokens expire. 0 for no expiration. not implemented yet
|
|
51
51
|
* @param {string} [settings.defaultAccessRule='auth'] when the server runs for the first time, what defaults to use to generate the rules.json file with. Options are: 'auth' (only authenticated access to db, default), 'deny' (deny access to anyone except admin user), 'allow' (allow access to anyone)
|
|
52
52
|
* @param {boolean} [settings.defaultAdminPassword] when the server runs for the first time, what password to use for the admin user. If not supplied, a generated password will be used and shown ONCE in the console output.
|
|
53
|
-
* @param {boolean} [settings.
|
|
53
|
+
* @param {boolean} [settings.separateDb=false] whether to use a separate database for auth and logging
|
|
54
54
|
*/
|
|
55
55
|
constructor(settings) {
|
|
56
56
|
if (typeof settings !== "object") { settings = {}; }
|
|
@@ -60,7 +60,9 @@ class AceBaseServerAuthenticationSettings {
|
|
|
60
60
|
this.tokensExpire = typeof settings.tokensExpire === 'number' ? settings.tokensExpire : 0;
|
|
61
61
|
this.defaultAccessRule = settings.defaultAccessRule || AceBaseServerAuthenticationSettings.ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
|
|
62
62
|
this.defaultAdminPassword = typeof settings.defaultAdminPassword === 'string' ? settings.defaultAdminPassword : undefined;
|
|
63
|
-
this.
|
|
63
|
+
this.separateDb = typeof settings.separateDb === 'boolean'
|
|
64
|
+
? settings.separateDb
|
|
65
|
+
: typeof settings.seperateDb === 'boolean' ? seperateDb : false; // Handle previous _wrong_ spelling
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
static get ACCESS_DEFAULT() {
|
|
@@ -191,6 +193,19 @@ class AceBaseServerEmailSettings {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
196
|
+
class AceBaseServerTransactionSettings {
|
|
197
|
+
/**
|
|
198
|
+
* TODO: Use AceBaseTransactionLogSettings from 'acebase/src/storage-acebase.js'
|
|
199
|
+
* @param {AceBaseServerTransactionSettings} settings
|
|
200
|
+
*/
|
|
201
|
+
constructor(settings) {
|
|
202
|
+
settings = settings || { log: false }; // Keep default false until transaction logging is out of alpha/beta
|
|
203
|
+
this.log = settings.log === true;
|
|
204
|
+
this.maxAge = typeof settings.maxAge === 'number' ? settings.maxAge : 30; // 30 days
|
|
205
|
+
this.noWait = settings.noWait === true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
194
209
|
class AceBaseServerSettings {
|
|
195
210
|
|
|
196
211
|
/**
|
|
@@ -205,6 +220,7 @@ class AceBaseServerSettings {
|
|
|
205
220
|
* @param {AceBaseServerHttpsSettings} [settings.https] { keyPath:string, certPath:string} | { pfxPath:string, passphrase:string }
|
|
206
221
|
* @param {AceBaseServerAuthenticationSettings} [settings.auth]
|
|
207
222
|
* @param {AceBaseServerEmailSettings} [settings.email]
|
|
223
|
+
* @param {AceBaseServerTransactionSettings} [settings.transactions]
|
|
208
224
|
*
|
|
209
225
|
*/
|
|
210
226
|
constructor(settings) {
|
|
@@ -219,6 +235,7 @@ class AceBaseServerSettings {
|
|
|
219
235
|
this.maxPayloadSize = settings.maxPayloadSize || '10mb';
|
|
220
236
|
this.allowOrigin = settings.allowOrigin || '*';
|
|
221
237
|
this.email = typeof settings.email === 'object' ? new AceBaseServerEmailSettings(settings.email) : null;
|
|
238
|
+
this.transactions = new AceBaseServerTransactionSettings(settings.transactions);
|
|
222
239
|
}
|
|
223
240
|
}
|
|
224
241
|
|
|
@@ -482,12 +499,44 @@ class AceBaseServer extends EventEmitter {
|
|
|
482
499
|
this._ready = false;
|
|
483
500
|
|
|
484
501
|
options = new AceBaseServerSettings(options);
|
|
485
|
-
|
|
502
|
+
|
|
503
|
+
const app = express();
|
|
486
504
|
app.set('trust proxy', true); // When behind proxy server, req.ip and req.hostname will be set the right way
|
|
487
|
-
|
|
505
|
+
|
|
506
|
+
const corsOptions = {
|
|
507
|
+
origin: options.allowOrigin === '*' ? true : options.allowOrigin.split(/,\s*/),
|
|
508
|
+
methods: 'GET,PUT,POST,DELETE,OPTIONS',
|
|
509
|
+
allowedHeaders: 'Content-Type, Authorization, Content-Length, Accept, Origin, X-Requested-With, AceBase-Context' // Disabled so cors will allow all used request headers
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
// When updating socket.io to 3+, use this for cors instead:
|
|
513
|
+
// const cors = require('cors');
|
|
514
|
+
// app.use(cors(corsOptions));
|
|
515
|
+
|
|
516
|
+
// With socket.io 2.x:
|
|
517
|
+
const corsHandler = (req, res, next) => {
|
|
518
|
+
res.header('Access-Control-Allow-Origin', options.allowOrigin !== '*' ? options.allowOrigin : (req.headers.origin || '*'));
|
|
519
|
+
res.header('Access-Control-Allow-Methods', corsOptions.methods);
|
|
520
|
+
res.header('Access-Control-Allow-Headers', corsOptions.allowedHeaders);
|
|
521
|
+
if (req.method === 'OPTIONS') {
|
|
522
|
+
res.status(200).end();
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
next();
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
app.use(corsHandler);
|
|
529
|
+
|
|
488
530
|
const server = options.https.enabled ? require('https').createServer(options.https, app) : require('http').createServer(app);
|
|
489
|
-
const io = require('socket.io')
|
|
531
|
+
const io = require('socket.io')(server, {
|
|
532
|
+
// socket.io 2.x:
|
|
533
|
+
handlePreflightRequest: corsHandler
|
|
534
|
+
// socket.io 3+:
|
|
535
|
+
// cors: corsOptions
|
|
536
|
+
});
|
|
490
537
|
|
|
538
|
+
app.use(express.json({ limit: options.maxPayloadSize, extended: true }));
|
|
539
|
+
|
|
491
540
|
this.config = {
|
|
492
541
|
hostname: options.host,
|
|
493
542
|
port: options.port,
|
|
@@ -496,7 +545,10 @@ class AceBaseServer extends EventEmitter {
|
|
|
496
545
|
},
|
|
497
546
|
https: options.https,
|
|
498
547
|
authentication: options.authentication,
|
|
499
|
-
email: options.email
|
|
548
|
+
email: options.email,
|
|
549
|
+
get transactionLoggingEnabled() {
|
|
550
|
+
return options.transactions && options.transactions.log === true;
|
|
551
|
+
}
|
|
500
552
|
};
|
|
501
553
|
this.url = this.config.url; // Is this used?
|
|
502
554
|
this.debug = new DebugLogger(options.logLevel, `[${dbname}]`.colorize(ColorStyle.green)); //`« ${dbname} »`
|
|
@@ -507,7 +559,8 @@ class AceBaseServer extends EventEmitter {
|
|
|
507
559
|
storage: {
|
|
508
560
|
cluster: options.cluster,
|
|
509
561
|
path: options.path,
|
|
510
|
-
removeVoidProperties: true
|
|
562
|
+
removeVoidProperties: true,
|
|
563
|
+
transactions: options.transactions
|
|
511
564
|
}
|
|
512
565
|
};
|
|
513
566
|
|
|
@@ -530,12 +583,16 @@ class AceBaseServer extends EventEmitter {
|
|
|
530
583
|
const otherDbsPath = `${options.path}/${dbname}.acebase`;
|
|
531
584
|
// const eventsDb = new AceBase('events', { logLevel: dbOptions.logLevel, storage: { path: otherDbsPath, removeVoidProperties: true } })
|
|
532
585
|
// const logsDb = new AceBase('logs', { logLevel: dbOptions.logLevel, storage: { path: otherDbsPath, removeVoidProperties: true } })
|
|
533
|
-
const authDb =
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
586
|
+
const authDb = (() => {
|
|
587
|
+
if (!options.authentication.enabled) {
|
|
588
|
+
return null;
|
|
589
|
+
}
|
|
590
|
+
switch(options.authentication.separateDb) {
|
|
591
|
+
case true: return new AceBase('auth', { logLevel: dbOptions.logLevel, storage: { path: otherDbsPath, removeVoidProperties: true, info: `${dbname} auth database` } });
|
|
592
|
+
case 'v2': /*NOT TESTED YET*/return new AceBase(dbname, { logLevel: dbOptions.logLevel, storage: { type: 'auth', path: options.path, removeVoidProperties: true, info: `${dbname} auth database` } });
|
|
593
|
+
default: return db;
|
|
594
|
+
}
|
|
595
|
+
})();
|
|
539
596
|
|
|
540
597
|
// To handle unhandled promise rejections so process will not die in future versions of node:
|
|
541
598
|
// process.on("unhandledRejection", (reason, p) => {
|
|
@@ -555,11 +612,10 @@ class AceBaseServer extends EventEmitter {
|
|
|
555
612
|
const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
|
|
556
613
|
const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
|
|
557
614
|
const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
|
|
615
|
+
const rulesFilePath = `${options.path}/${dbname}.acebase/rules.json`;
|
|
558
616
|
|
|
559
617
|
const setupRules = () => {
|
|
560
618
|
// Check if there is a rules file, load it or generate default
|
|
561
|
-
const rulesFilePath = `${options.path}/${dbname}.acebase/rules.json`;
|
|
562
|
-
|
|
563
619
|
fs.unwatchFile(rulesFilePath); // If function was triggered because of file change, stop listening now. Listener will be setup again at end of function
|
|
564
620
|
|
|
565
621
|
const defaultAccessRule = (def => {
|
|
@@ -659,7 +715,7 @@ class AceBaseServer extends EventEmitter {
|
|
|
659
715
|
fs.watchFile(rulesFilePath, (currStats, prevStats) => {
|
|
660
716
|
// rules.json file changed, setup rules again
|
|
661
717
|
setupRules();
|
|
662
|
-
})
|
|
718
|
+
});
|
|
663
719
|
}
|
|
664
720
|
setupRules();
|
|
665
721
|
|
|
@@ -847,7 +903,7 @@ class AceBaseServer extends EventEmitter {
|
|
|
847
903
|
return false;
|
|
848
904
|
}
|
|
849
905
|
|
|
850
|
-
const env = { now: Date.now(), auth: user || null };
|
|
906
|
+
const env = { now: Date.now(), auth: user || null }; // IDEA: Add functions like "exists" and "value". These will be async (so that requires refactoring) and can be used like "await exists('./shared/' + auth.uid)" and "await value('./writable') === true"
|
|
851
907
|
const pathKeys = PathInfo.getPathKeys(path);
|
|
852
908
|
let rule = accessRules.rules;
|
|
853
909
|
let rulePath = [];
|
|
@@ -1027,20 +1083,6 @@ class AceBaseServer extends EventEmitter {
|
|
|
1027
1083
|
this.debug.log(err);
|
|
1028
1084
|
});
|
|
1029
1085
|
|
|
1030
|
-
app.use(bodyParser.json({ limit: options.maxPayloadSize, extended: true }));
|
|
1031
|
-
|
|
1032
|
-
app.use((req, res, next) => {
|
|
1033
|
-
res.header('Access-Control-Allow-Origin', options.allowOrigin);
|
|
1034
|
-
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
|
1035
|
-
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, Accept, Origin, X-Requested-With, AceBase-Context'); // Safari is not satisfied with *
|
|
1036
|
-
if (req.method === 'OPTIONS') {
|
|
1037
|
-
res.sendStatus(200);
|
|
1038
|
-
}
|
|
1039
|
-
else {
|
|
1040
|
-
next();
|
|
1041
|
-
}
|
|
1042
|
-
});
|
|
1043
|
-
|
|
1044
1086
|
app.use((req, res, next) => {
|
|
1045
1087
|
// Setup AceBase context, to allow clients to pass contextual info with data updates,
|
|
1046
1088
|
// that will be sent along to data event subscribers on affected data.
|
|
@@ -1349,9 +1391,17 @@ class AceBaseServer extends EventEmitter {
|
|
|
1349
1391
|
email(email) {
|
|
1350
1392
|
return /[a-z0-9_.+]+@([a-z0-9\-]+\.)+[a-z]{2,}/i.test(email);
|
|
1351
1393
|
},
|
|
1394
|
+
async newEmailAddress(email) {
|
|
1395
|
+
const exists = await authRef.query().filter('email', '==', email).exists();
|
|
1396
|
+
return !exists;
|
|
1397
|
+
},
|
|
1352
1398
|
username(username) {
|
|
1353
1399
|
return username !== 'admin' && typeof username === 'string' && username.length >= 5 && /^[a-z0-9]+$/.test(username);
|
|
1354
1400
|
},
|
|
1401
|
+
async newUsername(username) {
|
|
1402
|
+
const exists = await authRef.query().filter('username', '==', username).exists();
|
|
1403
|
+
return !exists;
|
|
1404
|
+
},
|
|
1355
1405
|
displayName(displayName) {
|
|
1356
1406
|
return typeof displayName === 'string' && displayName.length >= 5;
|
|
1357
1407
|
},
|
|
@@ -1359,6 +1409,9 @@ class AceBaseServer extends EventEmitter {
|
|
|
1359
1409
|
// return typeof password === 'string' && password.length >= 8 && password.indexOf(' ') < 0 && /[0-9]/.test(password) && /[a-z]/.test(password) && /[A-Z]/.test(password);
|
|
1360
1410
|
return typeof password === 'string' && password.length >= 8 && password.indexOf(' ') < 0; // Let client application set their own password rules. Keep minimum length of 8 and no spaces requirement.
|
|
1361
1411
|
},
|
|
1412
|
+
picture(picture) {
|
|
1413
|
+
return picture === null || (typeof picture === 'object' && typeof picture.url === 'string' && typeof picture.width === 'number' && typeof picture.height === 'number');
|
|
1414
|
+
},
|
|
1362
1415
|
settings(settings) {
|
|
1363
1416
|
return typeof settings === 'undefined'
|
|
1364
1417
|
|| (
|
|
@@ -1372,12 +1425,16 @@ class AceBaseServer extends EventEmitter {
|
|
|
1372
1425
|
const validationErrors = {
|
|
1373
1426
|
email: { code: 'invalid_email', message: 'Invalid email address' },
|
|
1374
1427
|
username: { code: 'invalid_username', message: 'Invalid username, must be at least 5 characters and can only contain lowercase characters a-z and 0-9' },
|
|
1428
|
+
emailExists: { code: 'email_conflict', message: 'Account with email address exists already' },
|
|
1429
|
+
usernameExists: { code: 'username_conflict', message: 'Account with username exists already' },
|
|
1430
|
+
emailOrUsernameExists: { code: 'conflict', message: `Account with username and/or email already exists` },
|
|
1375
1431
|
displayName: { code: 'invalid_display_name', message: 'Invalid display_name, must be at least 5 characters' },
|
|
1376
1432
|
password: { code: 'invalid_password', message: 'Invalid password, must be at least 8 characters and cannot contain spaces' },
|
|
1433
|
+
picture: { code: 'invalid_picture', message: 'Invalid picture, must be an object with url, width and height properties'},
|
|
1377
1434
|
settings: { code: 'invalid_settings', message: 'Invalid settings, must be an object and contain only string, number and/or boolean values. Additionaly, string values can have a maximum length of 250, and a maximum of 100 settings can be added' }
|
|
1378
1435
|
};
|
|
1379
1436
|
|
|
1380
|
-
app.post(`/auth/${dbname}/signup`, (req, res) => {
|
|
1437
|
+
app.post(`/auth/${dbname}/signup`, async (req, res) => {
|
|
1381
1438
|
if (!this.config.authentication.allowUserSignup && (!req.user || req.user.username !== 'admin')) {
|
|
1382
1439
|
logRef.push({ action: 'signup', success: false, code: 'user_signup_disabled', ip: req.ip, date: new Date() });
|
|
1383
1440
|
res.statusCode = 403; // Forbidden
|
|
@@ -1397,9 +1454,15 @@ class AceBaseServer extends EventEmitter {
|
|
|
1397
1454
|
else if (details.email && !isValid.email(details.email)) {
|
|
1398
1455
|
err = validationErrors.email;
|
|
1399
1456
|
}
|
|
1400
|
-
else if (details.
|
|
1457
|
+
else if (details.email && !await isValid.newEmailAddress(details.email)) {
|
|
1458
|
+
err = validationErrors.emailExists;
|
|
1459
|
+
}
|
|
1460
|
+
else if (details.username && !isValid.username(details.username)) {
|
|
1401
1461
|
err = validationErrors.username;
|
|
1402
1462
|
}
|
|
1463
|
+
else if (details.username && !await isValid.newUsername(details.username)) {
|
|
1464
|
+
err = validationErrors.usernameExists;
|
|
1465
|
+
}
|
|
1403
1466
|
else if (!isValid.displayName(details.displayName)) {
|
|
1404
1467
|
err = validationErrors.displayName;
|
|
1405
1468
|
}
|
|
@@ -1409,36 +1472,20 @@ class AceBaseServer extends EventEmitter {
|
|
|
1409
1472
|
else if (!isValid.settings(details.settings)) {
|
|
1410
1473
|
err = validationErrors.settings;
|
|
1411
1474
|
}
|
|
1412
|
-
|
|
1475
|
+
|
|
1476
|
+
if (err && [validationErrors.emailExists, validationErrors.usernameExists].includes(err)) {
|
|
1477
|
+
logRef.push({ action: 'signup', success: false, code: 'conflict', ip: req.ip, date: new Date(), username: details.username, email: details.email });
|
|
1478
|
+
res.statusCode = 409; // conflict
|
|
1479
|
+
return res.send(validationErrors.emailOrUsernameExists);
|
|
1480
|
+
}
|
|
1481
|
+
else if (err) {
|
|
1413
1482
|
// Log failure
|
|
1414
1483
|
logRef.push({ action: 'signup', success: false, code: err.code, ip: req.ip, date: new Date() });
|
|
1415
|
-
|
|
1416
1484
|
res.statusCode = 422; // Unprocessable Entity
|
|
1417
|
-
res.send(err);
|
|
1418
|
-
return;
|
|
1485
|
+
return res.send(err);
|
|
1419
1486
|
}
|
|
1420
1487
|
|
|
1421
|
-
|
|
1422
|
-
const promises = [];
|
|
1423
|
-
if (details.username) {
|
|
1424
|
-
let promise = authRef.query().filter('username', '==', details.username).get();
|
|
1425
|
-
promises.push(promise);
|
|
1426
|
-
}
|
|
1427
|
-
if (details.email) {
|
|
1428
|
-
let promise = authRef.query().filter('email', '==', details.email).get();
|
|
1429
|
-
promises.push(promise);
|
|
1430
|
-
}
|
|
1431
|
-
return Promise.all(promises).then(arr => {
|
|
1432
|
-
return arr.reduce((n, snaps) => n + snaps.length, 0);
|
|
1433
|
-
})
|
|
1434
|
-
.then(userCount => {
|
|
1435
|
-
if (userCount > 0) {
|
|
1436
|
-
logRef.push({ action: 'signup', success: false, code: 'conflict', ip: req.ip, date: new Date(), username: details.username, email: details.email });
|
|
1437
|
-
res.statusCode = 409; // conflict
|
|
1438
|
-
res.send({ code: 'conflict', message: `Account with username and/or email already exists` });
|
|
1439
|
-
return;
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1488
|
+
try {
|
|
1442
1489
|
// Ok, create user
|
|
1443
1490
|
let pwd = createPasswordHash(details.password);
|
|
1444
1491
|
/** @type {DbUserAccountDetails} */
|
|
@@ -1458,52 +1505,50 @@ class AceBaseServer extends EventEmitter {
|
|
|
1458
1505
|
settings: details.settings || {}
|
|
1459
1506
|
};
|
|
1460
1507
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
user.uid = uid;
|
|
1508
|
+
const userRef = await authRef.push(user);
|
|
1509
|
+
const uid = userRef.key;
|
|
1510
|
+
user.uid = uid;
|
|
1465
1511
|
|
|
1466
|
-
|
|
1467
|
-
|
|
1512
|
+
// Log success
|
|
1513
|
+
logRef.push({ action: 'signup', success: true, ip: req.ip, date: new Date(), uid });
|
|
1468
1514
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1515
|
+
// Cache the user
|
|
1516
|
+
_authCache.set(user.uid, user);
|
|
1471
1517
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1518
|
+
// Request welcome e-mail to be sent
|
|
1519
|
+
const request = new AceBaseUserSignupEmailRequest({
|
|
1520
|
+
user: {
|
|
1521
|
+
uid: user.uid,
|
|
1522
|
+
username: user.username,
|
|
1523
|
+
email: user.email,
|
|
1524
|
+
displayName: user.display_name,
|
|
1525
|
+
settings: user.settings
|
|
1526
|
+
},
|
|
1527
|
+
date: user.created,
|
|
1528
|
+
ip: user.created_ip,
|
|
1529
|
+
provider: 'acebase',
|
|
1530
|
+
activationCode: createSignedPublicToken({ uid: user.uid }, _secureObjectsSalt), // , email: user.email, code: user.email_verification_code
|
|
1531
|
+
emailVerified: false
|
|
1532
|
+
});
|
|
1487
1533
|
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1534
|
+
this.config.email && this.config.email.send(request).catch(err => {
|
|
1535
|
+
logRef.push({ action: 'signup_email', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, request });
|
|
1536
|
+
});
|
|
1491
1537
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
});
|
|
1538
|
+
// Return the positive news
|
|
1539
|
+
const isAdmin = req.user && req.user.uid === 'admin';
|
|
1540
|
+
res.send({
|
|
1541
|
+
access_token: isAdmin ? '' : createPublicAccessToken(user.uid, req.ip, user.access_token, _secureObjectsSalt),
|
|
1542
|
+
user: getPublicAccountDetails(user)
|
|
1498
1543
|
});
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1544
|
+
}
|
|
1545
|
+
catch(err) {
|
|
1501
1546
|
logRef.push({ action: 'signup', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, username: details.username, email: details.email });
|
|
1502
1547
|
sendError(res, err);
|
|
1503
|
-
}
|
|
1548
|
+
}
|
|
1504
1549
|
});
|
|
1505
1550
|
|
|
1506
|
-
app.post(`/auth/${dbname}/update`, (req, res) => {
|
|
1551
|
+
app.post(`/auth/${dbname}/update`, async (req, res) => {
|
|
1507
1552
|
let details = req.body;
|
|
1508
1553
|
|
|
1509
1554
|
if (!req.user) {
|
|
@@ -1523,12 +1568,21 @@ class AceBaseServer extends EventEmitter {
|
|
|
1523
1568
|
if (details.email && !isValid.email(details.email)) {
|
|
1524
1569
|
err = validationErrors.email;
|
|
1525
1570
|
}
|
|
1526
|
-
else if (details.
|
|
1571
|
+
else if (details.email && !await isValid.newEmailAddress(details.email)) {
|
|
1572
|
+
err = validationErrors.emailExists;
|
|
1573
|
+
}
|
|
1574
|
+
else if (details.username && !isValid.username(details.username)) {
|
|
1527
1575
|
err = validationErrors.username;
|
|
1528
1576
|
}
|
|
1577
|
+
else if (details.username && !await isValid.newUsername(details.username)) {
|
|
1578
|
+
err = validationErrors.usernameExists;
|
|
1579
|
+
}
|
|
1529
1580
|
else if (details.display_name && !isValid.displayName(details.display_name)) {
|
|
1530
1581
|
err = validationErrors.displayName;
|
|
1531
1582
|
}
|
|
1583
|
+
else if (details.picture && !isValid.picture(details.picture)) {
|
|
1584
|
+
err = validationErrors.picture;
|
|
1585
|
+
}
|
|
1532
1586
|
else if (!isValid.settings(details.settings)) {
|
|
1533
1587
|
err = validationErrors.settings;
|
|
1534
1588
|
}
|
|
@@ -1551,12 +1605,13 @@ class AceBaseServer extends EventEmitter {
|
|
|
1551
1605
|
return;
|
|
1552
1606
|
}
|
|
1553
1607
|
user = snap.val();
|
|
1554
|
-
if (details.email !== user.email) {
|
|
1608
|
+
if (details.email && details.email !== user.email) {
|
|
1555
1609
|
user.email = details.email;
|
|
1556
1610
|
user.email_verified = false; // TODO: send verification email
|
|
1557
1611
|
}
|
|
1558
|
-
if (details.username) {
|
|
1559
|
-
if (details.display_name) {
|
|
1612
|
+
if (details.username) { user.username = details.username; }
|
|
1613
|
+
if (details.display_name) { user.display_name = details.display_name; }
|
|
1614
|
+
if (details.picture) { user.picture = details.picture; }
|
|
1560
1615
|
if (details.settings) {
|
|
1561
1616
|
if (typeof user.settings !== 'object') {
|
|
1562
1617
|
user.settings = {};
|
|
@@ -1627,6 +1682,10 @@ class AceBaseServer extends EventEmitter {
|
|
|
1627
1682
|
try {
|
|
1628
1683
|
const providerName = req.query.provider;
|
|
1629
1684
|
const callbackUrl = req.query.callbackUrl;
|
|
1685
|
+
const options = Object.keys(req.query).filter(key => key.startsWith('option_')).reduce((options, key) => {
|
|
1686
|
+
const name = key.slice(7);
|
|
1687
|
+
options[name] = req.query[key];
|
|
1688
|
+
}, {});
|
|
1630
1689
|
const signedInUid = req.user && req.user.uid;
|
|
1631
1690
|
const provider = this.authProviders[providerName];
|
|
1632
1691
|
if (!provider) {
|
|
@@ -1635,7 +1694,7 @@ class AceBaseServer extends EventEmitter {
|
|
|
1635
1694
|
// Create secure state so it cannot be tampered with. hash it with a server-only known salt: the generated admin password salt
|
|
1636
1695
|
await this.ready();
|
|
1637
1696
|
const state = createSignedPublicToken({ flow: 'redirect', provider: providerName, uid: signedInUid, callbackUrl }, _secureObjectsSalt);
|
|
1638
|
-
const clientAuthUrl = await provider.init({ redirect_url: `${req.protocol}://${req.headers.host}/oauth2/${dbname}/signin`, state });
|
|
1697
|
+
const clientAuthUrl = await provider.init({ redirect_url: `${req.protocol}://${req.headers.host}/oauth2/${dbname}/signin`, state, options });
|
|
1639
1698
|
res.send({ redirectUrl: clientAuthUrl });
|
|
1640
1699
|
}
|
|
1641
1700
|
catch(err) {
|
|
@@ -1964,7 +2023,7 @@ class AceBaseServer extends EventEmitter {
|
|
|
1964
2023
|
|
|
1965
2024
|
app.get(`/info/${dbname}`, (req, res) => {
|
|
1966
2025
|
const info = {
|
|
1967
|
-
version: '
|
|
2026
|
+
version: '1.5.1', // TODO: Load from package.json
|
|
1968
2027
|
time: Date.now(),
|
|
1969
2028
|
process: process.pid
|
|
1970
2029
|
};
|
|
@@ -2017,7 +2076,7 @@ class AceBaseServer extends EventEmitter {
|
|
|
2017
2076
|
res.send(info);
|
|
2018
2077
|
});
|
|
2019
2078
|
|
|
2020
|
-
app.get(`/data/${dbname}/*`, (req, res) => {
|
|
2079
|
+
app.get(`/data/${dbname}/*`, async (req, res) => {
|
|
2021
2080
|
// Request data
|
|
2022
2081
|
const path = req.path.substr(dbname.length + 7); //.replace(/^\/+/g, '').replace(/\/+$/g, '');
|
|
2023
2082
|
if (!userHasAccess(req.user, path, false, denyDetails => sendUnauthorizedError(res, denyDetails.code, denyDetails.message))) {
|
|
@@ -2048,21 +2107,25 @@ class AceBaseServer extends EventEmitter {
|
|
|
2048
2107
|
options.exclude = [...options.exclude || [], '__auth__', '__log__'];
|
|
2049
2108
|
}
|
|
2050
2109
|
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
const
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
res.
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2110
|
+
try {
|
|
2111
|
+
// const snap = await db.ref(path).get(options);
|
|
2112
|
+
// const value = snap.val(), context = snap.context();
|
|
2113
|
+
const { value, context } = await db.api.get(path, options);
|
|
2114
|
+
if (!this.config.transactionLoggingEnabled) {
|
|
2115
|
+
delete context.acebase_cursor;
|
|
2116
|
+
}
|
|
2117
|
+
const serialized = Transport.serialize(value);
|
|
2118
|
+
|
|
2119
|
+
res.setHeader('AceBase-Context', JSON.stringify(context));
|
|
2120
|
+
res.send({
|
|
2121
|
+
exists: value !== null,
|
|
2122
|
+
val: serialized.val,
|
|
2123
|
+
map: serialized.map
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
2126
|
+
catch (err) {
|
|
2127
|
+
res.status(500).send(err);
|
|
2128
|
+
}
|
|
2066
2129
|
});
|
|
2067
2130
|
|
|
2068
2131
|
app.get(`/reflect/${dbname}/*`, (req, res) => {
|
|
@@ -2261,18 +2324,18 @@ class AceBaseServer extends EventEmitter {
|
|
|
2261
2324
|
}
|
|
2262
2325
|
catch(err) {
|
|
2263
2326
|
if (err instanceof SchemaValidationError) {
|
|
2264
|
-
logRef.push({ action: 'set_data', success: false, code: 'schema_validation_failed', path, error: err.reason });
|
|
2327
|
+
logRef && logRef.push({ action: 'set_data', success: false, code: 'schema_validation_failed', path, error: err.reason });
|
|
2265
2328
|
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
2266
2329
|
}
|
|
2267
2330
|
else {
|
|
2268
2331
|
this.debug.error(`failed to set "${path}":`, err);
|
|
2269
|
-
logRef.push({ action: 'set_data', success: false, code: 'unknown_error', path, error: err.message });
|
|
2332
|
+
logRef && logRef.push({ action: 'set_data', success: false, code: 'unknown_error', path, error: err.message });
|
|
2270
2333
|
sendError(res, err);
|
|
2271
2334
|
}
|
|
2272
2335
|
};
|
|
2273
2336
|
});
|
|
2274
2337
|
|
|
2275
|
-
app.post(`/query/${dbname}/*`, (req, res) => {
|
|
2338
|
+
app.post(`/query/${dbname}/*`, async (req, res) => {
|
|
2276
2339
|
// Execute query
|
|
2277
2340
|
const path = req.path.substr(dbname.length + 8);
|
|
2278
2341
|
if (!userHasAccess(req.user, path, false, denyDetails => sendUnauthorizedError(res, denyDetails.code, denyDetails.message))) {
|
|
@@ -2280,6 +2343,9 @@ class AceBaseServer extends EventEmitter {
|
|
|
2280
2343
|
}
|
|
2281
2344
|
|
|
2282
2345
|
const data = Transport.deserialize(req.body);
|
|
2346
|
+
if (typeof data !== 'object' || typeof data.query !== 'object' || typeof data.options !== 'object') {
|
|
2347
|
+
return sendError(res, { code: 'invalid_request', message: 'Invalid query request' });
|
|
2348
|
+
}
|
|
2283
2349
|
const query = data.query;
|
|
2284
2350
|
const options = data.options;
|
|
2285
2351
|
if (options.monitor === true) {
|
|
@@ -2303,14 +2369,21 @@ class AceBaseServer extends EventEmitter {
|
|
|
2303
2369
|
}
|
|
2304
2370
|
options.eventHandler = sendEvent;
|
|
2305
2371
|
}
|
|
2306
|
-
|
|
2307
|
-
|
|
2372
|
+
try {
|
|
2373
|
+
const { results, context } = await db.api.query(path, query, options);
|
|
2374
|
+
if (!this.config.transactionLoggingEnabled) {
|
|
2375
|
+
delete context.acebase_cursor;
|
|
2376
|
+
}
|
|
2308
2377
|
const response = {
|
|
2309
2378
|
count: results.length,
|
|
2310
2379
|
list: results // []
|
|
2311
2380
|
};
|
|
2381
|
+
res.setHeader('AceBase-Context', JSON.stringify(context));
|
|
2312
2382
|
res.send(Transport.serialize(response));
|
|
2313
|
-
}
|
|
2383
|
+
}
|
|
2384
|
+
catch(err) {
|
|
2385
|
+
sendError(res, { code: 'unknown', message: err.message });
|
|
2386
|
+
}
|
|
2314
2387
|
});
|
|
2315
2388
|
|
|
2316
2389
|
app.get(`/index/${dbname}`, async (req, res) => {
|
|
@@ -2407,6 +2480,91 @@ class AceBaseServer extends EventEmitter {
|
|
|
2407
2480
|
}
|
|
2408
2481
|
});
|
|
2409
2482
|
|
|
2483
|
+
app.get(`/sync/mutations/${dbname}`, async (req, res) => {
|
|
2484
|
+
// Gets mutations for specific path(s) and event combinations since given cursor
|
|
2485
|
+
if (!this.config.transactionLoggingEnabled) {
|
|
2486
|
+
return sendError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
|
|
2487
|
+
}
|
|
2488
|
+
try {
|
|
2489
|
+
const data = req.query;
|
|
2490
|
+
let targets = typeof data.path === 'string'
|
|
2491
|
+
? [{ path: data.path, events: ['value'] }]
|
|
2492
|
+
: typeof data.for === 'string'
|
|
2493
|
+
? JSON.parse(data.for)
|
|
2494
|
+
: null;
|
|
2495
|
+
if (targets === null) {
|
|
2496
|
+
return sendError(res, { code: 'invalid_request', message: 'Invalid mutations request' });
|
|
2497
|
+
}
|
|
2498
|
+
if (targets.length === 0) {
|
|
2499
|
+
targets.push({ path: '', events: ['value'] });
|
|
2500
|
+
}
|
|
2501
|
+
// Filter out any requested paths user does not have access to.
|
|
2502
|
+
targets = targets.filter(target => {
|
|
2503
|
+
let path = target.path;
|
|
2504
|
+
if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
|
|
2505
|
+
// Only child_ events, check if they have access to children instead
|
|
2506
|
+
path = PathInfo.get(path).childPath('*');
|
|
2507
|
+
}
|
|
2508
|
+
return userHasAccess(req.user, path, false);
|
|
2509
|
+
});
|
|
2510
|
+
if (targets.length === 0) {
|
|
2511
|
+
return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
const { cursor, timestamp } = data;
|
|
2515
|
+
const result = await db.api.getMutations({ for: targets, cursor, timestamp });
|
|
2516
|
+
|
|
2517
|
+
res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
|
|
2518
|
+
res.contentType('application/json');
|
|
2519
|
+
res.send(result.mutations);
|
|
2520
|
+
}
|
|
2521
|
+
catch(err) {
|
|
2522
|
+
sendError(res, err);
|
|
2523
|
+
}
|
|
2524
|
+
});
|
|
2525
|
+
|
|
2526
|
+
app.get(`/sync/changes/${dbname}`, async (req, res) => {
|
|
2527
|
+
// Gets effective changes for specific path(s) and event combinations since given cursor
|
|
2528
|
+
if (!this.config.transactionLoggingEnabled) {
|
|
2529
|
+
return sendError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
|
|
2530
|
+
}
|
|
2531
|
+
try {
|
|
2532
|
+
const data = req.query;
|
|
2533
|
+
let targets = typeof data.path === 'string'
|
|
2534
|
+
? [{ path: data.path, events: ['value'] }]
|
|
2535
|
+
: typeof data.for === 'string'
|
|
2536
|
+
? JSON.parse(data.for)
|
|
2537
|
+
: null;
|
|
2538
|
+
if (targets === null) {
|
|
2539
|
+
return sendError(res, { code: 'invalid_request', message: 'Invalid mutations request' });
|
|
2540
|
+
}
|
|
2541
|
+
if (targets.length === 0) {
|
|
2542
|
+
targets.push({ path: '', events: ['value'] });
|
|
2543
|
+
}
|
|
2544
|
+
// Filter out any requested paths user does not have access to.
|
|
2545
|
+
targets = targets.filter(target => {
|
|
2546
|
+
let path = target.path;
|
|
2547
|
+
if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
|
|
2548
|
+
// Only child_ events, check if they have access to children instead
|
|
2549
|
+
path = PathInfo.get(path).childPath('*');
|
|
2550
|
+
}
|
|
2551
|
+
return userHasAccess(req.user, path, false);
|
|
2552
|
+
});
|
|
2553
|
+
if (targets.length === 0) {
|
|
2554
|
+
return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
const { cursor, timestamp } = data;
|
|
2558
|
+
const result = await db.api.getChanges({ for: targets, cursor, timestamp });
|
|
2559
|
+
|
|
2560
|
+
res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
|
|
2561
|
+
res.contentType('application/json');
|
|
2562
|
+
res.send(result.changes);
|
|
2563
|
+
}
|
|
2564
|
+
catch(err) {
|
|
2565
|
+
sendError(res, err);
|
|
2566
|
+
}
|
|
2567
|
+
});
|
|
2410
2568
|
|
|
2411
2569
|
const _transactions = new Map();
|
|
2412
2570
|
app.post(`/transaction/${dbname}/start`, (req, res) => {
|
|
@@ -2536,6 +2694,21 @@ class AceBaseServer extends EventEmitter {
|
|
|
2536
2694
|
}
|
|
2537
2695
|
};
|
|
2538
2696
|
|
|
2697
|
+
this.shutdown = async () => {
|
|
2698
|
+
this.debug.warn('shutting down server');
|
|
2699
|
+
fs.unwatchFile(rulesFilePath);
|
|
2700
|
+
await new Promise((resolve) => {
|
|
2701
|
+
server.close(resolve);
|
|
2702
|
+
clients.list.slice().forEach(client => {
|
|
2703
|
+
client.socket.disconnect(true);
|
|
2704
|
+
});
|
|
2705
|
+
});
|
|
2706
|
+
this.debug.warn('closing database');
|
|
2707
|
+
await db.close(); // TODO: Check what happens if shutdown was triggered by SIGINT. Maybe already closed?
|
|
2708
|
+
this.debug.warn('shutdown complete');
|
|
2709
|
+
};
|
|
2710
|
+
process.on('SIGINT', () => this.shutdown());
|
|
2711
|
+
|
|
2539
2712
|
/** @type {Map<string, Client>} */
|
|
2540
2713
|
// const clientsNew = new Map();
|
|
2541
2714
|
|
|
@@ -2604,11 +2777,13 @@ class AceBaseServer extends EventEmitter {
|
|
|
2604
2777
|
client.user = null;
|
|
2605
2778
|
});
|
|
2606
2779
|
|
|
2607
|
-
socket.on("oauth2-signin", async
|
|
2780
|
+
socket.on("oauth2-signin", async request => {
|
|
2781
|
+
// acebase-client does not use socket oauth flow yet
|
|
2608
2782
|
try {
|
|
2783
|
+
const providerName = typeof request === 'string' ? request : request.provider;
|
|
2609
2784
|
const provider = this.authProviders[providerName];
|
|
2610
2785
|
const state = Buffer.from(JSON.stringify({ flow: 'socket', provider: providerName, client_id: client.id })).toString('base64');
|
|
2611
|
-
const clientAuthUrl = await provider.init({ redirectUrl: `${req.protocol}://${req.headers.host}/ouath2/${dbname}/signin`, state });
|
|
2786
|
+
const clientAuthUrl = await provider.init({ redirectUrl: `${req.protocol}://${req.headers.host}/ouath2/${dbname}/signin`, state, options: request.options });
|
|
2612
2787
|
socket.emit('oauth2-signin', { action: 'auth', url: clientAuthUrl });
|
|
2613
2788
|
}
|
|
2614
2789
|
catch(err) {
|
|
@@ -2672,7 +2847,7 @@ class AceBaseServer extends EventEmitter {
|
|
|
2672
2847
|
previous: previousValue
|
|
2673
2848
|
});
|
|
2674
2849
|
this.debug.verbose(`Sending data event "${data.event}" for path "/${path}" to client ${socket.id}`.colorize([ColorStyle.bgWhite, ColorStyle.black]));
|
|
2675
|
-
socket.emit(
|
|
2850
|
+
socket.emit('data-event', {
|
|
2676
2851
|
subscr_path: subscriptionPath,
|
|
2677
2852
|
path,
|
|
2678
2853
|
event: data.event,
|
|
@@ -2846,6 +3021,16 @@ class AceBaseServer extends EventEmitter {
|
|
|
2846
3021
|
throw new Error(`Failed to configure provider ${providerName}: ${err.message}`)
|
|
2847
3022
|
}
|
|
2848
3023
|
}
|
|
3024
|
+
|
|
3025
|
+
/**
|
|
3026
|
+
* Shuts down the server. Stops listening for incoming connections, breaks current connections and closes the database.
|
|
3027
|
+
*/
|
|
3028
|
+
async shutdown() {
|
|
3029
|
+
// Overridden by constructor once the server is started.
|
|
3030
|
+
// If this code executes, the server's not running yet.
|
|
3031
|
+
await this.ready();
|
|
3032
|
+
await this.shutdown(); // Now has new implementation
|
|
3033
|
+
}
|
|
2849
3034
|
}
|
|
2850
3035
|
|
|
2851
3036
|
if (__filename.replace(/\\/g,"/").endsWith("/acebase-server.js") && process.argv[2] === "start") {
|
package/src/index.d.ts
CHANGED
|
@@ -4,7 +4,14 @@ import { AceBase } from 'acebase';
|
|
|
4
4
|
declare namespace acebaseserver {
|
|
5
5
|
class AceBaseServer {
|
|
6
6
|
constructor(dbname: string, options?: AceBaseServerSettings)
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wait for the server to be ready to accept incoming connections
|
|
10
|
+
* @param callback (optional) callback function that is called when ready. You can also use the returned promise
|
|
11
|
+
* @returns returns a promise that resolves when ready
|
|
12
|
+
*/
|
|
13
|
+
ready(callback?: () => void): Promise<void>
|
|
14
|
+
|
|
8
15
|
get url(): string
|
|
9
16
|
|
|
10
17
|
/**
|
|
@@ -64,6 +71,11 @@ declare namespace acebaseserver {
|
|
|
64
71
|
* @param {(req: Express.Request, res: Express.Response)} handler
|
|
65
72
|
*/
|
|
66
73
|
extend(method:'get'|'put'|'post'|'delete', ext_path: string, handler: (req: Express.Request, res: Express.Response) => any): void
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Shuts down the server. Stops listening for incoming connections, breaks current connections and closes the database.
|
|
77
|
+
*/
|
|
78
|
+
shutdown(): Promise<void>
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
interface IOAuthProviderSettings {
|
|
@@ -95,6 +107,8 @@ declare namespace acebaseserver {
|
|
|
95
107
|
allowOrigin?: string
|
|
96
108
|
/** Email settings that enable AceBaseServer to send e-mails, eg for welcoming new users, to reset passwords, notify of new sign ins etc */
|
|
97
109
|
email?: AceBaseServerEmailSettings
|
|
110
|
+
/** Transaction logging settings. Warning: BETA stage, do NOT use in production yet */
|
|
111
|
+
transactions?: AceBaseServerTransactionLogSettings
|
|
98
112
|
}
|
|
99
113
|
|
|
100
114
|
interface AceBaseServerHttpsSettings {
|
|
@@ -111,6 +125,8 @@ declare namespace acebaseserver {
|
|
|
111
125
|
/** 'allow', 'deny' or 'auth' */
|
|
112
126
|
defaultAccessRule?: string
|
|
113
127
|
defaultAdminPassword?: string
|
|
128
|
+
separateDb?: boolean
|
|
129
|
+
/** @deprecated Misspelled, use separateDb instead */
|
|
114
130
|
seperateDb?: boolean
|
|
115
131
|
}
|
|
116
132
|
|
|
@@ -133,6 +149,12 @@ declare namespace acebaseserver {
|
|
|
133
149
|
secure?: boolean
|
|
134
150
|
}
|
|
135
151
|
|
|
152
|
+
interface AceBaseServerTransactionLogSettings {
|
|
153
|
+
log?: boolean;
|
|
154
|
+
maxAge?: number;
|
|
155
|
+
noWait?: boolean;
|
|
156
|
+
}
|
|
157
|
+
|
|
136
158
|
interface AceBaseEmailRequest {
|
|
137
159
|
readonly type: string
|
|
138
160
|
readonly ip: string
|
|
@@ -16,10 +16,17 @@ class DropboxAuthProvider {
|
|
|
16
16
|
* Starts auth flow by getting the url the user should be redirected to
|
|
17
17
|
* @param info.redirectUrl Url dropbox will redirect to after authorizing
|
|
18
18
|
* @param info.state Optional state that will be passed to redirectUri by dropbox
|
|
19
|
+
* @param info.options Optional Dropbox specific authentication settings
|
|
20
|
+
* @param info.options.require_role If this parameter is specified, the user will be asked to authorize with a particular type of Dropbox account, either work for a team account or personal for a personal account. Your app should still verify the type of Dropbox account after authorization since the user could modify or remove the require_role parameter.
|
|
21
|
+
* @param info.options.force_reapprove Whether or not to force the user to approve the app again if they've already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.
|
|
22
|
+
* @param info.options.disable_signup When true (default is false) users will not be able to sign up for a Dropbox account via the authorization page. Instead, the authorization page will show a link to the Dropbox iOS app in the App Store. This is only intended for use when necessary for compliance with App Store policies.
|
|
23
|
+
* @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
|
|
24
|
+
* @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
|
|
19
25
|
*/
|
|
20
26
|
async init(info) {
|
|
21
27
|
// Return url to get authorization code with
|
|
22
|
-
const
|
|
28
|
+
const options = info.options || {};
|
|
29
|
+
const authUrl = `https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&locale=${options.locale || ''}&require_role=${options.require_role || ''}&force_reauthentication=${options.force_reauthentication === true}&force_reapprove=${options.force_reapprove === true}&disable_signup=${options.disable_signup === true}&state=${encodeURIComponent(info.state)}`;
|
|
23
30
|
return authUrl;
|
|
24
31
|
}
|
|
25
32
|
getAccessToken(params) {
|
|
@@ -59,10 +59,17 @@ export class DropboxAuthProvider implements IOAuth2Provider {
|
|
|
59
59
|
* Starts auth flow by getting the url the user should be redirected to
|
|
60
60
|
* @param info.redirectUrl Url dropbox will redirect to after authorizing
|
|
61
61
|
* @param info.state Optional state that will be passed to redirectUri by dropbox
|
|
62
|
+
* @param info.options Optional Dropbox specific authentication settings
|
|
63
|
+
* @param info.options.require_role If this parameter is specified, the user will be asked to authorize with a particular type of Dropbox account, either work for a team account or personal for a personal account. Your app should still verify the type of Dropbox account after authorization since the user could modify or remove the require_role parameter.
|
|
64
|
+
* @param info.options.force_reapprove Whether or not to force the user to approve the app again if they've already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.
|
|
65
|
+
* @param info.options.disable_signup When true (default is false) users will not be able to sign up for a Dropbox account via the authorization page. Instead, the authorization page will show a link to the Dropbox iOS app in the App Store. This is only intended for use when necessary for compliance with App Store policies.
|
|
66
|
+
* @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
|
|
67
|
+
* @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
|
|
62
68
|
*/
|
|
63
|
-
async init(info: { redirect_url: string, state?: string }) {
|
|
69
|
+
async init(info: { redirect_url: string, state?: string, options?: { locale?: string, require_role?: string, disable_signup?: boolean, force_reapprove?: boolean, force_reauthentication?: boolean } }) {
|
|
64
70
|
// Return url to get authorization code with
|
|
65
|
-
const
|
|
71
|
+
const options = info.options || {};
|
|
72
|
+
const authUrl = `https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&locale=${options.locale || ''}&require_role=${options.require_role || ''}&force_reauthentication=${options.force_reauthentication === true}&force_reapprove=${options.force_reapprove === true}&disable_signup=${options.disable_signup === true}&state=${encodeURIComponent(info.state)}`;
|
|
66
73
|
return authUrl;
|
|
67
74
|
}
|
|
68
75
|
|
|
@@ -19,7 +19,7 @@ export interface IOAuth2TokenResult {
|
|
|
19
19
|
refresh_token?: string
|
|
20
20
|
}
|
|
21
21
|
export interface IOAuth2Provider {
|
|
22
|
-
init(
|
|
22
|
+
init(info: { redirect_url: string, state?: string, options?: any }): Promise<string>
|
|
23
23
|
getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult>
|
|
24
24
|
getUserInfo(access_token: string): Promise<{ id: string, name: string, display_name: string, picture?: Array<{ width?: number, height?: number, url: string }>, email: string, email_verified: boolean, other?: { [key:string]: string|number|boolean } }>
|
|
25
25
|
}
|
|
@@ -145,6 +145,22 @@
|
|
|
145
145
|
/* general class to get pointer */
|
|
146
146
|
cursor: pointer;
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
@keyframes flash {
|
|
150
|
+
0%, 100% {
|
|
151
|
+
background-color: transparent;
|
|
152
|
+
}
|
|
153
|
+
50% {
|
|
154
|
+
background-color: lightskyblue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
.flash span {
|
|
158
|
+
animation-name: flash;
|
|
159
|
+
animation-duration: 1s;
|
|
160
|
+
animation-timing-function: ease-in-out;
|
|
161
|
+
animation-iteration-count: 1;
|
|
162
|
+
}
|
|
163
|
+
|
|
148
164
|
</style>
|
|
149
165
|
</head>
|
|
150
166
|
<body>
|
|
@@ -247,8 +263,8 @@ M.AutoInit();
|
|
|
247
263
|
</script>
|
|
248
264
|
|
|
249
265
|
<!-- AceBase client js -->
|
|
250
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/acebase-client@1.
|
|
251
|
-
<!-- <script type="text/javascript" src="
|
|
266
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/acebase-client@1.7.1/dist/browser.min.js"></script>
|
|
267
|
+
<!-- <script type="text/javascript" src="acebase-client-browser.min.js"></script> -->
|
|
252
268
|
|
|
253
269
|
<!-- AceBase Webmanager js -->
|
|
254
270
|
<script type="text/javascript" src="index.js"></script>
|
package/src/webmanager/index.js
CHANGED
|
@@ -202,9 +202,10 @@ function updateBrowsePath(path = '') {
|
|
|
202
202
|
return childElem;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
function addNode(nodeInfo) {
|
|
205
|
+
function addNode(nodeInfo, noFlash = false) {
|
|
206
206
|
console.log(`Adding node ${nodeInfo.key}:`, nodeInfo);
|
|
207
207
|
const childElem = createNode(nodeInfo);
|
|
208
|
+
if (!noFlash) { childElem.classList.add('flash'); }
|
|
208
209
|
container.appendChild(childElem);
|
|
209
210
|
}
|
|
210
211
|
function updateNode(nodeInfo) {
|
|
@@ -212,6 +213,7 @@ function updateBrowsePath(path = '') {
|
|
|
212
213
|
const currentElem = document.getElementById(id);
|
|
213
214
|
if (currentElem) { currentElem.id = 'prev_' + id; }
|
|
214
215
|
const newElem = createNode(nodeInfo);
|
|
216
|
+
newElem.classList.add('flash');
|
|
215
217
|
if (currentElem) {
|
|
216
218
|
container.replaceChild(newElem, currentElem);
|
|
217
219
|
}
|
|
@@ -283,7 +285,7 @@ function updateBrowsePath(path = '') {
|
|
|
283
285
|
|
|
284
286
|
// Add children
|
|
285
287
|
info.children.list.forEach(childInfo => {
|
|
286
|
-
addNode(childInfo);
|
|
288
|
+
addNode(childInfo, true);
|
|
287
289
|
});
|
|
288
290
|
|
|
289
291
|
// Is there more data?
|