acebase-server 1.10.1 → 1.13.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/.vscode/launch.json +24 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +16 -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/oauth-providers/dropbox.js +3 -2
- package/dist/cjs/oauth-providers/facebook.js +3 -2
- package/dist/cjs/oauth-providers/google.js +3 -2
- package/dist/cjs/oauth-providers/instagram.js +3 -2
- package/dist/cjs/oauth-providers/oauth-provider.js +23 -0
- package/dist/cjs/oauth-providers/spotify.js +3 -2
- 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 +11 -7
- package/dist/cjs/routes/data-transaction.js +30 -10
- package/dist/cjs/routes/data-update.js +11 -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 +15 -11
- package/dist/cjs/rules.js +5 -5
- package/dist/cjs/server.js +6 -4
- package/dist/cjs/settings/index.js +6 -7
- 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 +43 -24
- package/dist/cjs/websocket/socket.io.js +8 -11
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -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/oauth-providers/dropbox.js +3 -2
- package/dist/esm/oauth-providers/facebook.js +3 -2
- package/dist/esm/oauth-providers/google.js +3 -2
- package/dist/esm/oauth-providers/instagram.js +3 -2
- package/dist/esm/oauth-providers/oauth-provider.js +21 -1
- package/dist/esm/oauth-providers/spotify.js +3 -2
- 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 +9 -5
- package/dist/esm/routes/data-transaction.js +28 -8
- package/dist/esm/routes/data-update.js +9 -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 +14 -10
- package/dist/esm/rules.js +5 -5
- package/dist/esm/server.js +6 -4
- package/dist/esm/settings/index.js +5 -6
- 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 +38 -23
- package/dist/esm/websocket/socket.io.js +9 -11
- package/dist/types/index.d.ts +2 -0
- package/dist/types/logger.d.ts +35 -0
- package/dist/types/middleware/admin-only.d.ts +19 -0
- package/dist/types/oauth-providers/dropbox.d.ts +3 -14
- package/dist/types/oauth-providers/facebook.d.ts +3 -7
- package/dist/types/oauth-providers/google.d.ts +3 -7
- package/dist/types/oauth-providers/index.d.ts +2 -10
- package/dist/types/oauth-providers/instagram.d.ts +3 -7
- package/dist/types/oauth-providers/oauth-provider.d.ts +25 -21
- package/dist/types/oauth-providers/spotify.d.ts +3 -7
- package/dist/types/routes/data-query.d.ts +1 -1
- package/dist/types/routes/meta-logs.d.ts +20 -0
- package/dist/types/rules.d.ts +4 -4
- package/dist/types/server.d.ts +9 -7
- package/dist/types/settings/email.d.ts +1 -1
- package/dist/types/settings/index.d.ts +5 -6
- package/dist/types/shared/clients.d.ts +3 -1
- package/dist/types/shared/env.d.ts +6 -4
- package/dist/types/shared/http.d.ts +2 -0
- package/dist/types/shared/signin.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +4 -0
- package/dist/types/websocket/manager.d.ts +1 -1
- package/package.json +8 -8
- package/webmanager/acebase-client-browser.min.js +16 -0
- package/webmanager/index.html +2 -2
- package/webmanager/index.js +3 -6
- 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 -2
- 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 -143
- package/src/oauth-providers/facebook.ts +0 -102
- package/src/oauth-providers/google.ts +0 -146
- package/src/oauth-providers/index.ts +0 -20
- package/src/oauth-providers/instagram.ts +0 -97
- package/src/oauth-providers/oauth-provider.ts +0 -55
- package/src/oauth-providers/spotify.ts +0 -126
- 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 -76
- package/src/routes/data-set.yaml +0 -71
- 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 -76
- package/src/routes/data-transaction-start.yaml +0 -58
- package/src/routes/data-transaction.ts +0 -144
- package/src/routes/data-update.ts +0 -77
- package/src/routes/data-update.yaml +0 -71
- 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 -281
- 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 -416
- package/src/settings/email.ts +0 -18
- package/src/settings/index.ts +0 -240
- 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 -24
- 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 -91
- package/tsconfig-cjs.json +0 -10
- package/tsconfig.json +0 -21
|
@@ -25,15 +25,19 @@ exports.VerifyEmailError = VerifyEmailError;
|
|
|
25
25
|
* @returns returns the verification function
|
|
26
26
|
*/
|
|
27
27
|
const addRoute = (env) => {
|
|
28
|
+
const LOG_ACTION = 'auth.verify_email';
|
|
28
29
|
const verifyEmailAddress = (clientIp, code) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
const LOG_DETAILS = { ip: clientIp, uid: null };
|
|
29
31
|
try {
|
|
30
32
|
var verification = (0, tokens_1.parseSignedPublicToken)(code, env.tokenSalt);
|
|
31
33
|
}
|
|
32
34
|
catch (err) {
|
|
33
35
|
throw new VerifyEmailError('invalid_code', err.message);
|
|
34
36
|
}
|
|
37
|
+
LOG_DETAILS.uid = verification.uid;
|
|
35
38
|
const snap = yield env.authRef.child(verification.uid).get();
|
|
36
39
|
if (!snap.exists()) {
|
|
40
|
+
env.log.error(LOG_ACTION, 'unknown_user', LOG_DETAILS);
|
|
37
41
|
throw new VerifyEmailError('unknown_user', 'Unknown user');
|
|
38
42
|
}
|
|
39
43
|
const user = snap.val();
|
|
@@ -41,21 +45,20 @@ const addRoute = (env) => {
|
|
|
41
45
|
// No need to do further checks, code was signed by us so we can trust the contents
|
|
42
46
|
// Mark account as verified
|
|
43
47
|
yield snap.ref.update({ email_verified: true });
|
|
44
|
-
env.
|
|
48
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
45
49
|
});
|
|
46
50
|
env.app.post(`/auth/${env.db.name}/verify_email`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
var _a, _b;
|
|
48
51
|
const details = req.body;
|
|
49
52
|
try {
|
|
50
53
|
yield verifyEmailAddress(req.ip, details.code);
|
|
51
54
|
res.send('OK');
|
|
52
55
|
}
|
|
53
56
|
catch (err) {
|
|
54
|
-
env.logRef.push({ action: 'verify_email', success: false, code: err.code, message: err.message, ip: req.ip, date: new Date(), uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null });
|
|
55
57
|
if (err.code) {
|
|
56
58
|
(0, error_1.sendBadRequestError)(res, err);
|
|
57
59
|
}
|
|
58
60
|
else {
|
|
61
|
+
env.log.error(LOG_ACTION, 'unexpected', { ip: req.ip, message: err.message, verificaion_code: details.code });
|
|
59
62
|
(0, error_1.sendUnexpectedError)(res, err);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
@@ -10,12 +10,10 @@ 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
16
|
const handleRequest = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
17
|
-
return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform index operations');
|
|
18
|
-
}
|
|
19
17
|
try {
|
|
20
18
|
const data = req.body;
|
|
21
19
|
yield env.db.indexes.create(data.path, data.key, data.options);
|
|
@@ -26,7 +24,7 @@ const addRoute = (env) => {
|
|
|
26
24
|
(0, error_1.sendError)(res, err);
|
|
27
25
|
}
|
|
28
26
|
});
|
|
29
|
-
env.app.post(`/index/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
env.app.post(`/index/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
28
|
var _a;
|
|
31
29
|
// Legacy endpoint that was designed to handle multiple actions
|
|
32
30
|
// The only action ever implemented was 'create', so we'll handle that here
|
|
@@ -35,7 +33,7 @@ const addRoute = (env) => {
|
|
|
35
33
|
}
|
|
36
34
|
handleRequest(req, res);
|
|
37
35
|
}));
|
|
38
|
-
env.app.post(`/index/${env.db.name}/create`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
env.app.post(`/index/${env.db.name}/create`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
37
|
// New dedicated create endpoint
|
|
40
38
|
handleRequest(req, res);
|
|
41
39
|
}));
|
|
@@ -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(`/index/${env.db.name}/delete`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
env.app.post(`/index/${env.db.name}/delete`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
// Delete an index
|
|
17
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
18
|
-
return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform index operations');
|
|
19
|
-
}
|
|
20
18
|
try {
|
|
21
19
|
const data = req.body;
|
|
22
20
|
if (!data.fileName) {
|
|
@@ -10,14 +10,12 @@ 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
|
;
|
|
15
16
|
const addRoute = (env) => {
|
|
16
|
-
env.app.get(`/index/${env.db.name}`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
env.app.get(`/index/${env.db.name}`, (0, admin_only_1.default)(env), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
18
|
// Get all indexes
|
|
18
|
-
if (!req.user || req.user.username !== 'admin') {
|
|
19
|
-
return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'only admin can perform index operations');
|
|
20
|
-
}
|
|
21
19
|
try {
|
|
22
20
|
const indexes = yield env.db.indexes.get();
|
|
23
21
|
res.contentType('application/json').send(indexes.map(index => {
|
|
@@ -14,17 +14,15 @@ const acebase_core_1 = require("acebase-core");
|
|
|
14
14
|
const error_1 = require("../shared/error");
|
|
15
15
|
const addRoute = (env) => {
|
|
16
16
|
env.app.get(`/reflect/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
var _a;
|
|
17
18
|
// Reflection API
|
|
18
|
-
// if (!req.user || req.user.username !== 'admin') {
|
|
19
|
-
// return sendUnauthorizedError(res, 'admin_only', 'only admin can use reflection api');
|
|
20
|
-
// }
|
|
21
19
|
const path = req.path.slice(env.db.name.length + 10);
|
|
22
20
|
const access = env.rules.userHasAccess(req.user, path, false);
|
|
23
21
|
if (!access.allow) {
|
|
24
22
|
return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
|
|
25
23
|
}
|
|
26
24
|
const impersonatedAccess = {
|
|
27
|
-
uid: (
|
|
25
|
+
uid: ((_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== 'admin' ? null : req.query.impersonate,
|
|
28
26
|
read: {
|
|
29
27
|
allow: false,
|
|
30
28
|
error: null
|
|
@@ -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 defined schema for a specifc path
|
|
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 path = req.path.slice(env.db.name.length + 9);
|
|
22
20
|
const schema = yield env.db.schema.get(path);
|
|
@@ -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
|
}
|
|
@@ -47,24 +49,26 @@ const addRoute = (env) => {
|
|
|
47
49
|
yield env.db.ref(path)
|
|
48
50
|
.context(req.context)
|
|
49
51
|
.set(val);
|
|
52
|
+
// NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
|
|
53
|
+
const returnContext = { acebase_cursor: req.context.acebase_cursor };
|
|
54
|
+
res.setHeader('AceBase-Context', JSON.stringify(returnContext));
|
|
50
55
|
res.send({ success: true });
|
|
51
56
|
}
|
|
52
57
|
catch (err) {
|
|
53
58
|
if (err instanceof acebase_1.SchemaValidationError) {
|
|
54
|
-
|
|
59
|
+
env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
|
|
55
60
|
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
56
61
|
}
|
|
57
62
|
else if (err instanceof SetDataError) {
|
|
58
|
-
|
|
63
|
+
env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
|
|
59
64
|
(0, error_1.sendBadRequestError)(res, err);
|
|
60
65
|
}
|
|
61
66
|
else {
|
|
62
67
|
env.debug.error(`failed to set "${path}":`, err);
|
|
63
|
-
|
|
68
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
64
69
|
(0, error_1.sendError)(res, err);
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
|
-
;
|
|
68
72
|
}));
|
|
69
73
|
};
|
|
70
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,34 +88,48 @@ 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
|
|
88
95
|
try {
|
|
89
|
-
|
|
96
|
+
let cancel = false;
|
|
97
|
+
if (typeof data.value === 'object' && (data.value === null || Object.keys(data.value).length === 0)) {
|
|
98
|
+
// Returning undefined from a transaction callback should cancel the transaction
|
|
99
|
+
// acebase-client (Transport.serialize) serializes value undefined as { val: undefined, map: undefined }, which
|
|
100
|
+
// then is sent to the server as an empty object: {}
|
|
101
|
+
cancel = true;
|
|
102
|
+
}
|
|
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))) {
|
|
90
104
|
throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
91
105
|
}
|
|
92
|
-
const newValue = acebase_core_1.Transport.deserialize(data.value);
|
|
93
|
-
if (tx.path === '' && ((
|
|
106
|
+
const newValue = cancel ? undefined : acebase_core_1.Transport.deserialize(data.value);
|
|
107
|
+
if (tx.path === '' && ((_g = req.user) === null || _g === void 0 ? void 0 : _g.uid) !== 'admin' && newValue !== null && typeof newValue === 'object') {
|
|
94
108
|
// Non-admin user: remove any private properties from the update object
|
|
95
109
|
Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
|
|
96
110
|
}
|
|
97
|
-
yield tx.finish(newValue);
|
|
111
|
+
const result = yield tx.finish(newValue);
|
|
112
|
+
// NEW: capture cursor and return it in the response context header
|
|
113
|
+
if (!tx.context) {
|
|
114
|
+
tx.context = {};
|
|
115
|
+
}
|
|
116
|
+
tx.context.acebase_cursor = result.cursor;
|
|
117
|
+
res.setHeader('AceBase-Context', JSON.stringify(tx.context));
|
|
98
118
|
res.send('done');
|
|
99
119
|
}
|
|
100
120
|
catch (err) {
|
|
101
121
|
tx.finish(); // Finish without value cancels the transaction
|
|
102
122
|
if (err instanceof acebase_1.SchemaValidationError) {
|
|
103
|
-
|
|
123
|
+
env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
|
|
104
124
|
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
105
125
|
}
|
|
106
126
|
else if (err instanceof DataTransactionError) {
|
|
107
|
-
|
|
127
|
+
env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
|
|
108
128
|
(0, error_1.sendBadRequestError)(res, err);
|
|
109
129
|
}
|
|
110
130
|
else {
|
|
111
|
-
env.debug.error(`failed to
|
|
112
|
-
|
|
131
|
+
env.debug.error(`failed to finish transaction on "${tx.path}":`, err);
|
|
132
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
113
133
|
(0, error_1.sendError)(res, err);
|
|
114
134
|
}
|
|
115
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
|
}
|
|
@@ -47,20 +49,23 @@ const addRoute = (env) => {
|
|
|
47
49
|
yield env.db.ref(path)
|
|
48
50
|
.context(req.context)
|
|
49
51
|
.update(val);
|
|
52
|
+
// NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
|
|
53
|
+
const returnContext = { acebase_cursor: req.context.acebase_cursor };
|
|
54
|
+
res.setHeader('AceBase-Context', JSON.stringify(returnContext));
|
|
50
55
|
res.send({ success: true });
|
|
51
56
|
}
|
|
52
57
|
catch (err) {
|
|
53
58
|
if (err instanceof acebase_1.SchemaValidationError) {
|
|
54
|
-
|
|
59
|
+
env.log.error(LOG_ACTION, 'schema_validation_failed', Object.assign(Object.assign({}, LOG_DETAILS), { reason: err.reason }));
|
|
55
60
|
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
56
61
|
}
|
|
57
62
|
else if (err instanceof UpdateDataError) {
|
|
58
|
-
|
|
63
|
+
env.log.error(LOG_ACTION, err.code, Object.assign(Object.assign({}, LOG_DETAILS), { message: err.message }));
|
|
59
64
|
(0, error_1.sendBadRequestError)(res, err);
|
|
60
65
|
}
|
|
61
66
|
else {
|
|
62
67
|
env.debug.error(`failed to update "${path}":`, err);
|
|
63
|
-
|
|
68
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
64
69
|
(0, error_1.sendError)(res, err);
|
|
65
70
|
}
|
|
66
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;
|
|
@@ -55,12 +58,13 @@ const addRoute = (env) => {
|
|
|
55
58
|
if (contentType === 'image/png') { //state.provider === 'google' &&
|
|
56
59
|
// Don't accept image/png, because it's probably a placeholder image. Google does this by creating a png with people's initials
|
|
57
60
|
user_details.picture = [];
|
|
58
|
-
return;
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
else {
|
|
63
|
+
const image = yield response.arrayBuffer();
|
|
64
|
+
let buff = Buffer.from(image);
|
|
65
|
+
best.url = `data:${contentType};base64,${buff.toString('base64')}`;
|
|
66
|
+
user_details.picture = [best]; // Only keep the best one
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
catch (err) {
|
|
66
70
|
env.debug.warn(`Could not fetch profile picture from "${best.url}": `, err);
|
|
@@ -141,7 +145,7 @@ const addRoute = (env) => {
|
|
|
141
145
|
// Add provider details
|
|
142
146
|
yield env.authRef.child(uid).child('settings').update(getProviderSettings());
|
|
143
147
|
// Log success
|
|
144
|
-
env.
|
|
148
|
+
env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { uid }));
|
|
145
149
|
// Cache the user
|
|
146
150
|
env.authCache.set(user.uid, user);
|
|
147
151
|
// Request signin e-mail to be sent
|
|
@@ -161,13 +165,13 @@ const addRoute = (env) => {
|
|
|
161
165
|
provider: state.provider
|
|
162
166
|
};
|
|
163
167
|
(_a = env.config.email) === null || _a === void 0 ? void 0 : _a.send(request).catch(err => {
|
|
164
|
-
env.
|
|
168
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { uid, request }), err);
|
|
165
169
|
});
|
|
166
170
|
}
|
|
167
171
|
else if (snaps.length === 0) {
|
|
168
172
|
// User does not exist, create
|
|
169
173
|
if (!env.config.auth.allowUserSignup) {
|
|
170
|
-
env.
|
|
174
|
+
env.log.error(LOG_ACTION, 'user_signup_disabled', Object.assign(Object.assign({}, LOG_DETAILS), { email: user_details.email }));
|
|
171
175
|
res.statusCode = 403; // Forbidden
|
|
172
176
|
return res.send({ code: 'admin_only', message: 'Only admin is allowed to create users' });
|
|
173
177
|
}
|
|
@@ -194,7 +198,7 @@ const addRoute = (env) => {
|
|
|
194
198
|
const uid = userRef.key;
|
|
195
199
|
user.uid = uid;
|
|
196
200
|
// Log success
|
|
197
|
-
env.
|
|
201
|
+
env.log.event(LOG_ACTION, Object.assign(Object.assign({}, LOG_DETAILS), { uid }));
|
|
198
202
|
// Cache the user
|
|
199
203
|
env.authCache.set(user.uid, user);
|
|
200
204
|
// Request welcome e-mail to be sent
|
|
@@ -214,7 +218,7 @@ const addRoute = (env) => {
|
|
|
214
218
|
provider: state.provider
|
|
215
219
|
};
|
|
216
220
|
(_b = env.config.email) === null || _b === void 0 ? void 0 : _b.send(request).catch(err => {
|
|
217
|
-
env.
|
|
221
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { uid, request }), err);
|
|
218
222
|
});
|
|
219
223
|
}
|
|
220
224
|
else {
|
package/dist/cjs/rules.js
CHANGED
|
@@ -64,11 +64,11 @@ class PathBasedRules {
|
|
|
64
64
|
rule.getText = () => {
|
|
65
65
|
return text;
|
|
66
66
|
};
|
|
67
|
-
parent[key] = rule;
|
|
67
|
+
return parent[key] = rule;
|
|
68
68
|
}
|
|
69
69
|
else if (key === '.schema') {
|
|
70
70
|
// Add schema
|
|
71
|
-
env.db.schema.set(path, rule)
|
|
71
|
+
return env.db.schema.set(path, rule)
|
|
72
72
|
.catch(err => {
|
|
73
73
|
env.debug.error(`Error parsing ${path}/.schema: ${err.message}`);
|
|
74
74
|
});
|
|
@@ -83,15 +83,15 @@ class PathBasedRules {
|
|
|
83
83
|
};
|
|
84
84
|
processRules('', accessRules.rules, []);
|
|
85
85
|
// Watch file for changes
|
|
86
|
-
const
|
|
86
|
+
const watchFileListener = () => {
|
|
87
87
|
// Reload access rules
|
|
88
88
|
const accessRules = readRules();
|
|
89
89
|
processRules('', accessRules, []);
|
|
90
90
|
this.accessRules = accessRules;
|
|
91
91
|
};
|
|
92
|
-
fs.watchFile(rulesFilePath,
|
|
92
|
+
fs.watchFile(rulesFilePath, watchFileListener);
|
|
93
93
|
this.stop = () => {
|
|
94
|
-
fs.unwatchFile(rulesFilePath,
|
|
94
|
+
fs.unwatchFile(rulesFilePath, watchFileListener);
|
|
95
95
|
};
|
|
96
96
|
process.on('SIGINT', this.stop);
|
|
97
97
|
this.authEnabled = env.authEnabled;
|