acebase-server 1.19.2 → 1.20.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/README.md +19 -33
- package/api-clients/thunder-client/README.md +32 -0
- package/api-clients/thunder-client/collection.json +1069 -0
- package/api-clients/thunder-client/environment.json +25 -0
- package/dist/cjs/auth.js +10 -7
- package/dist/cjs/logger.js +3 -3
- package/dist/cjs/middleware/user.js +6 -13
- package/dist/cjs/oauth-providers/facebook.js +1 -1
- package/dist/cjs/oauth-providers/instagram.js +1 -1
- package/dist/cjs/routes/auth-change-password.js +12 -9
- package/dist/cjs/routes/auth-reset-password.js +6 -5
- package/dist/cjs/routes/auth-signin.js +15 -2
- package/dist/cjs/routes/data-reflect.js +1 -1
- package/dist/cjs/routes/data-transaction.js +7 -7
- package/dist/cjs/routes/docs.js +1 -1
- package/dist/cjs/routes/meta-info.js +2 -2
- package/dist/cjs/routes/oauth2-signin.js +2 -2
- package/dist/cjs/rules.js +4 -2
- package/dist/cjs/sandbox.js +2 -3
- package/dist/cjs/server.js +5 -2
- package/dist/cjs/shared/admin.js +1 -2
- package/dist/cjs/shared/error.js +2 -1
- package/dist/cjs/shared/http.js +17 -0
- package/dist/cjs/shared/signin.js +72 -76
- package/dist/cjs/shared/simple-fetch.js +1 -2
- package/dist/cjs/shared/tokens.js +1 -1
- package/dist/cjs/start.js +1 -1
- package/dist/cjs/websocket/index.js +10 -10
- package/dist/cjs/websocket/socket.io.js +2 -2
- package/dist/esm/auth.js +10 -7
- package/dist/esm/middleware/user.js +6 -13
- package/dist/esm/oauth-providers/facebook.js +1 -1
- package/dist/esm/oauth-providers/instagram.js +1 -1
- package/dist/esm/routes/auth-change-password.js +11 -8
- package/dist/esm/routes/auth-reset-password.js +3 -3
- package/dist/esm/routes/auth-signin.js +17 -4
- package/dist/esm/routes/data-reflect.js +1 -1
- package/dist/esm/routes/docs.js +1 -1
- package/dist/esm/routes/meta-info.js +2 -2
- package/dist/esm/routes/oauth2-signin.js +2 -2
- package/dist/esm/rules.js +4 -2
- package/dist/esm/server.js +4 -1
- package/dist/esm/shared/error.js +1 -1
- package/dist/esm/shared/http.js +17 -0
- package/dist/esm/shared/signin.js +87 -75
- package/dist/esm/shared/tokens.js +1 -1
- package/dist/esm/start.js +1 -1
- package/dist/esm/websocket/socket.io.js +2 -2
- package/dist/types/routes/auth-change-password.d.ts +1 -0
- package/dist/types/rules.d.ts +1 -1
- package/dist/types/schema/user.d.ts +4 -0
- package/dist/types/settings/index.d.ts +0 -2
- package/dist/types/shared/clients.d.ts +0 -1
- package/dist/types/shared/env.d.ts +12 -11
- package/dist/types/shared/http.d.ts +2 -2
- package/dist/types/shared/password.d.ts +1 -1
- package/dist/types/shared/signin.d.ts +4 -6
- package/dist/types/shared/simple-fetch.d.ts +2 -2
- package/dist/types/shared/tokens.d.ts +1 -1
- package/package.json +10 -11
- package/release_notes.md +21 -2
- package/src/routes/auth-change-password.yaml +9 -0
- package/src/routes/auth-signin.yaml +2 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"clientName": "Thunder Client",
|
|
3
|
+
"environmentName": "AceBase Server",
|
|
4
|
+
"environmentId": "6b7c8d9e-0f1a-2b3c-4d5e-6f7a8b9c0d1e",
|
|
5
|
+
"dateExported": "2026-11-16T00:00:00.000Z",
|
|
6
|
+
"version": "1.2",
|
|
7
|
+
"ref": "environment.json",
|
|
8
|
+
"variables": [
|
|
9
|
+
{
|
|
10
|
+
"name": "base_url",
|
|
11
|
+
"value": "http://localhost:3000",
|
|
12
|
+
"isEnabled": true
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "dbname",
|
|
16
|
+
"value": "default",
|
|
17
|
+
"isEnabled": true
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "access_token",
|
|
21
|
+
"value": "",
|
|
22
|
+
"isEnabled": true
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
package/dist/cjs/auth.js
CHANGED
|
@@ -17,16 +17,19 @@ const setupAuthentication = (env) => __awaiter(void 0, void 0, void 0, function*
|
|
|
17
17
|
// Setup auth cache
|
|
18
18
|
env.authCache = new acebase_core_1.SimpleCache({ expirySeconds: 300, cloneValues: false, maxEntries: 1000 });
|
|
19
19
|
// Get or generate a salt to hash public tokens with
|
|
20
|
-
yield env.securityRef.child('token_salt').transaction(snap => {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
yield env.securityRef.child('token_salt').transaction((snap) => {
|
|
21
|
+
if (snap.exists()) {
|
|
22
|
+
env.tokenSalt = snap.val();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// Generate new salt and store it
|
|
23
26
|
const length = 256;
|
|
24
27
|
env.tokenSalt = (0, crypto_1.randomBytes)(Math.ceil(length / 2)).toString('hex').slice(0, length);
|
|
25
28
|
return env.tokenSalt;
|
|
26
29
|
}
|
|
27
30
|
});
|
|
28
31
|
// Setup admin account
|
|
29
|
-
yield env.authRef.child('admin').transaction(snap => {
|
|
32
|
+
yield env.authRef.child('admin').transaction((snap) => {
|
|
30
33
|
let adminAccount = snap.val();
|
|
31
34
|
if (adminAccount === null) {
|
|
32
35
|
// Use provided default password, or generate one:
|
|
@@ -35,13 +38,13 @@ const setupAuthentication = (env) => __awaiter(void 0, void 0, void 0, function*
|
|
|
35
38
|
adminAccount = {
|
|
36
39
|
uid: null,
|
|
37
40
|
username: 'admin',
|
|
38
|
-
email: null,
|
|
41
|
+
email: null, // no email address for admin
|
|
39
42
|
display_name: `${env.db.name} AceBase admin`,
|
|
40
43
|
password: pwd.hash,
|
|
41
44
|
password_salt: pwd.salt,
|
|
42
|
-
change_password: true,
|
|
45
|
+
change_password: true, // flags that password must be changed. Not implemented yet
|
|
43
46
|
created: new Date(),
|
|
44
|
-
access_token: null,
|
|
47
|
+
access_token: null, // Will be set upon login, so bearer authentication strategy can find user with this token
|
|
45
48
|
settings: {},
|
|
46
49
|
};
|
|
47
50
|
env.debug.warn(`__________________________________________________________________`.colorize(acebase_core_1.ColorStyle.red));
|
package/dist/cjs/logger.js
CHANGED
|
@@ -21,8 +21,8 @@ class DatabaseLog {
|
|
|
21
21
|
* @param details any additional details to be logged
|
|
22
22
|
*/
|
|
23
23
|
event(action, details) {
|
|
24
|
-
var _a;
|
|
25
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
var _a;
|
|
26
26
|
yield ((_a = this.logRef) === null || _a === void 0 ? void 0 : _a.push(Object.assign({ type: 'event', action, date: new Date() }, details)));
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -33,8 +33,8 @@ class DatabaseLog {
|
|
|
33
33
|
* @param details any additional details to be logged
|
|
34
34
|
*/
|
|
35
35
|
warning(action, code, details) {
|
|
36
|
-
var _a;
|
|
37
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
38
38
|
yield ((_a = this.logRef) === null || _a === void 0 ? void 0 : _a.push(Object.assign({ type: 'warning', action, code, date: new Date() }, details)));
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -45,8 +45,8 @@ class DatabaseLog {
|
|
|
45
45
|
* @param details any additional details to be logged
|
|
46
46
|
*/
|
|
47
47
|
error(action, code, details, unexpectedError) {
|
|
48
|
-
var _a, _b, _c, _d;
|
|
49
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a, _b, _c, _d;
|
|
50
50
|
const errorDetails = unexpectedError instanceof Error
|
|
51
51
|
? { error: (_a = unexpectedError.stack) !== null && _a !== void 0 ? _a : unexpectedError.message }
|
|
52
52
|
: { error: (_c = (_b = unexpectedError === null || unexpectedError === void 0 ? void 0 : unexpectedError.message) !== null && _b !== void 0 ? _b : unexpectedError === null || unexpectedError === void 0 ? void 0 : unexpectedError.toString()) !== null && _c !== void 0 ? _c : null };
|
|
@@ -34,21 +34,14 @@ const addMiddleware = (env) => {
|
|
|
34
34
|
tokenDetails = (0, tokens_1.decodePublicAccessToken)(token, env.tokenSalt);
|
|
35
35
|
}
|
|
36
36
|
catch (err) {
|
|
37
|
-
return (0, error_1.sendNotAuthenticatedError)(res, 'invalid_token', '
|
|
37
|
+
return (0, error_1.sendNotAuthenticatedError)(res, 'invalid_token', 'Access token is invalid. Sign in again');
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Query database to get user for this token
|
|
43
|
-
try {
|
|
44
|
-
req.user = yield (0, signin_1.signIn)({ method: 'internal', access_token: tokenDetails.access_token }, env, req);
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
return (0, error_1.sendNotAuthenticatedError)(res, err.code, err.message);
|
|
48
|
-
}
|
|
39
|
+
try {
|
|
40
|
+
// Query database to get user for this token, assign to request
|
|
41
|
+
req.user = yield (0, signin_1.signIn)({ method: 'token', uid: tokenDetails.uid, access_token: tokenDetails.access_token }, env, req.ip, false);
|
|
49
42
|
}
|
|
50
|
-
|
|
51
|
-
return (0, error_1.sendNotAuthenticatedError)(res,
|
|
43
|
+
catch (err) {
|
|
44
|
+
return (0, error_1.sendNotAuthenticatedError)(res, err.code, err.message);
|
|
52
45
|
}
|
|
53
46
|
}
|
|
54
47
|
next();
|
|
@@ -73,7 +73,7 @@ class FacebookAuthProvider extends oauth_provider_1.OAuth2Provider {
|
|
|
73
73
|
display_name: user.short_name,
|
|
74
74
|
picture: user.picture.data.is_silhouette ? null : [{ width: user.picture.data.width, height: user.picture.data.height, url: user.picture.data.url }],
|
|
75
75
|
email: user.email,
|
|
76
|
-
email_verified: typeof user.email === 'string',
|
|
76
|
+
email_verified: typeof user.email === 'string', // If we get the email address, it's always verified
|
|
77
77
|
other: {
|
|
78
78
|
// We haven't requested more, so we didn't get more
|
|
79
79
|
},
|
|
@@ -67,7 +67,7 @@ class InstagramAuthProvider extends oauth_provider_1.OAuth2Provider {
|
|
|
67
67
|
name: user.full_name,
|
|
68
68
|
display_name: user.username,
|
|
69
69
|
picture: [{ url: user.profile_picture }],
|
|
70
|
-
email: null,
|
|
70
|
+
email: null, //NO E-MAIL! user.email,
|
|
71
71
|
email_verified: false,
|
|
72
72
|
other: Object.keys(user)
|
|
73
73
|
.filter(key => !['id', 'username', 'full_name', 'profile_picture'].includes(key))
|
|
@@ -23,8 +23,8 @@ class ChangePasswordError extends Error {
|
|
|
23
23
|
exports.ChangePasswordError = ChangePasswordError;
|
|
24
24
|
const addRoute = (env) => {
|
|
25
25
|
env.router.post(`/auth/${env.db.name}/change_password`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
var _a, _b;
|
|
27
|
-
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
let accessToken = (_a = req.user) === null || _a === void 0 ? void 0 : _a.access_token;
|
|
28
28
|
const details = req.body;
|
|
29
29
|
const LOG_ACTION = 'auth.change_password';
|
|
30
30
|
const LOG_DETAILS = { ip: req.ip, uid: (_b = details.uid) !== null && _b !== void 0 ? _b : null };
|
|
@@ -40,7 +40,7 @@ const addRoute = (env) => {
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
const signOutOtherClients = details.sign_out === true;
|
|
44
44
|
yield env.authRef.child(details.uid).transaction(snap => {
|
|
45
45
|
if (!snap.exists()) {
|
|
46
46
|
throw new ChangePasswordError('unknown_uid', `Unknown uid`);
|
|
@@ -51,29 +51,32 @@ const addRoute = (env) => {
|
|
|
51
51
|
if (user.password !== hash) {
|
|
52
52
|
throw new ChangePasswordError('wrong_password', `Wrong password`);
|
|
53
53
|
}
|
|
54
|
-
if (
|
|
54
|
+
if (accessToken && accessToken !== user.access_token) {
|
|
55
55
|
throw new ChangePasswordError('wrong_access_token', `Cannot change password while signed in as other user, or with an old token`);
|
|
56
56
|
}
|
|
57
57
|
const pwd = (0, password_1.createPasswordHash)(details.new_password);
|
|
58
58
|
const updates = {
|
|
59
|
-
access_token: acebase_core_1.ID.generate(),
|
|
60
|
-
access_token_created: new Date(),
|
|
61
59
|
password: pwd.hash,
|
|
62
60
|
password_salt: pwd.salt,
|
|
63
61
|
};
|
|
62
|
+
if (signOutOtherClients || !accessToken) {
|
|
63
|
+
accessToken = acebase_core_1.ID.generate();
|
|
64
|
+
updates.access_token = accessToken;
|
|
65
|
+
updates.access_token_created = new Date();
|
|
66
|
+
}
|
|
64
67
|
// Update user object
|
|
65
68
|
Object.assign(user, updates);
|
|
66
69
|
// Set or update cache
|
|
67
70
|
env.authCache.set(user.uid, user);
|
|
68
|
-
// Create new public access token
|
|
69
|
-
publicAccessToken = (0, tokens_1.createPublicAccessToken)(user.uid, req.ip, user.access_token, env.tokenSalt);
|
|
70
71
|
return user; // Update db
|
|
71
72
|
});
|
|
73
|
+
// Create new public access token
|
|
74
|
+
const publicAccessToken = (0, tokens_1.createPublicAccessToken)(details.uid, req.ip, accessToken, env.tokenSalt);
|
|
72
75
|
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
73
76
|
res.send({ access_token: publicAccessToken }); // Client must use this new access token from now on
|
|
74
77
|
}
|
|
75
78
|
catch (err) {
|
|
76
|
-
env.log.error(LOG_ACTION, err.code, LOG_DETAILS);
|
|
79
|
+
env.log.error(LOG_ACTION, (_c = err === null || err === void 0 ? void 0 : err.code) !== null && _c !== void 0 ? _c : 'unknown', LOG_DETAILS);
|
|
77
80
|
if (err.code) {
|
|
78
81
|
(0, error_1.sendBadRequestError)(res, err);
|
|
79
82
|
}
|
|
@@ -29,11 +29,12 @@ const addRoute = (env) => {
|
|
|
29
29
|
const resetPassword = (clientIp, code, newPassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
30
|
var _a;
|
|
31
31
|
const verification = (() => {
|
|
32
|
+
var _a;
|
|
32
33
|
try {
|
|
33
34
|
return (0, tokens_1.parseSignedPublicToken)(code, env.tokenSalt);
|
|
34
35
|
}
|
|
35
36
|
catch (err) {
|
|
36
|
-
throw new ResetPasswordError('invalid_code', err.message);
|
|
37
|
+
throw new ResetPasswordError('invalid_code', (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : '');
|
|
37
38
|
}
|
|
38
39
|
})();
|
|
39
40
|
const snap = yield env.authRef.child(verification.uid).get();
|
|
@@ -72,18 +73,18 @@ const addRoute = (env) => {
|
|
|
72
73
|
return user;
|
|
73
74
|
});
|
|
74
75
|
env.router.post(`/auth/${env.db.name}/reset_password`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
-
var _b, _c, _d, _e;
|
|
76
|
+
var _a, _b, _c, _d, _e;
|
|
76
77
|
const details = req.body;
|
|
77
78
|
const LOG_ACTION = 'auth.reset_password';
|
|
78
|
-
const LOG_DETAILS = { ip: req.ip, uid: (
|
|
79
|
+
const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null };
|
|
79
80
|
try {
|
|
80
81
|
const user = yield resetPassword(req.ip, details.code, details.password);
|
|
81
82
|
env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { reset_uid: user.uid }));
|
|
82
83
|
res.send('OK');
|
|
83
84
|
}
|
|
84
85
|
catch (err) {
|
|
85
|
-
env.log.error(LOG_ACTION, (
|
|
86
|
-
if (err.code) {
|
|
86
|
+
env.log.error(LOG_ACTION, (_c = err === null || err === void 0 ? void 0 : err.code) !== null && _c !== void 0 ? _c : 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: (_e = (_d = err === null || err === void 0 ? void 0 : err.message) !== null && _d !== void 0 ? _d : err === null || err === void 0 ? void 0 : err.toString()) !== null && _e !== void 0 ? _e : 'Unexpected error' }));
|
|
87
|
+
if (err === null || err === void 0 ? void 0 : err.code) {
|
|
87
88
|
(0, error_1.sendBadRequestError)(res, err);
|
|
88
89
|
}
|
|
89
90
|
else {
|
|
@@ -22,7 +22,20 @@ const addRoute = (env) => {
|
|
|
22
22
|
const details = req.body;
|
|
23
23
|
const clientId = details.client_id || null; // NEW in AceBaseClient v0.9.4
|
|
24
24
|
try {
|
|
25
|
-
const
|
|
25
|
+
const credentials = (() => {
|
|
26
|
+
if (details.method === 'token') {
|
|
27
|
+
// This is a public access token, convert to a private token that contains the user's uid and actual access token
|
|
28
|
+
try {
|
|
29
|
+
const tokenDetails = (0, tokens_1.decodePublicAccessToken)(details.access_token, env.tokenSalt);
|
|
30
|
+
return { method: 'token', uid: tokenDetails.uid, access_token: tokenDetails.access_token };
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw new signin_1.SignInError('invalid_token', `Access token is invalid. Sign in again`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return details;
|
|
37
|
+
})();
|
|
38
|
+
const user = yield (0, signin_1.signIn)(credentials, env, req.ip, true);
|
|
26
39
|
if (typeof clientId === 'string' && env.clients.has(clientId)) {
|
|
27
40
|
const client = env.clients.get(clientId);
|
|
28
41
|
client.user = user; // Bind user to client socket
|
|
@@ -33,7 +46,7 @@ const addRoute = (env) => {
|
|
|
33
46
|
});
|
|
34
47
|
}
|
|
35
48
|
catch (err) {
|
|
36
|
-
if (typeof err.code === 'string') {
|
|
49
|
+
if (typeof (err === null || err === void 0 ? void 0 : err.code) === 'string') {
|
|
37
50
|
// Authentication error
|
|
38
51
|
return (0, error_1.sendNotAuthenticatedError)(res, err.code, err.message);
|
|
39
52
|
}
|
|
@@ -81,7 +81,7 @@ const addRoute = (env) => {
|
|
|
81
81
|
}
|
|
82
82
|
for (const childInfo of list !== null && list !== void 0 ? list : []) {
|
|
83
83
|
childInfo.access = {
|
|
84
|
-
read: (yield env.rules.isOperationAllowed(impersonatedUser, acebase_core_1.PathInfo.getChildPath(path, childInfo.key), 'get')).allow,
|
|
84
|
+
read: (yield env.rules.isOperationAllowed(impersonatedUser, acebase_core_1.PathInfo.getChildPath(path, childInfo.key), 'get')).allow, // Use pre-flight 'get' check to mimic legacy 'read' check
|
|
85
85
|
write: (yield env.rules.isOperationAllowed(impersonatedUser, acebase_core_1.PathInfo.getChildPath(path, childInfo.key), 'update')).allow, // Use pre-flight 'update' check to mimic legacy 'write' check
|
|
86
86
|
};
|
|
87
87
|
}
|
|
@@ -54,11 +54,11 @@ const addRoutes = (env) => {
|
|
|
54
54
|
env.debug.verbose(`Transaction ${tx.id} starting...`);
|
|
55
55
|
// const ref = db.ref(tx.path);
|
|
56
56
|
const donePromise = env.db.api.transaction(tx.path, (val) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
var
|
|
57
|
+
var _a;
|
|
58
58
|
env.debug.verbose(`Transaction ${tx.id} started with value: `, val);
|
|
59
59
|
const access = yield env.rules.isOperationAllowed(req.user, data.path, 'get', { value: val, context: req.context });
|
|
60
60
|
if (!access.allow) {
|
|
61
|
-
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (
|
|
61
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_a = access.rulePath) !== null && _a !== void 0 ? _a : null }), access.details);
|
|
62
62
|
(0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
63
63
|
return; // Return undefined to cancel transaction
|
|
64
64
|
}
|
|
@@ -84,13 +84,13 @@ const addRoutes = (env) => {
|
|
|
84
84
|
}));
|
|
85
85
|
// Finish transaction endpoint:
|
|
86
86
|
env.router.post(`/transaction/${env.db.name}/finish`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
-
var
|
|
87
|
+
var _a, _b, _c, _d, _e, _f;
|
|
88
88
|
const data = req.body;
|
|
89
89
|
const LOG_ACTION = 'data.transaction.finish';
|
|
90
|
-
const LOG_DETAILS = { ip: req.ip, uid: (
|
|
90
|
+
const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path: data.path };
|
|
91
91
|
const tx = _transactions.get(data.id);
|
|
92
92
|
if (!tx || tx.path !== data.path) {
|
|
93
|
-
env.log.error(LOG_ACTION, tx ? 'wrong_path' : 'not_found', Object.assign(Object.assign({}, LOG_DETAILS), { id: data.id, tx_path: (
|
|
93
|
+
env.log.error(LOG_ACTION, tx ? 'wrong_path' : 'not_found', Object.assign(Object.assign({}, LOG_DETAILS), { id: data.id, tx_path: (_c = tx === null || tx === void 0 ? void 0 : tx.path) !== null && _c !== void 0 ? _c : null }));
|
|
94
94
|
res.statusCode = 410; // Gone
|
|
95
95
|
res.send(`transaction not found`);
|
|
96
96
|
return;
|
|
@@ -111,7 +111,7 @@ const addRoutes = (env) => {
|
|
|
111
111
|
// then is sent to the server as an empty object: {}
|
|
112
112
|
cancel = true;
|
|
113
113
|
}
|
|
114
|
-
else if (typeof ((
|
|
114
|
+
else if (typeof ((_d = data.value) === null || _d === void 0 ? void 0 : _d.val) === 'undefined' || !['string', 'object', 'undefined'].includes(typeof ((_e = data.value) === null || _e === void 0 ? void 0 : _e.map))) {
|
|
115
115
|
throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
116
116
|
}
|
|
117
117
|
const newValue = cancel ? undefined : acebase_core_1.Transport.deserialize(data.value);
|
|
@@ -137,7 +137,7 @@ const addRoutes = (env) => {
|
|
|
137
137
|
tx.finish(); // Finish without value cancels the transaction
|
|
138
138
|
if (err instanceof rules_1.AccessRuleValidationError) {
|
|
139
139
|
const access = err.result;
|
|
140
|
-
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (
|
|
140
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_f = access.rulePath) !== null && _f !== void 0 ? _f : null }), access.details);
|
|
141
141
|
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
142
142
|
}
|
|
143
143
|
else if (err instanceof acebase_1.SchemaValidationError) {
|
package/dist/cjs/routes/docs.js
CHANGED
|
@@ -19,7 +19,7 @@ const addRoute = (env) => {
|
|
|
19
19
|
info: {
|
|
20
20
|
title: 'AceBase Server',
|
|
21
21
|
description: 'AceBase Server API endpoint documentation and test environment. This documentation is available on the server because it is running in development mode. To disable this, set your NODE_ENV environment variable to production. Many endpoints require you to authenticate using Bearer authentication. Use the _/auth/{dbname}/signin_ endpoint to obtain an access token, then click the _Authorize_ button and paste your token into the input field. For more information about AceBase, see GitHub',
|
|
22
|
-
version: '1.
|
|
22
|
+
version: '1.20.0', // Loaded from package.json by npm scripts
|
|
23
23
|
contact: {
|
|
24
24
|
name: 'AceBase API Support',
|
|
25
25
|
email: 'me@appy.one',
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addRoute = void 0;
|
|
4
4
|
const admin_1 = require("../shared/admin");
|
|
5
5
|
const os = require("os");
|
|
6
|
-
const SERVER_VERSION = '1.
|
|
6
|
+
const SERVER_VERSION = '1.20.0'; // Loaded from package.json by npm scripts
|
|
7
7
|
const addRoute = (env) => {
|
|
8
8
|
// Add info endpoint
|
|
9
9
|
env.router.get(`/info/${env.db.name}`, (req, res) => {
|
|
@@ -42,7 +42,7 @@ const addRoute = (env) => {
|
|
|
42
42
|
total: numberToByteSize(os.totalmem()),
|
|
43
43
|
free: numberToByteSize(os.freemem()),
|
|
44
44
|
process: {
|
|
45
|
-
arrayBuffers: numberToByteSize(mem.arrayBuffers),
|
|
45
|
+
arrayBuffers: numberToByteSize(mem.arrayBuffers), // arrayBuffers was added in Node v13.9.0, v12.17.0
|
|
46
46
|
external: numberToByteSize(mem.external),
|
|
47
47
|
heapTotal: numberToByteSize(mem.heapTotal),
|
|
48
48
|
heapUsed: numberToByteSize(mem.heapUsed),
|
|
@@ -179,9 +179,9 @@ const addRoute = (env) => {
|
|
|
179
179
|
const pwd = (0, password_1.createPasswordHash)((0, password_1.generatePassword)());
|
|
180
180
|
user = {
|
|
181
181
|
uid: null,
|
|
182
|
-
username: typeof user_details.email === 'undefined' ? providerUsername : null,
|
|
182
|
+
username: typeof user_details.email === 'undefined' ? providerUsername : null, // provider-accountid usernames for external accounts without email address
|
|
183
183
|
email: user_details.email || null,
|
|
184
|
-
email_verified: user_details.email_verified,
|
|
184
|
+
email_verified: user_details.email_verified, // trust provider's verification
|
|
185
185
|
display_name: user_details.display_name,
|
|
186
186
|
password: pwd.hash,
|
|
187
187
|
password_salt: pwd.salt,
|
package/dist/cjs/rules.js
CHANGED
|
@@ -125,10 +125,12 @@ class PathBasedRules {
|
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
fs.watchFile(rulesFilePath, watchFileListener);
|
|
128
|
-
|
|
128
|
+
const stop = () => {
|
|
129
129
|
fs.unwatchFile(rulesFilePath, watchFileListener);
|
|
130
|
+
process.off('SIGINT', stop);
|
|
130
131
|
};
|
|
131
|
-
|
|
132
|
+
this.stop = stop;
|
|
133
|
+
process.on('SIGINT', stop);
|
|
132
134
|
this.authEnabled = env.authEnabled;
|
|
133
135
|
this.accessRules = accessRules;
|
|
134
136
|
}
|
package/dist/cjs/sandbox.js
CHANGED
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.executeSandboxed = executeSandboxed;
|
|
13
|
+
exports.isCodeSafe = isCodeSafe;
|
|
13
14
|
const vm_1 = require("vm");
|
|
14
15
|
function executeSandboxed(code, env) {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -20,9 +21,7 @@ function executeSandboxed(code, env) {
|
|
|
20
21
|
return result;
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
|
-
exports.executeSandboxed = executeSandboxed;
|
|
24
24
|
function isCodeSafe(code) {
|
|
25
25
|
return /eval|prototype|require|import/.test(code); // Do not allow prototype access, require or import statements
|
|
26
26
|
}
|
|
27
|
-
exports.isCodeSafe = isCodeSafe;
|
|
28
27
|
//# sourceMappingURL=sandbox.js.map
|
package/dist/cjs/server.js
CHANGED
|
@@ -104,8 +104,8 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
|
|
|
104
104
|
this.init({ authDb });
|
|
105
105
|
}
|
|
106
106
|
init(env) {
|
|
107
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
108
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
109
109
|
const config = this.config;
|
|
110
110
|
const db = this.db;
|
|
111
111
|
const authDb = env.authDb;
|
|
@@ -226,7 +226,10 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
|
|
|
226
226
|
});
|
|
227
227
|
});
|
|
228
228
|
// Handle SIGINT and shutdown requests
|
|
229
|
+
const sigintHandler = () => shutdown({ sigint: true });
|
|
229
230
|
const shutdown = (request) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
// Don't keep listening for SIGINT once the server has been shut down
|
|
232
|
+
process.off('SIGINT', sigintHandler);
|
|
230
233
|
this.debug.warn('shutting down server');
|
|
231
234
|
routeEnv.rules.stop();
|
|
232
235
|
const getConnectionsCount = () => {
|
|
@@ -327,7 +330,7 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
|
|
|
327
330
|
this._ready = true;
|
|
328
331
|
this.emitOnce(`ready`);
|
|
329
332
|
});
|
|
330
|
-
process.on('SIGINT',
|
|
333
|
+
process.on('SIGINT', sigintHandler);
|
|
331
334
|
}
|
|
332
335
|
});
|
|
333
336
|
}
|
package/dist/cjs/shared/admin.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isAdmin =
|
|
3
|
+
exports.isAdmin = isAdmin;
|
|
4
4
|
function isAdmin(user) {
|
|
5
5
|
return (user === null || user === void 0 ? void 0 : user.uid) === 'admin' || ((user === null || user === void 0 ? void 0 : user.roles) || []).includes('admin');
|
|
6
6
|
}
|
|
7
|
-
exports.isAdmin = isAdmin;
|
|
8
7
|
//# sourceMappingURL=admin.js.map
|
package/dist/cjs/shared/error.js
CHANGED
|
@@ -28,7 +28,8 @@ const sendBadRequestError = (res, err) => {
|
|
|
28
28
|
};
|
|
29
29
|
exports.sendBadRequestError = sendBadRequestError;
|
|
30
30
|
const sendUnexpectedError = (res, err) => {
|
|
31
|
-
|
|
31
|
+
var _a;
|
|
32
|
+
res.status(500).contentType('application/json').send({ code: 'unexpected', message: 'server error', details: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : 'Unknown error' }); // Internal server error
|
|
32
33
|
};
|
|
33
34
|
exports.sendUnexpectedError = sendUnexpectedError;
|
|
34
35
|
//# sourceMappingURL=error.js.map
|
package/dist/cjs/shared/http.js
CHANGED
|
@@ -15,6 +15,23 @@ const createApp = (settings) => {
|
|
|
15
15
|
app.set('trust proxy', settings.trustProxy);
|
|
16
16
|
// Parse json request bodies
|
|
17
17
|
app.use(express.json({ limit: settings.maxPayloadSize })); // , extended: true ?
|
|
18
|
+
// Handle body parsing errors ourselves, preventing Express' default error handler from
|
|
19
|
+
// sending detailed error info (including stack trace) to the client
|
|
20
|
+
app.use((err, req, res, next) => {
|
|
21
|
+
if (typeof (err === null || err === void 0 ? void 0 : err.type) !== 'string' || typeof (err === null || err === void 0 ? void 0 : err.status) !== 'number') {
|
|
22
|
+
// Not a body-parser error
|
|
23
|
+
return next(err);
|
|
24
|
+
}
|
|
25
|
+
const code = err.type === 'entity.parse.failed' ? 'invalid_json'
|
|
26
|
+
: err.type === 'entity.too.large' ? 'payload_too_large'
|
|
27
|
+
: 'invalid_body';
|
|
28
|
+
const message = err.type === 'entity.parse.failed' ? 'Request body is not valid JSON'
|
|
29
|
+
: err.type === 'entity.too.large' ? 'Request body is too large'
|
|
30
|
+
: 'Request body could not be read';
|
|
31
|
+
res.status(err.status >= 400 && err.status < 500 ? err.status : 400)
|
|
32
|
+
.contentType('application/json')
|
|
33
|
+
.send({ code, message });
|
|
34
|
+
});
|
|
18
35
|
return app;
|
|
19
36
|
};
|
|
20
37
|
exports.createApp = createApp;
|