acebase-server 1.11.0 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +24 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/logger.js +74 -0
- package/dist/cjs/middleware/admin-only.js +29 -0
- package/dist/cjs/middleware/user.js +4 -4
- package/dist/cjs/routes/auth-change-password.js +7 -4
- package/dist/cjs/routes/auth-delete.js +9 -7
- package/dist/cjs/routes/auth-forgot-password.js +9 -6
- package/dist/cjs/routes/auth-reset-password.js +5 -3
- package/dist/cjs/routes/auth-signout.js +6 -4
- package/dist/cjs/routes/auth-signup.js +17 -15
- package/dist/cjs/routes/auth-update.js +9 -6
- package/dist/cjs/routes/auth-verify-email.js +6 -3
- package/dist/cjs/routes/data-index-create.js +3 -5
- package/dist/cjs/routes/data-index-delete.js +2 -4
- package/dist/cjs/routes/data-index-list.js +2 -4
- package/dist/cjs/routes/data-reflect.js +2 -4
- package/dist/cjs/routes/data-schema-get.js +2 -4
- package/dist/cjs/routes/data-schema-set.js +2 -4
- package/dist/cjs/routes/data-schema-test.js +2 -4
- package/dist/cjs/routes/data-schemas-list.js +2 -4
- package/dist/cjs/routes/data-set.js +8 -7
- package/dist/cjs/routes/data-transaction.js +15 -8
- package/dist/cjs/routes/data-update.js +8 -6
- package/dist/cjs/routes/meta-logs.js +50 -0
- package/dist/cjs/routes/meta.js +3 -0
- package/dist/cjs/routes/oauth2-signin.js +9 -6
- package/dist/cjs/server.js +3 -1
- package/dist/cjs/shared/rootpath.js +2 -0
- package/dist/cjs/shared/signin.js +8 -3
- package/dist/cjs/start.js +3 -0
- package/dist/cjs/websocket/index.js +42 -23
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/logger.js +52 -0
- package/dist/esm/middleware/admin-only.js +25 -0
- package/dist/esm/middleware/user.js +4 -4
- package/dist/esm/routes/auth-change-password.js +6 -3
- package/dist/esm/routes/auth-delete.js +7 -5
- package/dist/esm/routes/auth-forgot-password.js +8 -6
- package/dist/esm/routes/auth-reset-password.js +4 -2
- package/dist/esm/routes/auth-signout.js +4 -2
- package/dist/esm/routes/auth-signup.js +12 -10
- package/dist/esm/routes/auth-update.js +8 -6
- package/dist/esm/routes/auth-verify-email.js +6 -2
- package/dist/esm/routes/data-index-create.js +4 -6
- package/dist/esm/routes/data-index-delete.js +3 -5
- package/dist/esm/routes/data-index-list.js +3 -5
- package/dist/esm/routes/data-reflect.js +1 -4
- package/dist/esm/routes/data-schema-get.js +3 -5
- package/dist/esm/routes/data-schema-set.js +3 -5
- package/dist/esm/routes/data-schema-test.js +3 -5
- package/dist/esm/routes/data-schemas-list.js +3 -5
- package/dist/esm/routes/data-set.js +6 -5
- package/dist/esm/routes/data-transaction.js +12 -5
- package/dist/esm/routes/data-update.js +6 -4
- package/dist/esm/routes/meta-logs.js +36 -0
- package/dist/esm/routes/meta.js +3 -0
- package/dist/esm/routes/oauth2-signin.js +8 -5
- package/dist/esm/server.js +3 -1
- package/dist/esm/shared/rootpath.js +2 -0
- package/dist/esm/shared/signin.js +7 -3
- package/dist/esm/start.js +3 -0
- package/dist/esm/websocket/index.js +37 -22
- package/dist/types/logger.d.ts +35 -0
- package/dist/types/middleware/admin-only.d.ts +19 -0
- package/dist/types/routes/meta-logs.d.ts +20 -0
- package/dist/types/rules.d.ts +2 -2
- package/dist/types/shared/env.d.ts +3 -1
- package/dist/types/shared/signin.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +4 -0
- package/package.json +5 -5
- package/webmanager/acebase-client-browser.min.js +16 -16
- package/create-package-files +0 -12
- package/dist/cjs/auth.js.map +0 -1
- package/dist/cjs/cluster.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/middleware/404.js.map +0 -1
- package/dist/cjs/middleware/cache.js.map +0 -1
- package/dist/cjs/middleware/connection.js.map +0 -1
- package/dist/cjs/middleware/context.js.map +0 -1
- package/dist/cjs/middleware/cors.js.map +0 -1
- package/dist/cjs/middleware/swagger.js.map +0 -1
- package/dist/cjs/middleware/user.js.map +0 -1
- package/dist/cjs/oauth-providers/dropbox.js.map +0 -1
- package/dist/cjs/oauth-providers/facebook.js.map +0 -1
- package/dist/cjs/oauth-providers/google.js.map +0 -1
- package/dist/cjs/oauth-providers/index.js.map +0 -1
- package/dist/cjs/oauth-providers/instagram.js.map +0 -1
- package/dist/cjs/oauth-providers/oauth-provider.js.map +0 -1
- package/dist/cjs/oauth-providers/spotify.js.map +0 -1
- package/dist/cjs/routes/auth-change-password.js.map +0 -1
- package/dist/cjs/routes/auth-delete.js.map +0 -1
- package/dist/cjs/routes/auth-forgot-password.js.map +0 -1
- package/dist/cjs/routes/auth-reset-password.js.map +0 -1
- package/dist/cjs/routes/auth-signin.js.map +0 -1
- package/dist/cjs/routes/auth-signout.js.map +0 -1
- package/dist/cjs/routes/auth-signup.js.map +0 -1
- package/dist/cjs/routes/auth-state.js.map +0 -1
- package/dist/cjs/routes/auth-update.js.map +0 -1
- package/dist/cjs/routes/auth-verify-email.js.map +0 -1
- package/dist/cjs/routes/auth.js.map +0 -1
- package/dist/cjs/routes/data-exists.js.map +0 -1
- package/dist/cjs/routes/data-export.js.map +0 -1
- package/dist/cjs/routes/data-get.js.map +0 -1
- package/dist/cjs/routes/data-import.js.map +0 -1
- package/dist/cjs/routes/data-index-create.js.map +0 -1
- package/dist/cjs/routes/data-index-delete.js.map +0 -1
- package/dist/cjs/routes/data-index-list.js.map +0 -1
- package/dist/cjs/routes/data-query.js.map +0 -1
- package/dist/cjs/routes/data-reflect.js.map +0 -1
- package/dist/cjs/routes/data-schema-get.js.map +0 -1
- package/dist/cjs/routes/data-schema-set.js.map +0 -1
- package/dist/cjs/routes/data-schema-test.js.map +0 -1
- package/dist/cjs/routes/data-schemas-list.js.map +0 -1
- package/dist/cjs/routes/data-set.js.map +0 -1
- package/dist/cjs/routes/data-sync-changes.js.map +0 -1
- package/dist/cjs/routes/data-sync-mutations.js.map +0 -1
- package/dist/cjs/routes/data-transaction.js.map +0 -1
- package/dist/cjs/routes/data-update.js.map +0 -1
- package/dist/cjs/routes/data.js.map +0 -1
- package/dist/cjs/routes/docs.js.map +0 -1
- package/dist/cjs/routes/meta-info.js.map +0 -1
- package/dist/cjs/routes/meta-ping.js.map +0 -1
- package/dist/cjs/routes/meta-stats.js.map +0 -1
- package/dist/cjs/routes/meta.js.map +0 -1
- package/dist/cjs/routes/oauth2-init.js.map +0 -1
- package/dist/cjs/routes/oauth2-refresh.js.map +0 -1
- package/dist/cjs/routes/oauth2-signin.js.map +0 -1
- package/dist/cjs/routes/webmanager.js.map +0 -1
- package/dist/cjs/rules.js.map +0 -1
- package/dist/cjs/schema/user.js.map +0 -1
- package/dist/cjs/server.js.map +0 -1
- package/dist/cjs/settings/email.js.map +0 -1
- package/dist/cjs/settings/index.js.map +0 -1
- package/dist/cjs/shared/clients.js.map +0 -1
- package/dist/cjs/shared/email.js.map +0 -1
- package/dist/cjs/shared/env.js.map +0 -1
- package/dist/cjs/shared/error.js.map +0 -1
- package/dist/cjs/shared/http.js.map +0 -1
- package/dist/cjs/shared/password.js.map +0 -1
- package/dist/cjs/shared/rootpath.js.map +0 -1
- package/dist/cjs/shared/signin.js.map +0 -1
- package/dist/cjs/shared/simple-fetch.js.map +0 -1
- package/dist/cjs/shared/tokens.js.map +0 -1
- package/dist/cjs/shared/validate.js.map +0 -1
- package/dist/cjs/start.js.map +0 -1
- package/dist/cjs/test.js.map +0 -1
- package/dist/cjs/websocket/index.js.map +0 -1
- package/dist/cjs/websocket/manager.js.map +0 -1
- package/dist/cjs/websocket/socket.io.js.map +0 -1
- package/dist/esm/auth.js.map +0 -1
- package/dist/esm/cluster.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/middleware/404.js.map +0 -1
- package/dist/esm/middleware/cache.js.map +0 -1
- package/dist/esm/middleware/connection.js.map +0 -1
- package/dist/esm/middleware/context.js.map +0 -1
- package/dist/esm/middleware/cors.js.map +0 -1
- package/dist/esm/middleware/swagger.js.map +0 -1
- package/dist/esm/middleware/user.js.map +0 -1
- package/dist/esm/oauth-providers/dropbox.js.map +0 -1
- package/dist/esm/oauth-providers/facebook.js.map +0 -1
- package/dist/esm/oauth-providers/google.js.map +0 -1
- package/dist/esm/oauth-providers/index.js.map +0 -1
- package/dist/esm/oauth-providers/instagram.js.map +0 -1
- package/dist/esm/oauth-providers/oauth-provider.js.map +0 -1
- package/dist/esm/oauth-providers/spotify.js.map +0 -1
- package/dist/esm/routes/auth-change-password.js.map +0 -1
- package/dist/esm/routes/auth-delete.js.map +0 -1
- package/dist/esm/routes/auth-forgot-password.js.map +0 -1
- package/dist/esm/routes/auth-reset-password.js.map +0 -1
- package/dist/esm/routes/auth-signin.js.map +0 -1
- package/dist/esm/routes/auth-signout.js.map +0 -1
- package/dist/esm/routes/auth-signup.js.map +0 -1
- package/dist/esm/routes/auth-state.js.map +0 -1
- package/dist/esm/routes/auth-update.js.map +0 -1
- package/dist/esm/routes/auth-verify-email.js.map +0 -1
- package/dist/esm/routes/auth.js.map +0 -1
- package/dist/esm/routes/data-exists.js.map +0 -1
- package/dist/esm/routes/data-export.js.map +0 -1
- package/dist/esm/routes/data-get.js.map +0 -1
- package/dist/esm/routes/data-import.js.map +0 -1
- package/dist/esm/routes/data-index-create.js.map +0 -1
- package/dist/esm/routes/data-index-delete.js.map +0 -1
- package/dist/esm/routes/data-index-list.js.map +0 -1
- package/dist/esm/routes/data-query.js.map +0 -1
- package/dist/esm/routes/data-reflect.js.map +0 -1
- package/dist/esm/routes/data-schema-get.js.map +0 -1
- package/dist/esm/routes/data-schema-set.js.map +0 -1
- package/dist/esm/routes/data-schema-test.js.map +0 -1
- package/dist/esm/routes/data-schemas-list.js.map +0 -1
- package/dist/esm/routes/data-set.js.map +0 -1
- package/dist/esm/routes/data-sync-changes.js.map +0 -1
- package/dist/esm/routes/data-sync-mutations.js.map +0 -1
- package/dist/esm/routes/data-transaction.js.map +0 -1
- package/dist/esm/routes/data-update.js.map +0 -1
- package/dist/esm/routes/data.js.map +0 -1
- package/dist/esm/routes/docs.js.map +0 -1
- package/dist/esm/routes/meta-info.js.map +0 -1
- package/dist/esm/routes/meta-ping.js.map +0 -1
- package/dist/esm/routes/meta-stats.js.map +0 -1
- package/dist/esm/routes/meta.js.map +0 -1
- package/dist/esm/routes/oauth2-init.js.map +0 -1
- package/dist/esm/routes/oauth2-refresh.js.map +0 -1
- package/dist/esm/routes/oauth2-signin.js.map +0 -1
- package/dist/esm/routes/webmanager.js.map +0 -1
- package/dist/esm/rules.js.map +0 -1
- package/dist/esm/schema/user.js.map +0 -1
- package/dist/esm/server.js.map +0 -1
- package/dist/esm/settings/email.js.map +0 -1
- package/dist/esm/settings/index.js.map +0 -1
- package/dist/esm/shared/clients.js.map +0 -1
- package/dist/esm/shared/email.js.map +0 -1
- package/dist/esm/shared/env.js.map +0 -1
- package/dist/esm/shared/error.js.map +0 -1
- package/dist/esm/shared/http.js.map +0 -1
- package/dist/esm/shared/password.js.map +0 -1
- package/dist/esm/shared/rootpath.js.map +0 -1
- package/dist/esm/shared/signin.js.map +0 -1
- package/dist/esm/shared/simple-fetch.js.map +0 -1
- package/dist/esm/shared/tokens.js.map +0 -1
- package/dist/esm/shared/validate.js.map +0 -1
- package/dist/esm/start.js.map +0 -1
- package/dist/esm/test.js.map +0 -1
- package/dist/esm/websocket/index.js.map +0 -1
- package/dist/esm/websocket/manager.js.map +0 -1
- package/dist/esm/websocket/socket.io.js.map +0 -1
- package/src/auth.ts +0 -87
- package/src/cluster.ts +0 -62
- package/src/index.ts +0 -4
- package/src/middleware/404.ts +0 -13
- package/src/middleware/cache.ts +0 -15
- package/src/middleware/connection.ts +0 -48
- package/src/middleware/context.ts +0 -23
- package/src/middleware/cors.ts +0 -49
- package/src/middleware/swagger.ts +0 -19
- package/src/middleware/user.ts +0 -51
- package/src/oauth-providers/dropbox.ts +0 -144
- package/src/oauth-providers/facebook.ts +0 -103
- package/src/oauth-providers/google.ts +0 -147
- package/src/oauth-providers/index.ts +0 -21
- package/src/oauth-providers/instagram.ts +0 -98
- package/src/oauth-providers/oauth-provider.ts +0 -65
- package/src/oauth-providers/spotify.ts +0 -127
- package/src/placeholder.d.ts +0 -12
- package/src/routes/auth-change-password.ts +0 -89
- package/src/routes/auth-change-password.yaml +0 -74
- package/src/routes/auth-delete.ts +0 -47
- package/src/routes/auth-delete.yaml +0 -78
- package/src/routes/auth-forgot-password.ts +0 -73
- package/src/routes/auth-forgot-password.yaml +0 -50
- package/src/routes/auth-reset-password.ts +0 -93
- package/src/routes/auth-reset-password.yaml +0 -54
- package/src/routes/auth-signin.ts +0 -55
- package/src/routes/auth-signin.yaml +0 -130
- package/src/routes/auth-signout.ts +0 -61
- package/src/routes/auth-signout.yaml +0 -46
- package/src/routes/auth-signup.ts +0 -161
- package/src/routes/auth-signup.yaml +0 -136
- package/src/routes/auth-state.ts +0 -20
- package/src/routes/auth-state.yaml +0 -29
- package/src/routes/auth-update.ts +0 -147
- package/src/routes/auth-update.yaml +0 -152
- package/src/routes/auth-verify-email.ts +0 -67
- package/src/routes/auth-verify-email.yaml +0 -53
- package/src/routes/auth.ts +0 -67
- package/src/routes/data-exists.ts +0 -31
- package/src/routes/data-exists.yaml +0 -44
- package/src/routes/data-export.ts +0 -51
- package/src/routes/data-export.yaml +0 -64
- package/src/routes/data-get.ts +0 -68
- package/src/routes/data-get.yaml +0 -54
- package/src/routes/data-import.ts +0 -56
- package/src/routes/data-import.yaml +0 -75
- package/src/routes/data-index-create.ts +0 -85
- package/src/routes/data-index-create.yaml +0 -105
- package/src/routes/data-index-delete.ts +0 -39
- package/src/routes/data-index-delete.yaml +0 -51
- package/src/routes/data-index-list.ts +0 -42
- package/src/routes/data-index-list.yaml +0 -80
- package/src/routes/data-query.ts +0 -97
- package/src/routes/data-query.yaml +0 -166
- package/src/routes/data-reflect.ts +0 -94
- package/src/routes/data-reflect.yaml +0 -124
- package/src/routes/data-schema-get.ts +0 -38
- package/src/routes/data-schema-get.yaml +0 -53
- package/src/routes/data-schema-set.ts +0 -38
- package/src/routes/data-schema-set.yaml +0 -60
- package/src/routes/data-schema-test.ts +0 -53
- package/src/routes/data-schema-test.yaml +0 -66
- package/src/routes/data-schemas-list.ts +0 -33
- package/src/routes/data-schemas-list.yaml +0 -41
- package/src/routes/data-set.ts +0 -80
- package/src/routes/data-set.yaml +0 -77
- package/src/routes/data-sync-changes.ts +0 -78
- package/src/routes/data-sync-changes.yaml +0 -67
- package/src/routes/data-sync-mutations.ts +0 -78
- package/src/routes/data-sync-mutations.yaml +0 -67
- package/src/routes/data-transaction-finish.yaml +0 -82
- package/src/routes/data-transaction-start.yaml +0 -58
- package/src/routes/data-transaction.ts +0 -159
- package/src/routes/data-update.ts +0 -81
- package/src/routes/data-update.yaml +0 -77
- package/src/routes/data.ts +0 -79
- package/src/routes/docs.ts +0 -249
- package/src/routes/meta-info.ts +0 -80
- package/src/routes/meta-info.yaml +0 -41
- package/src/routes/meta-ping.ts +0 -15
- package/src/routes/meta-ping.yaml +0 -23
- package/src/routes/meta-stats.ts +0 -31
- package/src/routes/meta-stats.yaml +0 -41
- package/src/routes/meta.ts +0 -18
- package/src/routes/oauth2-init.ts +0 -44
- package/src/routes/oauth2-init.yaml +0 -63
- package/src/routes/oauth2-refresh.ts +0 -39
- package/src/routes/oauth2-refresh.yaml +0 -65
- package/src/routes/oauth2-signin.ts +0 -282
- package/src/routes/oauth2-signin.yaml +0 -66
- package/src/routes/webmanager.ts +0 -29
- package/src/rules.ts +0 -196
- package/src/schema/user.ts +0 -99
- package/src/server.ts +0 -418
- package/src/settings/email.ts +0 -18
- package/src/settings/index.ts +0 -241
- package/src/shared/clients.ts +0 -31
- package/src/shared/email.ts +0 -33
- package/src/shared/env.ts +0 -38
- package/src/shared/error.ts +0 -37
- package/src/shared/http.ts +0 -26
- package/src/shared/password.ts +0 -41
- package/src/shared/rootpath.ts +0 -15
- package/src/shared/signin.ts +0 -143
- package/src/shared/simple-fetch.ts +0 -65
- package/src/shared/tokens.ts +0 -77
- package/src/shared/validate.ts +0 -53
- package/src/start.ts +0 -45
- package/src/test.ts +0 -10
- package/src/websocket/index.ts +0 -320
- package/src/websocket/manager.ts +0 -46
- package/src/websocket/socket.io.ts +0 -90
- package/tsconfig-cjs.json +0 -10
- package/tsconfig.json +0 -21
|
@@ -10,13 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.addRoute = void 0;
|
|
13
|
+
const admin_only_1 = require("../middleware/admin-only");
|
|
13
14
|
const error_1 = require("../shared/error");
|
|
14
15
|
const addRoute = (env) => {
|
|
15
|
-
env.app.post(`/schema/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
env.app.post(`/schema/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
// defines a schema
|
|
17
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
18
|
-
return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform schema operations');
|
|
19
|
-
}
|
|
20
18
|
try {
|
|
21
19
|
const data = req.body;
|
|
22
20
|
const { path, schema } = data;
|
|
@@ -11,14 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.addRoute = void 0;
|
|
13
13
|
const acebase_core_1 = require("acebase-core");
|
|
14
|
+
const admin_only_1 = require("../middleware/admin-only");
|
|
14
15
|
const error_1 = require("../shared/error");
|
|
15
16
|
const addRoute = (env) => {
|
|
16
|
-
env.app.post(`/schema/${env.db.name}/test`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
env.app.post(`/schema/${env.db.name}/test`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
18
|
var _a, _b;
|
|
18
19
|
// tests a schema
|
|
19
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
20
|
-
return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform schema operations');
|
|
21
|
-
}
|
|
22
20
|
try {
|
|
23
21
|
const data = req.body;
|
|
24
22
|
if (typeof ((_a = data.value) === null || _a === void 0 ? void 0 : _a.val) === 'undefined' || !['string', 'object', 'undefined'].includes(typeof ((_b = data.value) === null || _b === void 0 ? void 0 : _b.map))) {
|
|
@@ -10,13 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.addRoute = void 0;
|
|
13
|
+
const admin_only_1 = require("../middleware/admin-only");
|
|
13
14
|
const error_1 = require("../shared/error");
|
|
14
15
|
const addRoute = (env) => {
|
|
15
|
-
env.app.get(`/schema/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
env.app.get(`/schema/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
// Get all defined schemas
|
|
17
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
18
|
-
return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform schema operations');
|
|
19
|
-
}
|
|
20
18
|
try {
|
|
21
19
|
const schemas = yield env.db.schema.all();
|
|
22
20
|
res.contentType('application/json').send(schemas.map(schema => ({
|
|
@@ -22,11 +22,13 @@ class SetDataError extends Error {
|
|
|
22
22
|
exports.SetDataError = SetDataError;
|
|
23
23
|
const addRoute = (env) => {
|
|
24
24
|
env.app.put(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f
|
|
26
|
-
// Set data
|
|
25
|
+
var _a, _b, _c, _d, _e, _f;
|
|
27
26
|
const path = req.path.slice(env.db.name.length + 7);
|
|
27
|
+
const LOG_ACTION = 'data.set';
|
|
28
|
+
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 };
|
|
28
29
|
const access = env.rules.userHasAccess(req.user, path, true);
|
|
29
30
|
if (!access.allow) {
|
|
31
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_c = access.rulePath) !== null && _c !== void 0 ? _c : null, rule_error: (_e = (_d = access.details) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : null }));
|
|
30
32
|
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
31
33
|
}
|
|
32
34
|
try {
|
|
@@ -35,7 +37,7 @@ const addRoute = (env) => {
|
|
|
35
37
|
throw new SetDataError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
36
38
|
}
|
|
37
39
|
const val = acebase_core_1.Transport.deserialize(data);
|
|
38
|
-
if (path === '' && ((
|
|
40
|
+
if (path === '' && ((_f = req.user) === null || _f === void 0 ? void 0 : _f.uid) !== 'admin' && val !== null && typeof val === 'object') {
|
|
39
41
|
// Non-admin user: remove any private properties from the update object
|
|
40
42
|
Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
|
|
41
43
|
}
|
|
@@ -54,20 +56,19 @@ const addRoute = (env) => {
|
|
|
54
56
|
}
|
|
55
57
|
catch (err) {
|
|
56
58
|
if (err instanceof acebase_1.SchemaValidationError) {
|
|
57
|
-
|
|
59
|
+
env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
|
|
58
60
|
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
59
61
|
}
|
|
60
62
|
else if (err instanceof SetDataError) {
|
|
61
|
-
|
|
63
|
+
env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
|
|
62
64
|
(0, error_1.sendBadRequestError)(res, err);
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
65
67
|
env.debug.error(`failed to set "${path}":`, err);
|
|
66
|
-
|
|
68
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
67
69
|
(0, error_1.sendError)(res, err);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
|
-
;
|
|
71
72
|
}));
|
|
72
73
|
};
|
|
73
74
|
exports.addRoute = addRoute;
|
|
@@ -27,8 +27,11 @@ const addRoutes = (env) => {
|
|
|
27
27
|
env.app.post(`/transaction/${env.db.name}/start`, (req, res) => {
|
|
28
28
|
var _a, _b, _c, _d;
|
|
29
29
|
const data = req.body;
|
|
30
|
+
const LOG_ACTION = 'data.transaction.start';
|
|
31
|
+
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 };
|
|
30
32
|
const access = env.rules.userHasAccess(req.user, data.path, true);
|
|
31
33
|
if (!access.allow) {
|
|
34
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_c = access.rulePath) !== null && _c !== void 0 ? _c : null }), access.details);
|
|
32
35
|
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
33
36
|
}
|
|
34
37
|
// Start transaction
|
|
@@ -64,16 +67,19 @@ const addRoutes = (env) => {
|
|
|
64
67
|
}
|
|
65
68
|
catch (err) {
|
|
66
69
|
env.debug.error(`failed to start transaction on "${tx.path}":`, err);
|
|
67
|
-
|
|
70
|
+
env.log.error(LOG_ACTION, (_d = err.code) !== null && _d !== void 0 ? _d : 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
|
|
68
71
|
(0, error_1.sendUnexpectedError)(res, err);
|
|
69
72
|
}
|
|
70
73
|
});
|
|
71
74
|
// Finish transaction endpoint:
|
|
72
75
|
env.app.post(`/transaction/${env.db.name}/finish`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
76
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
74
77
|
const data = req.body;
|
|
78
|
+
const LOG_ACTION = 'data.transaction.finish';
|
|
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, path: data.path };
|
|
75
80
|
const tx = _transactions.get(data.id);
|
|
76
81
|
if (!tx || tx.path !== data.path) {
|
|
82
|
+
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 }));
|
|
77
83
|
res.statusCode = 410; // Gone
|
|
78
84
|
res.send(`transaction not found`);
|
|
79
85
|
return;
|
|
@@ -82,6 +88,7 @@ const addRoutes = (env) => {
|
|
|
82
88
|
_transactions.delete(tx.id);
|
|
83
89
|
const access = env.rules.userHasAccess(req.user, tx.path, true);
|
|
84
90
|
if (!access.allow) {
|
|
91
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_d = access.rulePath) !== null && _d !== void 0 ? _d : null }), access.details);
|
|
85
92
|
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
86
93
|
}
|
|
87
94
|
// Finish transaction
|
|
@@ -93,11 +100,11 @@ const addRoutes = (env) => {
|
|
|
93
100
|
// then is sent to the server as an empty object: {}
|
|
94
101
|
cancel = true;
|
|
95
102
|
}
|
|
96
|
-
else if (typeof ((
|
|
103
|
+
else if (typeof ((_e = data.value) === null || _e === void 0 ? void 0 : _e.val) === 'undefined' || !['string', 'object', 'undefined'].includes(typeof ((_f = data.value) === null || _f === void 0 ? void 0 : _f.map))) {
|
|
97
104
|
throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
98
105
|
}
|
|
99
106
|
const newValue = cancel ? undefined : acebase_core_1.Transport.deserialize(data.value);
|
|
100
|
-
if (tx.path === '' && ((
|
|
107
|
+
if (tx.path === '' && ((_g = req.user) === null || _g === void 0 ? void 0 : _g.uid) !== 'admin' && newValue !== null && typeof newValue === 'object') {
|
|
101
108
|
// Non-admin user: remove any private properties from the update object
|
|
102
109
|
Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
|
|
103
110
|
}
|
|
@@ -113,16 +120,16 @@ const addRoutes = (env) => {
|
|
|
113
120
|
catch (err) {
|
|
114
121
|
tx.finish(); // Finish without value cancels the transaction
|
|
115
122
|
if (err instanceof acebase_1.SchemaValidationError) {
|
|
116
|
-
|
|
123
|
+
env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
|
|
117
124
|
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
118
125
|
}
|
|
119
126
|
else if (err instanceof DataTransactionError) {
|
|
120
|
-
|
|
127
|
+
env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
|
|
121
128
|
(0, error_1.sendBadRequestError)(res, err);
|
|
122
129
|
}
|
|
123
130
|
else {
|
|
124
|
-
env.debug.error(`failed to
|
|
125
|
-
|
|
131
|
+
env.debug.error(`failed to finish transaction on "${tx.path}":`, err);
|
|
132
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
126
133
|
(0, error_1.sendError)(res, err);
|
|
127
134
|
}
|
|
128
135
|
}
|
|
@@ -22,11 +22,13 @@ class UpdateDataError extends Error {
|
|
|
22
22
|
exports.UpdateDataError = UpdateDataError;
|
|
23
23
|
const addRoute = (env) => {
|
|
24
24
|
env.app.post(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f
|
|
26
|
-
// update data
|
|
25
|
+
var _a, _b, _c, _d, _e, _f;
|
|
27
26
|
const path = req.path.slice(env.db.name.length + 7);
|
|
27
|
+
const LOG_ACTION = 'data.update';
|
|
28
|
+
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 };
|
|
28
29
|
const access = env.rules.userHasAccess(req.user, path, true);
|
|
29
30
|
if (!access.allow) {
|
|
31
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_c = access.rulePath) !== null && _c !== void 0 ? _c : null, rule_error: (_e = (_d = access.details) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : null }));
|
|
30
32
|
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
31
33
|
}
|
|
32
34
|
try {
|
|
@@ -35,7 +37,7 @@ const addRoute = (env) => {
|
|
|
35
37
|
throw new UpdateDataError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
36
38
|
}
|
|
37
39
|
const val = acebase_core_1.Transport.deserialize(data);
|
|
38
|
-
if (path === '' && ((
|
|
40
|
+
if (path === '' && ((_f = req.user) === null || _f === void 0 ? void 0 : _f.uid) !== 'admin' && val !== null && typeof val === 'object') {
|
|
39
41
|
// Non-admin user: remove any private properties from the update object
|
|
40
42
|
Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
|
|
41
43
|
}
|
|
@@ -54,16 +56,16 @@ const addRoute = (env) => {
|
|
|
54
56
|
}
|
|
55
57
|
catch (err) {
|
|
56
58
|
if (err instanceof acebase_1.SchemaValidationError) {
|
|
57
|
-
|
|
59
|
+
env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
|
|
58
60
|
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
59
61
|
}
|
|
60
62
|
else if (err instanceof UpdateDataError) {
|
|
61
|
-
|
|
63
|
+
env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
|
|
62
64
|
(0, error_1.sendBadRequestError)(res, err);
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
65
67
|
env.debug.error(`failed to update "${path}":`, err);
|
|
66
|
-
|
|
68
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
67
69
|
(0, error_1.sendError)(res, err);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addRoute = void 0;
|
|
13
|
+
const admin_only_1 = require("../middleware/admin-only");
|
|
14
|
+
const addRoute = (env) => {
|
|
15
|
+
env.app.get(`/logs/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
// Get database logs
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
// Create indexes if not there yet
|
|
19
|
+
const db = env.log.ref.db;
|
|
20
|
+
const createIndexes = [
|
|
21
|
+
db.indexes.create(env.log.ref.path, 'date')
|
|
22
|
+
];
|
|
23
|
+
if (req.query.filter_col === 'action') {
|
|
24
|
+
createIndexes.push(db.indexes.create(env.log.ref.path, 'action', { include: ['date'] }));
|
|
25
|
+
}
|
|
26
|
+
if (req.query.filter_col === 'code') {
|
|
27
|
+
createIndexes.push(db.indexes.create(env.log.ref.path, 'code', { include: ['date'] }));
|
|
28
|
+
}
|
|
29
|
+
yield Promise.all(createIndexes);
|
|
30
|
+
try {
|
|
31
|
+
const query = env.log.query()
|
|
32
|
+
.take(parseInt((_a = req.query.take) !== null && _a !== void 0 ? _a : '100'))
|
|
33
|
+
.skip(parseInt((_b = req.query.skip) !== null && _b !== void 0 ? _b : '0'))
|
|
34
|
+
.sort((_c = req.query.sort) !== null && _c !== void 0 ? _c : 'date', false);
|
|
35
|
+
if (req.query.filter_col) {
|
|
36
|
+
query.filter(req.query.filter_col, req.query.filter_op, req.query.filter_val);
|
|
37
|
+
}
|
|
38
|
+
const snaps = yield query.get();
|
|
39
|
+
const logs = snaps.getValues();
|
|
40
|
+
res.send(logs);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
res.statusCode = 500;
|
|
44
|
+
res.send(err.message);
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
|
+
exports.addRoute = addRoute;
|
|
49
|
+
exports.default = exports.addRoute;
|
|
50
|
+
//# sourceMappingURL=meta-logs.js.map
|
package/dist/cjs/routes/meta.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.addRoutes = void 0;
|
|
|
4
4
|
const meta_info_1 = require("./meta-info");
|
|
5
5
|
const meta_ping_1 = require("./meta-ping");
|
|
6
6
|
const meta_stats_1 = require("./meta-stats");
|
|
7
|
+
const meta_logs_1 = require("./meta-logs");
|
|
7
8
|
const addRoutes = (env) => {
|
|
8
9
|
// Add info endpoint
|
|
9
10
|
(0, meta_info_1.default)(env);
|
|
@@ -11,6 +12,8 @@ const addRoutes = (env) => {
|
|
|
11
12
|
(0, meta_ping_1.default)(env);
|
|
12
13
|
// Add database stats endpoint
|
|
13
14
|
(0, meta_stats_1.default)(env);
|
|
15
|
+
// Add logs endpoint (admin only)
|
|
16
|
+
(0, meta_logs_1.default)(env);
|
|
14
17
|
};
|
|
15
18
|
exports.addRoutes = addRoutes;
|
|
16
19
|
exports.default = exports.addRoutes;
|
|
@@ -18,8 +18,10 @@ const socketSignInSuccess = `<html><script>window.close()</script><body>Signed i
|
|
|
18
18
|
const socketSignInFailed = `<html><script>window.close()</script><body>Failed to sign in. You can <a href="javascript:window.close()">close</a> this page</body></html>`;
|
|
19
19
|
const addRoute = (env) => {
|
|
20
20
|
env.app.get(`/oauth2/${env.db.name}/signin`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
var _a, _b;
|
|
22
21
|
// This is where the user is redirected to by the provider after signin or error
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const LOG_ACTION = 'oauth2.signin';
|
|
24
|
+
const LOG_DETAILS = { ip: req.ip, provider: null };
|
|
23
25
|
try {
|
|
24
26
|
const state = (0, tokens_1.parseSignedPublicToken)(req.query.state, env.tokenSalt);
|
|
25
27
|
if (req.query.error) {
|
|
@@ -36,6 +38,7 @@ const addRoute = (env) => {
|
|
|
36
38
|
// Got authorization code
|
|
37
39
|
const authCode = req.query.code;
|
|
38
40
|
const provider = env.authProviders[state.provider];
|
|
41
|
+
LOG_DETAILS.provider = state.provider;
|
|
39
42
|
// Get access & refresh tokens
|
|
40
43
|
const tokens = yield provider.getAccessToken({ type: 'auth', auth_code: authCode, redirect_url: `${req.protocol}://${req.headers.host}/oauth2/${env.db.name}/signin` });
|
|
41
44
|
let user_details;
|
|
@@ -142,7 +145,7 @@ const addRoute = (env) => {
|
|
|
142
145
|
// Add provider details
|
|
143
146
|
yield env.authRef.child(uid).child('settings').update(getProviderSettings());
|
|
144
147
|
// Log success
|
|
145
|
-
env.
|
|
148
|
+
env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { uid }));
|
|
146
149
|
// Cache the user
|
|
147
150
|
env.authCache.set(user.uid, user);
|
|
148
151
|
// Request signin e-mail to be sent
|
|
@@ -162,13 +165,13 @@ const addRoute = (env) => {
|
|
|
162
165
|
provider: state.provider
|
|
163
166
|
};
|
|
164
167
|
(_a = env.config.email) === null || _a === void 0 ? void 0 : _a.send(request).catch(err => {
|
|
165
|
-
env.
|
|
168
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { uid, request }), err);
|
|
166
169
|
});
|
|
167
170
|
}
|
|
168
171
|
else if (snaps.length === 0) {
|
|
169
172
|
// User does not exist, create
|
|
170
173
|
if (!env.config.auth.allowUserSignup) {
|
|
171
|
-
env.
|
|
174
|
+
env.log.error(LOG_ACTION, 'user_signup_disabled', Object.assign(Object.assign({}, LOG_DETAILS), { email: user_details.email }));
|
|
172
175
|
res.statusCode = 403; // Forbidden
|
|
173
176
|
return res.send({ code: 'admin_only', message: 'Only admin is allowed to create users' });
|
|
174
177
|
}
|
|
@@ -195,7 +198,7 @@ const addRoute = (env) => {
|
|
|
195
198
|
const uid = userRef.key;
|
|
196
199
|
user.uid = uid;
|
|
197
200
|
// Log success
|
|
198
|
-
env.
|
|
201
|
+
env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { uid }));
|
|
199
202
|
// Cache the user
|
|
200
203
|
env.authCache.set(user.uid, user);
|
|
201
204
|
// Request welcome e-mail to be sent
|
|
@@ -215,7 +218,7 @@ const addRoute = (env) => {
|
|
|
215
218
|
provider: state.provider
|
|
216
219
|
};
|
|
217
220
|
(_b = env.config.email) === null || _b === void 0 ? void 0 : _b.send(request).catch(err => {
|
|
218
|
-
env.
|
|
221
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { uid, request }), err);
|
|
219
222
|
});
|
|
220
223
|
}
|
|
221
224
|
else {
|
package/dist/cjs/server.js
CHANGED
|
@@ -29,6 +29,7 @@ const webmanager_1 = require("./routes/webmanager");
|
|
|
29
29
|
const meta_1 = require("./routes/meta");
|
|
30
30
|
const swagger_1 = require("./middleware/swagger");
|
|
31
31
|
const cache_1 = require("./middleware/cache");
|
|
32
|
+
const logger_1 = require("./logger");
|
|
32
33
|
// type PrivateLocalSettings = AceBaseLocalSettings & { storage: PrivateStorageSettings };
|
|
33
34
|
class AceBaseServerNotReadyError extends Error {
|
|
34
35
|
constructor() { super('Server is not ready yet'); }
|
|
@@ -117,6 +118,7 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
|
|
|
117
118
|
const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
|
|
118
119
|
const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
|
|
119
120
|
const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
|
|
121
|
+
const logger = new logger_1.DatabaseLog(logRef);
|
|
120
122
|
// Setup rules
|
|
121
123
|
const rulesFilePath = `${this.config.path}/${this.db.name}.acebase/rules.json`;
|
|
122
124
|
const rules = new rules_1.PathBasedRules(rulesFilePath, config.auth.defaultAccessRule, { db, debug: this.debug, authEnabled: this.config.auth.enabled });
|
|
@@ -129,7 +131,7 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
|
|
|
129
131
|
debug: this.debug,
|
|
130
132
|
securityRef,
|
|
131
133
|
authRef,
|
|
132
|
-
|
|
134
|
+
log: logger,
|
|
133
135
|
tokenSalt: null,
|
|
134
136
|
clients,
|
|
135
137
|
authCache: null,
|
|
@@ -10,6 +10,8 @@ if (process.platform === 'win32' && currentDir.startsWith('/')) {
|
|
|
10
10
|
// tsc-esm-fix does not handle win32 file urls correctly, the drive letter in import.meta.url is prefixed with a slash: file:///C:/dir/file.js
|
|
11
11
|
currentDir = currentDir.slice(1);
|
|
12
12
|
}
|
|
13
|
+
// tsc-esm-fix also does not use decodeURI to remove encoded characters (such as %20 for spaces)
|
|
14
|
+
currentDir = decodeURI(currentDir);
|
|
13
15
|
exports.packageRootPath = (0, path_1.resolve)(currentDir, '../../..');
|
|
14
16
|
exports.default = exports.packageRootPath;
|
|
15
17
|
//# sourceMappingURL=rootpath.js.map
|
|
@@ -30,6 +30,9 @@ exports.SignInError = SignInError;
|
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
32
|
const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
var _a;
|
|
34
|
+
const LOG_ACTION = 'auth.signin';
|
|
35
|
+
const LOG_DETAILS = { ip: req.ip, method: credentials.method };
|
|
33
36
|
try {
|
|
34
37
|
const query = env.authRef.query();
|
|
35
38
|
let tokenDetails;
|
|
@@ -47,7 +50,7 @@ const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, func
|
|
|
47
50
|
}
|
|
48
51
|
break;
|
|
49
52
|
}
|
|
50
|
-
case '
|
|
53
|
+
case 'internal': {
|
|
51
54
|
// Method used internally: uses the access token extracted from a public access token (see tokenDetails.access_token in above 'token' case)
|
|
52
55
|
if (typeof credentials.access_token !== 'string') {
|
|
53
56
|
throw new SignInError('invalid_details', 'sign in request has invalid arguments');
|
|
@@ -122,7 +125,9 @@ const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, func
|
|
|
122
125
|
// Update db
|
|
123
126
|
yield snap.ref.update(updates);
|
|
124
127
|
// Log history item
|
|
125
|
-
|
|
128
|
+
if (credentials.method !== 'internal') {
|
|
129
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
130
|
+
}
|
|
126
131
|
// Add to cache
|
|
127
132
|
env.authCache.set(user.uid, user);
|
|
128
133
|
// Bind user to current request
|
|
@@ -131,7 +136,7 @@ const signIn = (credentials, env, req) => __awaiter(void 0, void 0, void 0, func
|
|
|
131
136
|
}
|
|
132
137
|
catch (err) {
|
|
133
138
|
// Log error
|
|
134
|
-
env.
|
|
139
|
+
env.log.error(LOG_ACTION, (_a = err.code) !== null && _a !== void 0 ? _a : 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
|
|
135
140
|
throw err;
|
|
136
141
|
}
|
|
137
142
|
});
|
package/dist/cjs/start.js
CHANGED
|
@@ -42,6 +42,9 @@ if (+getVariable('TXLOG', 0) === 1) {
|
|
|
42
42
|
maxAge: +getVariable('TXDAYS', 30)
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
if (+getVariable('AUTH', 1) === 0) {
|
|
46
|
+
options.authentication = { enabled: false };
|
|
47
|
+
}
|
|
45
48
|
const server = new server_1.AceBaseServer(dbname, options);
|
|
46
49
|
server.once("ready", () => {
|
|
47
50
|
var _a;
|
|
@@ -9,11 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.addWebsocketServer = void 0;
|
|
12
|
+
exports.addWebsocketServer = exports.SocketRequestError = void 0;
|
|
13
13
|
const acebase_core_1 = require("acebase-core");
|
|
14
14
|
const clients_1 = require("../shared/clients");
|
|
15
15
|
const tokens_1 = require("../shared/tokens");
|
|
16
16
|
const socket_io_1 = require("./socket.io");
|
|
17
|
+
class SocketRequestError extends Error {
|
|
18
|
+
constructor(code, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.SocketRequestError = SocketRequestError;
|
|
17
24
|
const addWebsocketServer = (env) => {
|
|
18
25
|
// TODO: Allow using uWebSockets.js server instead of Socket.IO
|
|
19
26
|
const serverManager = (0, socket_io_1.createServer)(env);
|
|
@@ -106,7 +113,7 @@ const addWebsocketServer = (env) => {
|
|
|
106
113
|
serverManager.send(event.socket, 'oauth2-signin', { error: err.message });
|
|
107
114
|
}
|
|
108
115
|
}));
|
|
109
|
-
const
|
|
116
|
+
const acknowledgeRequest = (socket, requestId) => {
|
|
110
117
|
// Send acknowledgement
|
|
111
118
|
serverManager.send(socket, 'result', {
|
|
112
119
|
success: true,
|
|
@@ -122,6 +129,7 @@ const addWebsocketServer = (env) => {
|
|
|
122
129
|
});
|
|
123
130
|
};
|
|
124
131
|
serverManager.on('subscribe', event => {
|
|
132
|
+
var _a, _b;
|
|
125
133
|
// Client wants to subscribe to events on a node
|
|
126
134
|
const client = getClientBySocketId(event.socket_id, 'subscribe');
|
|
127
135
|
if (!client) {
|
|
@@ -131,12 +139,12 @@ const addWebsocketServer = (env) => {
|
|
|
131
139
|
const subscriptionPath = event.data.path;
|
|
132
140
|
const isSubscribed = () => subscriptionPath in client.subscriptions && client.subscriptions[subscriptionPath].some(s => s.event === event.data.event);
|
|
133
141
|
if (isSubscribed()) {
|
|
134
|
-
return
|
|
142
|
+
return acknowledgeRequest(event.socket, event.data.req_id);
|
|
135
143
|
}
|
|
136
144
|
// Get client
|
|
137
145
|
// const client = clients.get(socket.id);
|
|
138
146
|
if (!env.rules.userHasAccess(client.user, subscriptionPath, false)) {
|
|
139
|
-
env.
|
|
147
|
+
env.log.error('event.subscribe', 'access_denied', { uid: (_b = (_a = client.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : 'anonymous', path: subscriptionPath });
|
|
140
148
|
return failRequest(event.socket, event.data.req_id, 'access_denied');
|
|
141
149
|
}
|
|
142
150
|
const callback = (err, path, currentValue, previousValue, context) => {
|
|
@@ -177,7 +185,7 @@ const addWebsocketServer = (env) => {
|
|
|
177
185
|
let subscr = { path: subscriptionPath, event: event.data.event, callback };
|
|
178
186
|
pathSubs.push(subscr);
|
|
179
187
|
env.db.api.subscribe(subscriptionPath, event.data.event, callback);
|
|
180
|
-
|
|
188
|
+
acknowledgeRequest(event.socket, event.data.req_id);
|
|
181
189
|
});
|
|
182
190
|
serverManager.on('unsubscribe', event => {
|
|
183
191
|
// Client unsubscribes from events on a node
|
|
@@ -190,7 +198,7 @@ const addWebsocketServer = (env) => {
|
|
|
190
198
|
let pathSubs = client.subscriptions[event.data.path];
|
|
191
199
|
if (!pathSubs) {
|
|
192
200
|
// We have no knowledge of any active subscriptions on this path
|
|
193
|
-
return
|
|
201
|
+
return acknowledgeRequest(event.socket, event.data.req_id);
|
|
194
202
|
}
|
|
195
203
|
let remove = pathSubs;
|
|
196
204
|
if (event.data.event) {
|
|
@@ -207,7 +215,7 @@ const addWebsocketServer = (env) => {
|
|
|
207
215
|
// No subscriptions left on this path, remove the path entry
|
|
208
216
|
delete client.subscriptions[event.data.path];
|
|
209
217
|
}
|
|
210
|
-
return
|
|
218
|
+
return acknowledgeRequest(event.socket, event.data.req_id);
|
|
211
219
|
});
|
|
212
220
|
serverManager.on('query-unsubscribe', event => {
|
|
213
221
|
// Client unsubscribing from realtime query events
|
|
@@ -218,15 +226,18 @@ const addWebsocketServer = (env) => {
|
|
|
218
226
|
env.debug.verbose(`Client ${event.socket_id} is unsubscribing from realtime query "${event.data.query_id}"`);
|
|
219
227
|
// const client = clients.get(socket.id);
|
|
220
228
|
delete client.realtimeQueries[event.data.query_id];
|
|
221
|
-
|
|
229
|
+
acknowledgeRequest(event.socket, event.data.req_id);
|
|
222
230
|
});
|
|
223
231
|
const TRANSACTION_TIMEOUT_MS = 10000; // 10s to finish a started transaction
|
|
224
232
|
serverManager.on('transaction-start', event => {
|
|
233
|
+
var _a, _b, _c;
|
|
225
234
|
// Start transaction
|
|
226
235
|
const client = getClientBySocketId(event.socket_id, 'transaction-start');
|
|
227
|
-
if (!client) {
|
|
236
|
+
if (!client || !event.data) {
|
|
228
237
|
return;
|
|
229
238
|
}
|
|
239
|
+
const LOG_ACTION = 'socket.transaction.start';
|
|
240
|
+
const LOG_DETAILS = { ip: event.socket.conn.remoteAddress, uid: (_b = (_a = client.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path: event.data.path };
|
|
230
241
|
env.debug.verbose(`Client ${event.socket_id} is sending transaction start request on path "${event.data.path}"`);
|
|
231
242
|
const data = event.data;
|
|
232
243
|
const tx = {
|
|
@@ -238,11 +249,14 @@ const addWebsocketServer = (env) => {
|
|
|
238
249
|
timeout: setTimeout(() => {
|
|
239
250
|
delete client.transactions[tx.id];
|
|
240
251
|
tx.finish(); // Finish without value cancels the transaction
|
|
252
|
+
env.log.error(LOG_ACTION, 'timeout', LOG_DETAILS);
|
|
241
253
|
serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: 'timeout' });
|
|
242
254
|
}, TRANSACTION_TIMEOUT_MS)
|
|
243
255
|
};
|
|
244
|
-
|
|
256
|
+
const access = env.rules.userHasAccess(client.user, data.path, true);
|
|
257
|
+
if (!access.allow) {
|
|
245
258
|
// throw new AccessDeniedError(`access_denied`);
|
|
259
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_c = access.rulePath) !== null && _c !== void 0 ? _c : null }), access.details);
|
|
246
260
|
return serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: 'access_denied' });
|
|
247
261
|
}
|
|
248
262
|
// Bind to client
|
|
@@ -264,34 +278,39 @@ const addWebsocketServer = (env) => {
|
|
|
264
278
|
}, { context: tx.context });
|
|
265
279
|
});
|
|
266
280
|
serverManager.on('transaction-finish', (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
+
var _a, _b, _c, _d, _e;
|
|
267
282
|
// Finish transaction
|
|
268
283
|
const client = getClientBySocketId(event.socket_id, 'transaction-finish');
|
|
269
|
-
if (!client) {
|
|
284
|
+
if (!client || !event.data) {
|
|
270
285
|
return;
|
|
271
286
|
}
|
|
287
|
+
const LOG_ACTION = 'socket.transaction.finish';
|
|
288
|
+
const LOG_DETAILS = { ip: event.socket.conn.remoteAddress, uid: (_b = (_a = client.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path: event.data.path };
|
|
272
289
|
const data = event.data;
|
|
273
290
|
const tx = client.transactions[data.id];
|
|
274
291
|
try {
|
|
275
292
|
if (!tx || data.path !== tx.path) {
|
|
276
|
-
|
|
293
|
+
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 }));
|
|
294
|
+
throw new SocketRequestError('transaction_not_found', 'Transaction not found');
|
|
277
295
|
}
|
|
278
296
|
clearTimeout(tx.timeout);
|
|
279
297
|
delete client.transactions[data.id];
|
|
280
|
-
|
|
281
|
-
|
|
298
|
+
const access = env.rules.userHasAccess(client.user, data.path, true);
|
|
299
|
+
if (!access.allow) {
|
|
300
|
+
env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_d = access.rulePath) !== null && _d !== void 0 ? _d : null }), access.details);
|
|
301
|
+
throw new SocketRequestError('access_denied', 'Access denied');
|
|
282
302
|
}
|
|
283
303
|
const newValue = 'val' in data.value ? acebase_core_1.Transport.deserialize(data.value) : undefined;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
serverManager.send(event.socket, 'tx_completed', { id: tx.id, context: { cursor } });
|
|
288
|
-
}
|
|
289
|
-
catch (err) {
|
|
290
|
-
serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: err.message });
|
|
291
|
-
}
|
|
304
|
+
const { cursor } = yield tx.finish(newValue);
|
|
305
|
+
env.debug.verbose(`Transaction ${tx.id} finished`);
|
|
306
|
+
serverManager.send(event.socket, 'tx_completed', { id: tx.id, context: { cursor } });
|
|
292
307
|
}
|
|
293
308
|
catch (err) {
|
|
294
|
-
|
|
309
|
+
if (!(err instanceof SocketRequestError)) {
|
|
310
|
+
// Other errors have been logged already
|
|
311
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
312
|
+
}
|
|
313
|
+
serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: (_e = err.code) !== null && _e !== void 0 ? _e : err.message, data });
|
|
295
314
|
tx.finish(); // Finish with undefined, canceling the transaction
|
|
296
315
|
}
|
|
297
316
|
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../types';
|