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
|
@@ -7,6 +7,8 @@ const socketSignInFailed = `<html><script>window.close()</script><body>Failed to
|
|
|
7
7
|
export const addRoute = (env) => {
|
|
8
8
|
env.app.get(`/oauth2/${env.db.name}/signin`, async (req, res) => {
|
|
9
9
|
// This is where the user is redirected to by the provider after signin or error
|
|
10
|
+
const LOG_ACTION = 'oauth2.signin';
|
|
11
|
+
const LOG_DETAILS = { ip: req.ip, provider: null };
|
|
10
12
|
try {
|
|
11
13
|
const state = parseSignedPublicToken(req.query.state, env.tokenSalt);
|
|
12
14
|
if (req.query.error) {
|
|
@@ -23,6 +25,7 @@ export const addRoute = (env) => {
|
|
|
23
25
|
// Got authorization code
|
|
24
26
|
const authCode = req.query.code;
|
|
25
27
|
const provider = env.authProviders[state.provider];
|
|
28
|
+
LOG_DETAILS.provider = state.provider;
|
|
26
29
|
// Get access & refresh tokens
|
|
27
30
|
const tokens = await provider.getAccessToken({ type: 'auth', auth_code: authCode, redirect_url: `${req.protocol}://${req.headers.host}/oauth2/${env.db.name}/signin` });
|
|
28
31
|
let user_details;
|
|
@@ -42,12 +45,13 @@ export const addRoute = (env) => {
|
|
|
42
45
|
if (contentType === 'image/png') { //state.provider === 'google' &&
|
|
43
46
|
// Don't accept image/png, because it's probably a placeholder image. Google does this by creating a png with people's initials
|
|
44
47
|
user_details.picture = [];
|
|
45
|
-
return;
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
else {
|
|
50
|
+
const image = await response.arrayBuffer();
|
|
51
|
+
let buff = Buffer.from(image);
|
|
52
|
+
best.url = `data:${contentType};base64,${buff.toString('base64')}`;
|
|
53
|
+
user_details.picture = [best]; // Only keep the best one
|
|
54
|
+
}
|
|
51
55
|
}
|
|
52
56
|
catch (err) {
|
|
53
57
|
env.debug.warn(`Could not fetch profile picture from "${best.url}": `, err);
|
|
@@ -128,7 +132,7 @@ export const addRoute = (env) => {
|
|
|
128
132
|
// Add provider details
|
|
129
133
|
await env.authRef.child(uid).child('settings').update(getProviderSettings());
|
|
130
134
|
// Log success
|
|
131
|
-
env.
|
|
135
|
+
env.log.event(LOG_ACTION, { ...LOG_DETAILS, uid });
|
|
132
136
|
// Cache the user
|
|
133
137
|
env.authCache.set(user.uid, user);
|
|
134
138
|
// Request signin e-mail to be sent
|
|
@@ -148,13 +152,13 @@ export const addRoute = (env) => {
|
|
|
148
152
|
provider: state.provider
|
|
149
153
|
};
|
|
150
154
|
env.config.email?.send(request).catch(err => {
|
|
151
|
-
env.
|
|
155
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', { ...LOG_DETAILS, uid, request }, err);
|
|
152
156
|
});
|
|
153
157
|
}
|
|
154
158
|
else if (snaps.length === 0) {
|
|
155
159
|
// User does not exist, create
|
|
156
160
|
if (!env.config.auth.allowUserSignup) {
|
|
157
|
-
env.
|
|
161
|
+
env.log.error(LOG_ACTION, 'user_signup_disabled', { ...LOG_DETAILS, email: user_details.email });
|
|
158
162
|
res.statusCode = 403; // Forbidden
|
|
159
163
|
return res.send({ code: 'admin_only', message: 'Only admin is allowed to create users' });
|
|
160
164
|
}
|
|
@@ -181,7 +185,7 @@ export const addRoute = (env) => {
|
|
|
181
185
|
const uid = userRef.key;
|
|
182
186
|
user.uid = uid;
|
|
183
187
|
// Log success
|
|
184
|
-
env.
|
|
188
|
+
env.log.event(LOG_ACTION, { ...LOG_DETAILS, uid });
|
|
185
189
|
// Cache the user
|
|
186
190
|
env.authCache.set(user.uid, user);
|
|
187
191
|
// Request welcome e-mail to be sent
|
|
@@ -201,7 +205,7 @@ export const addRoute = (env) => {
|
|
|
201
205
|
provider: state.provider
|
|
202
206
|
};
|
|
203
207
|
env.config.email?.send(request).catch(err => {
|
|
204
|
-
env.
|
|
208
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', { ...LOG_DETAILS, uid, request }, err);
|
|
205
209
|
});
|
|
206
210
|
}
|
|
207
211
|
else {
|
package/dist/esm/rules.js
CHANGED
|
@@ -61,11 +61,11 @@ export class PathBasedRules {
|
|
|
61
61
|
rule.getText = () => {
|
|
62
62
|
return text;
|
|
63
63
|
};
|
|
64
|
-
parent[key] = rule;
|
|
64
|
+
return parent[key] = rule;
|
|
65
65
|
}
|
|
66
66
|
else if (key === '.schema') {
|
|
67
67
|
// Add schema
|
|
68
|
-
env.db.schema.set(path, rule)
|
|
68
|
+
return env.db.schema.set(path, rule)
|
|
69
69
|
.catch(err => {
|
|
70
70
|
env.debug.error(`Error parsing ${path}/.schema: ${err.message}`);
|
|
71
71
|
});
|
|
@@ -80,15 +80,15 @@ export class PathBasedRules {
|
|
|
80
80
|
};
|
|
81
81
|
processRules('', accessRules.rules, []);
|
|
82
82
|
// Watch file for changes
|
|
83
|
-
const
|
|
83
|
+
const watchFileListener = () => {
|
|
84
84
|
// Reload access rules
|
|
85
85
|
const accessRules = readRules();
|
|
86
86
|
processRules('', accessRules, []);
|
|
87
87
|
this.accessRules = accessRules;
|
|
88
88
|
};
|
|
89
|
-
fs.watchFile(rulesFilePath,
|
|
89
|
+
fs.watchFile(rulesFilePath, watchFileListener);
|
|
90
90
|
this.stop = () => {
|
|
91
|
-
fs.unwatchFile(rulesFilePath,
|
|
91
|
+
fs.unwatchFile(rulesFilePath, watchFileListener);
|
|
92
92
|
};
|
|
93
93
|
process.on('SIGINT', this.stop);
|
|
94
94
|
this.authEnabled = env.authEnabled;
|
package/dist/esm/server.js
CHANGED
|
@@ -17,6 +17,7 @@ import addWebManagerRoutes from './routes/webmanager.js';
|
|
|
17
17
|
import addMetadataRoutes from './routes/meta.js';
|
|
18
18
|
import addSwaggerMiddleware from './middleware/swagger.js';
|
|
19
19
|
import addCacheMiddleware from './middleware/cache.js';
|
|
20
|
+
import { DatabaseLog } from './logger.js';
|
|
20
21
|
// type PrivateLocalSettings = AceBaseLocalSettings & { storage: PrivateStorageSettings };
|
|
21
22
|
export class AceBaseServerNotReadyError extends Error {
|
|
22
23
|
constructor() { super('Server is not ready yet'); }
|
|
@@ -100,6 +101,7 @@ export class AceBaseServer extends SimpleEventEmitter {
|
|
|
100
101
|
const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
|
|
101
102
|
const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
|
|
102
103
|
const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
|
|
104
|
+
const logger = new DatabaseLog(logRef);
|
|
103
105
|
// Setup rules
|
|
104
106
|
const rulesFilePath = `${this.config.path}/${this.db.name}.acebase/rules.json`;
|
|
105
107
|
const rules = new PathBasedRules(rulesFilePath, config.auth.defaultAccessRule, { db, debug: this.debug, authEnabled: this.config.auth.enabled });
|
|
@@ -112,7 +114,7 @@ export class AceBaseServer extends SimpleEventEmitter {
|
|
|
112
114
|
debug: this.debug,
|
|
113
115
|
securityRef,
|
|
114
116
|
authRef,
|
|
115
|
-
|
|
117
|
+
log: logger,
|
|
116
118
|
tokenSalt: null,
|
|
117
119
|
clients,
|
|
118
120
|
authCache: null,
|
|
@@ -313,9 +315,9 @@ export class AceBaseServer extends SimpleEventEmitter {
|
|
|
313
315
|
* .then(quote => {
|
|
314
316
|
* console.log(`Got random quote: ${quote}`);
|
|
315
317
|
* })
|
|
316
|
-
* @param
|
|
317
|
-
* @param
|
|
318
|
-
* @param
|
|
318
|
+
* @param method http method to bind to
|
|
319
|
+
* @param ext_path path to bind to (appended to /ext/)
|
|
320
|
+
* @param handler your Express request handler callback
|
|
319
321
|
*/
|
|
320
322
|
extend(method, ext_path, handler) {
|
|
321
323
|
throw new AceBaseServerNotReadyError();
|
|
@@ -16,12 +16,11 @@ export class AceBaseServerHttpsConfig {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})(AUTH_ACCESS_DEFAULT || (AUTH_ACCESS_DEFAULT = {}));
|
|
19
|
+
export const AUTH_ACCESS_DEFAULT = {
|
|
20
|
+
DENY_ALL: 'deny',
|
|
21
|
+
ALLOW_ALL: 'allow',
|
|
22
|
+
ALLOW_AUTHENTICATED: 'auth'
|
|
23
|
+
};
|
|
25
24
|
export class AceBaseServerAuthenticationSettings {
|
|
26
25
|
constructor(settings) {
|
|
27
26
|
/**
|
|
@@ -7,6 +7,8 @@ if (process.platform === 'win32' && currentDir.startsWith('/')) {
|
|
|
7
7
|
// 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
|
|
8
8
|
currentDir = currentDir.slice(1);
|
|
9
9
|
}
|
|
10
|
+
// tsc-esm-fix also does not use decodeURI to remove encoded characters (such as %20 for spaces)
|
|
11
|
+
currentDir = decodeURI(currentDir);
|
|
10
12
|
export const packageRootPath = resolve(currentDir, '../../..');
|
|
11
13
|
export default packageRootPath;
|
|
12
14
|
//# sourceMappingURL=rootpath.js.map
|
|
@@ -17,6 +17,8 @@ export class SignInError extends Error {
|
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
19
|
export const signIn = async (credentials, env, req) => {
|
|
20
|
+
const LOG_ACTION = 'auth.signin';
|
|
21
|
+
const LOG_DETAILS = { ip: req.ip, method: credentials.method };
|
|
20
22
|
try {
|
|
21
23
|
const query = env.authRef.query();
|
|
22
24
|
let tokenDetails;
|
|
@@ -34,7 +36,7 @@ export const signIn = async (credentials, env, req) => {
|
|
|
34
36
|
}
|
|
35
37
|
break;
|
|
36
38
|
}
|
|
37
|
-
case '
|
|
39
|
+
case 'internal': {
|
|
38
40
|
// Method used internally: uses the access token extracted from a public access token (see tokenDetails.access_token in above 'token' case)
|
|
39
41
|
if (typeof credentials.access_token !== 'string') {
|
|
40
42
|
throw new SignInError('invalid_details', 'sign in request has invalid arguments');
|
|
@@ -109,7 +111,9 @@ export const signIn = async (credentials, env, req) => {
|
|
|
109
111
|
// Update db
|
|
110
112
|
await snap.ref.update(updates);
|
|
111
113
|
// Log history item
|
|
112
|
-
|
|
114
|
+
if (credentials.method !== 'internal') {
|
|
115
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
116
|
+
}
|
|
113
117
|
// Add to cache
|
|
114
118
|
env.authCache.set(user.uid, user);
|
|
115
119
|
// Bind user to current request
|
|
@@ -118,7 +122,7 @@ export const signIn = async (credentials, env, req) => {
|
|
|
118
122
|
}
|
|
119
123
|
catch (err) {
|
|
120
124
|
// Log error
|
|
121
|
-
env.
|
|
125
|
+
env.log.error(LOG_ACTION, err.code ?? 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
|
|
122
126
|
throw err;
|
|
123
127
|
}
|
|
124
128
|
};
|
package/dist/esm/start.js
CHANGED
|
@@ -40,6 +40,9 @@ if (+getVariable('TXLOG', 0) === 1) {
|
|
|
40
40
|
maxAge: +getVariable('TXDAYS', 30)
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
+
if (+getVariable('AUTH', 1) === 0) {
|
|
44
|
+
options.authentication = { enabled: false };
|
|
45
|
+
}
|
|
43
46
|
const server = new AceBaseServer(dbname, options);
|
|
44
47
|
server.once("ready", () => {
|
|
45
48
|
server.debug.log(`AceBase server running`);
|
|
@@ -2,6 +2,12 @@ import { ColorStyle, Transport } from "acebase-core";
|
|
|
2
2
|
import { ConnectedClient } from "../shared/clients.js";
|
|
3
3
|
import { decodePublicAccessToken } from "../shared/tokens.js";
|
|
4
4
|
import { createServer } from "./socket.io.js";
|
|
5
|
+
export class SocketRequestError extends Error {
|
|
6
|
+
constructor(code, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
5
11
|
export const addWebsocketServer = (env) => {
|
|
6
12
|
// TODO: Allow using uWebSockets.js server instead of Socket.IO
|
|
7
13
|
const serverManager = createServer(env);
|
|
@@ -94,7 +100,7 @@ export const addWebsocketServer = (env) => {
|
|
|
94
100
|
serverManager.send(event.socket, 'oauth2-signin', { error: err.message });
|
|
95
101
|
}
|
|
96
102
|
});
|
|
97
|
-
const
|
|
103
|
+
const acknowledgeRequest = (socket, requestId) => {
|
|
98
104
|
// Send acknowledgement
|
|
99
105
|
serverManager.send(socket, 'result', {
|
|
100
106
|
success: true,
|
|
@@ -119,12 +125,12 @@ export const addWebsocketServer = (env) => {
|
|
|
119
125
|
const subscriptionPath = event.data.path;
|
|
120
126
|
const isSubscribed = () => subscriptionPath in client.subscriptions && client.subscriptions[subscriptionPath].some(s => s.event === event.data.event);
|
|
121
127
|
if (isSubscribed()) {
|
|
122
|
-
return
|
|
128
|
+
return acknowledgeRequest(event.socket, event.data.req_id);
|
|
123
129
|
}
|
|
124
130
|
// Get client
|
|
125
131
|
// const client = clients.get(socket.id);
|
|
126
132
|
if (!env.rules.userHasAccess(client.user, subscriptionPath, false)) {
|
|
127
|
-
env.
|
|
133
|
+
env.log.error('event.subscribe', 'access_denied', { uid: client.user?.uid ?? 'anonymous', path: subscriptionPath });
|
|
128
134
|
return failRequest(event.socket, event.data.req_id, 'access_denied');
|
|
129
135
|
}
|
|
130
136
|
const callback = (err, path, currentValue, previousValue, context) => {
|
|
@@ -165,7 +171,7 @@ export const addWebsocketServer = (env) => {
|
|
|
165
171
|
let subscr = { path: subscriptionPath, event: event.data.event, callback };
|
|
166
172
|
pathSubs.push(subscr);
|
|
167
173
|
env.db.api.subscribe(subscriptionPath, event.data.event, callback);
|
|
168
|
-
|
|
174
|
+
acknowledgeRequest(event.socket, event.data.req_id);
|
|
169
175
|
});
|
|
170
176
|
serverManager.on('unsubscribe', event => {
|
|
171
177
|
// Client unsubscribes from events on a node
|
|
@@ -178,7 +184,7 @@ export const addWebsocketServer = (env) => {
|
|
|
178
184
|
let pathSubs = client.subscriptions[event.data.path];
|
|
179
185
|
if (!pathSubs) {
|
|
180
186
|
// We have no knowledge of any active subscriptions on this path
|
|
181
|
-
return
|
|
187
|
+
return acknowledgeRequest(event.socket, event.data.req_id);
|
|
182
188
|
}
|
|
183
189
|
let remove = pathSubs;
|
|
184
190
|
if (event.data.event) {
|
|
@@ -195,7 +201,7 @@ export const addWebsocketServer = (env) => {
|
|
|
195
201
|
// No subscriptions left on this path, remove the path entry
|
|
196
202
|
delete client.subscriptions[event.data.path];
|
|
197
203
|
}
|
|
198
|
-
return
|
|
204
|
+
return acknowledgeRequest(event.socket, event.data.req_id);
|
|
199
205
|
});
|
|
200
206
|
serverManager.on('query-unsubscribe', event => {
|
|
201
207
|
// Client unsubscribing from realtime query events
|
|
@@ -206,15 +212,17 @@ export const addWebsocketServer = (env) => {
|
|
|
206
212
|
env.debug.verbose(`Client ${event.socket_id} is unsubscribing from realtime query "${event.data.query_id}"`);
|
|
207
213
|
// const client = clients.get(socket.id);
|
|
208
214
|
delete client.realtimeQueries[event.data.query_id];
|
|
209
|
-
|
|
215
|
+
acknowledgeRequest(event.socket, event.data.req_id);
|
|
210
216
|
});
|
|
211
217
|
const TRANSACTION_TIMEOUT_MS = 10000; // 10s to finish a started transaction
|
|
212
218
|
serverManager.on('transaction-start', event => {
|
|
213
219
|
// Start transaction
|
|
214
220
|
const client = getClientBySocketId(event.socket_id, 'transaction-start');
|
|
215
|
-
if (!client) {
|
|
221
|
+
if (!client || !event.data) {
|
|
216
222
|
return;
|
|
217
223
|
}
|
|
224
|
+
const LOG_ACTION = 'socket.transaction.start';
|
|
225
|
+
const LOG_DETAILS = { ip: event.socket.conn.remoteAddress, uid: client.user?.uid ?? null, path: event.data.path };
|
|
218
226
|
env.debug.verbose(`Client ${event.socket_id} is sending transaction start request on path "${event.data.path}"`);
|
|
219
227
|
const data = event.data;
|
|
220
228
|
const tx = {
|
|
@@ -226,11 +234,14 @@ export const addWebsocketServer = (env) => {
|
|
|
226
234
|
timeout: setTimeout(() => {
|
|
227
235
|
delete client.transactions[tx.id];
|
|
228
236
|
tx.finish(); // Finish without value cancels the transaction
|
|
237
|
+
env.log.error(LOG_ACTION, 'timeout', LOG_DETAILS);
|
|
229
238
|
serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: 'timeout' });
|
|
230
239
|
}, TRANSACTION_TIMEOUT_MS)
|
|
231
240
|
};
|
|
232
|
-
|
|
241
|
+
const access = env.rules.userHasAccess(client.user, data.path, true);
|
|
242
|
+
if (!access.allow) {
|
|
233
243
|
// throw new AccessDeniedError(`access_denied`);
|
|
244
|
+
env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
|
|
234
245
|
return serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: 'access_denied' });
|
|
235
246
|
}
|
|
236
247
|
// Bind to client
|
|
@@ -254,32 +265,36 @@ export const addWebsocketServer = (env) => {
|
|
|
254
265
|
serverManager.on('transaction-finish', async (event) => {
|
|
255
266
|
// Finish transaction
|
|
256
267
|
const client = getClientBySocketId(event.socket_id, 'transaction-finish');
|
|
257
|
-
if (!client) {
|
|
268
|
+
if (!client || !event.data) {
|
|
258
269
|
return;
|
|
259
270
|
}
|
|
271
|
+
const LOG_ACTION = 'socket.transaction.finish';
|
|
272
|
+
const LOG_DETAILS = { ip: event.socket.conn.remoteAddress, uid: client.user?.uid ?? null, path: event.data.path };
|
|
260
273
|
const data = event.data;
|
|
261
274
|
const tx = client.transactions[data.id];
|
|
262
275
|
try {
|
|
263
276
|
if (!tx || data.path !== tx.path) {
|
|
264
|
-
|
|
277
|
+
env.log.error(LOG_ACTION, tx ? 'wrong_path' : 'not_found', { ...LOG_DETAILS, id: data.id, tx_path: tx?.path ?? null });
|
|
278
|
+
throw new SocketRequestError('transaction_not_found', 'Transaction not found');
|
|
265
279
|
}
|
|
266
280
|
clearTimeout(tx.timeout);
|
|
267
281
|
delete client.transactions[data.id];
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
try {
|
|
273
|
-
await tx.finish(newValue);
|
|
274
|
-
env.debug.verbose(`Transaction ${tx.id} finished`);
|
|
275
|
-
serverManager.send(event.socket, 'tx_completed', { id: tx.id });
|
|
276
|
-
}
|
|
277
|
-
catch (err) {
|
|
278
|
-
serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: err.message });
|
|
282
|
+
const access = env.rules.userHasAccess(client.user, data.path, true);
|
|
283
|
+
if (!access.allow) {
|
|
284
|
+
env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
|
|
285
|
+
throw new SocketRequestError('access_denied', 'Access denied');
|
|
279
286
|
}
|
|
287
|
+
const newValue = 'val' in data.value ? Transport.deserialize(data.value) : undefined;
|
|
288
|
+
const { cursor } = await tx.finish(newValue);
|
|
289
|
+
env.debug.verbose(`Transaction ${tx.id} finished`);
|
|
290
|
+
serverManager.send(event.socket, 'tx_completed', { id: tx.id, context: { cursor } });
|
|
280
291
|
}
|
|
281
292
|
catch (err) {
|
|
282
|
-
|
|
293
|
+
if (!(err instanceof SocketRequestError)) {
|
|
294
|
+
// Other errors have been logged already
|
|
295
|
+
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
296
|
+
}
|
|
297
|
+
serverManager.send(event.socket, 'tx_error', { id: tx.id, reason: err.code ?? err.message, data });
|
|
283
298
|
tx.finish(); // Finish with undefined, canceling the transaction
|
|
284
299
|
}
|
|
285
300
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
const createSocketIOServer =
|
|
1
|
+
import { Server as SocketIOServer } from 'socket.io';
|
|
2
|
+
const createSocketIOServer = (httpServer, options) => {
|
|
3
|
+
return new SocketIOServer(httpServer, options);
|
|
4
|
+
};
|
|
3
5
|
import { WebSocketManager } from './manager.js';
|
|
4
|
-
import {
|
|
6
|
+
import { getCorsOptions } from '../middleware/cors.js';
|
|
5
7
|
export class SocketIOManager extends WebSocketManager {
|
|
6
8
|
constructor() {
|
|
7
9
|
super('Socket.IO');
|
|
@@ -31,14 +33,10 @@ export const createServer = (env) => {
|
|
|
31
33
|
pingInterval: 5000,
|
|
32
34
|
pingTimeout: 5000,
|
|
33
35
|
maxHttpBufferSize: maxPayloadBytes,
|
|
34
|
-
// socket.io 2.x:
|
|
35
|
-
|
|
36
|
-
const headers = getCorsHeaders(env.config.allowOrigin, req.headers.origin);
|
|
37
|
-
res.writeHead(200, headers);
|
|
38
|
-
res.end();
|
|
39
|
-
}
|
|
36
|
+
// Allow socket.io 2.x clients (using engine.io 3.x):
|
|
37
|
+
allowEIO3: true,
|
|
40
38
|
// socket.io 3+ uses cors package:
|
|
41
|
-
|
|
39
|
+
cors: getCorsOptions(env.config.allowOrigin)
|
|
42
40
|
});
|
|
43
41
|
// Setup event emitter for communication with consuming server
|
|
44
42
|
const manager = new SocketIOManager();
|
|
@@ -47,7 +45,7 @@ export const createServer = (env) => {
|
|
|
47
45
|
// Notify manager of new connection
|
|
48
46
|
manager.emit('connect', { socket, socket_id: socket.id });
|
|
49
47
|
// Pass any events to manager
|
|
50
|
-
socket.on('disconnect',
|
|
48
|
+
socket.on('disconnect', reason => manager.emit('disconnect', { socket, socket_id: socket.id, data: reason }));
|
|
51
49
|
socket.on('reconnect', data => manager.emit('connect', { socket, socket_id: socket.id, data }));
|
|
52
50
|
socket.on('signin', accessToken => manager.emit('signin', { socket, socket_id: socket.id, data: { accessToken } }));
|
|
53
51
|
socket.on('signout', data => manager.emit('signout', { socket, socket_id: socket.id, data }));
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DataReference } from "acebase-core";
|
|
2
|
+
export declare class DatabaseLog {
|
|
3
|
+
private logRef;
|
|
4
|
+
constructor(logRef: DataReference);
|
|
5
|
+
/**
|
|
6
|
+
* Logs an action initiated by a client/user with a positive or negative outcome. Used by `success` and `failure`
|
|
7
|
+
* @param action action identifier
|
|
8
|
+
* @param success whether the action was successful
|
|
9
|
+
* @param details any additional details to be logged
|
|
10
|
+
*/
|
|
11
|
+
event(action: string, details: any): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Logs a system warning
|
|
14
|
+
* @param action action identifier
|
|
15
|
+
* @param code warning code
|
|
16
|
+
* @param details any additional details to be logged
|
|
17
|
+
*/
|
|
18
|
+
warning(action: string, code: string, details: any): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Logs a system or client/user error
|
|
21
|
+
* @param action action identifier
|
|
22
|
+
* @param code error code
|
|
23
|
+
* @param details any additional details to be logged
|
|
24
|
+
*/
|
|
25
|
+
error(action: string, code: string, details: any, unexpectedError?: any): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Query the logs
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
query(): import("acebase-core").DataReferenceQuery;
|
|
31
|
+
/**
|
|
32
|
+
* Reference to the logs database collection
|
|
33
|
+
*/
|
|
34
|
+
get ref(): DataReference;
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NextFunction } from "express";
|
|
2
|
+
import { RouteInitEnvironment, RouteRequest } from "../shared/env";
|
|
3
|
+
import type { Response } from "../shared/http";
|
|
4
|
+
/**
|
|
5
|
+
* Middleware function that checks if the current user is `admin`. An 403 Forbidden error will be sent in the response if
|
|
6
|
+
* authentication is enabled on the server and the user is not signed in as admin.
|
|
7
|
+
*
|
|
8
|
+
* Can be applied to any route by adding it in the router chain.
|
|
9
|
+
* @example
|
|
10
|
+
* app.get('/endpoint', adminOnly(env), (req, res) => {
|
|
11
|
+
* // If we get here we are either an admin,
|
|
12
|
+
* // or the server doesn't have authentication enabled.
|
|
13
|
+
* })
|
|
14
|
+
* @param env Middle
|
|
15
|
+
* @param errorMessage
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare const adminOnly: (env: RouteInitEnvironment, errorMessage?: string) => (req: RouteRequest, res: Response, next: NextFunction) => void;
|
|
19
|
+
export default adminOnly;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
2
|
/**
|
|
3
3
|
* Details of your app to access the Dropbox API
|
|
4
4
|
*/
|
|
@@ -16,8 +16,7 @@ interface IDropboxAuthToken {
|
|
|
16
16
|
account_id: string;
|
|
17
17
|
uid: string;
|
|
18
18
|
}
|
|
19
|
-
export declare class DropboxAuthProvider
|
|
20
|
-
private settings;
|
|
19
|
+
export declare class DropboxAuthProvider extends OAuth2Provider {
|
|
21
20
|
constructor(settings: IDropboxAuthSettings);
|
|
22
21
|
/**
|
|
23
22
|
* Starts auth flow by getting the url the user should be redirected to
|
|
@@ -30,17 +29,7 @@ export declare class DropboxAuthProvider implements IOAuth2Provider {
|
|
|
30
29
|
* @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
|
|
31
30
|
* @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
|
|
32
31
|
*/
|
|
33
|
-
init(info:
|
|
34
|
-
redirect_url: string;
|
|
35
|
-
state?: string;
|
|
36
|
-
options?: {
|
|
37
|
-
locale?: string;
|
|
38
|
-
require_role?: string;
|
|
39
|
-
disable_signup?: boolean;
|
|
40
|
-
force_reapprove?: boolean;
|
|
41
|
-
force_reauthentication?: boolean;
|
|
42
|
-
};
|
|
43
|
-
}): Promise<string>;
|
|
32
|
+
init(info: OAuth2ProviderInitInfo): Promise<string>;
|
|
44
33
|
getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IDropboxAuthToken>;
|
|
45
34
|
getUserInfo(access_token: string): Promise<{
|
|
46
35
|
id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
2
|
/**
|
|
3
3
|
* Details of your app to access the Facebook Graph API
|
|
4
4
|
*/
|
|
@@ -14,18 +14,14 @@ interface IFacebookAuthToken {
|
|
|
14
14
|
scope: string;
|
|
15
15
|
token_type: string;
|
|
16
16
|
}
|
|
17
|
-
export declare class FacebookAuthProvider
|
|
18
|
-
private settings;
|
|
17
|
+
export declare class FacebookAuthProvider extends OAuth2Provider {
|
|
19
18
|
constructor(settings: IFacebookAuthSettings);
|
|
20
19
|
/**
|
|
21
20
|
* Starts auth flow by getting the url the user should be redirected to
|
|
22
21
|
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
23
22
|
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
24
23
|
*/
|
|
25
|
-
init(info:
|
|
26
|
-
redirect_url: string;
|
|
27
|
-
state?: string;
|
|
28
|
-
}): Promise<string>;
|
|
24
|
+
init(info: OAuth2ProviderInitInfo): Promise<string>;
|
|
29
25
|
getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IFacebookAuthToken>;
|
|
30
26
|
getUserInfo(access_token: string): Promise<{
|
|
31
27
|
id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IOAuth2ProviderSettings, IOpenIDToken, IOpenIDConfiguration, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2ProviderInitInfo, OAuth2Provider } from "./oauth-provider";
|
|
2
2
|
/**
|
|
3
3
|
* Details of your app to access the Google API. See https://developers.google.com/identity/protocols/oauth2/scopes
|
|
4
4
|
*/
|
|
@@ -15,8 +15,7 @@ interface IGoogleAuthToken {
|
|
|
15
15
|
scope: string;
|
|
16
16
|
token_type: string;
|
|
17
17
|
}
|
|
18
|
-
export declare class GoogleAuthProvider
|
|
19
|
-
private settings;
|
|
18
|
+
export declare class GoogleAuthProvider extends OAuth2Provider {
|
|
20
19
|
_config: IOpenIDConfiguration;
|
|
21
20
|
constructor(settings: IGoogleAuthSettings);
|
|
22
21
|
getOpenIDConfig(): Promise<IOpenIDConfiguration>;
|
|
@@ -25,10 +24,7 @@ export declare class GoogleAuthProvider implements IOAuth2Provider {
|
|
|
25
24
|
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
26
25
|
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
27
26
|
*/
|
|
28
|
-
init(info:
|
|
29
|
-
redirect_url: string;
|
|
30
|
-
state?: string;
|
|
31
|
-
}): Promise<string>;
|
|
27
|
+
init(info: OAuth2ProviderInitInfo): Promise<string>;
|
|
32
28
|
getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IGoogleAuthToken>;
|
|
33
29
|
revokeAccess(access_token: string): Promise<void>;
|
|
34
30
|
getUserInfo(access_token: string): Promise<{
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FacebookAuthProvider } from './facebook';
|
|
3
|
-
import { GoogleAuthProvider } from './google';
|
|
4
|
-
import { InstagramAuthProvider } from './instagram';
|
|
5
|
-
import { SpotifyAuthProvider } from './spotify';
|
|
1
|
+
import { OAuth2Provider } from './oauth-provider';
|
|
6
2
|
export { DropboxAuthProvider, IDropboxAuthSettings } from './dropbox';
|
|
7
3
|
export { FacebookAuthProvider, IFacebookAuthSettings } from './facebook';
|
|
8
4
|
export { GoogleAuthProvider, IGoogleAuthSettings } from './google';
|
|
9
5
|
export { InstagramAuthProvider, IInstagramAuthSettings } from './instagram';
|
|
10
6
|
export { SpotifyAuthProvider, ISpotifyAuthSettings } from './spotify';
|
|
11
7
|
declare const oAuth2Providers: {
|
|
12
|
-
|
|
13
|
-
facebook: typeof FacebookAuthProvider;
|
|
14
|
-
google: typeof GoogleAuthProvider;
|
|
15
|
-
instagram: typeof InstagramAuthProvider;
|
|
16
|
-
spotify: typeof SpotifyAuthProvider;
|
|
8
|
+
[key: string]: typeof OAuth2Provider;
|
|
17
9
|
};
|
|
18
10
|
export default oAuth2Providers;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
2
|
/**
|
|
3
3
|
* Details of your app to access the Legacy Instagram API.
|
|
4
4
|
*/
|
|
@@ -24,18 +24,14 @@ interface IInstagramUser {
|
|
|
24
24
|
followed_by: number;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
export declare class InstagramAuthProvider
|
|
28
|
-
private settings;
|
|
27
|
+
export declare class InstagramAuthProvider extends OAuth2Provider {
|
|
29
28
|
constructor(settings: IInstagramAuthSettings);
|
|
30
29
|
/**
|
|
31
30
|
* Starts auth flow by getting the url the user should be redirected to
|
|
32
31
|
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
33
32
|
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
34
33
|
*/
|
|
35
|
-
init(info:
|
|
36
|
-
redirect_url: string;
|
|
37
|
-
state?: string;
|
|
38
|
-
}): Promise<string>;
|
|
34
|
+
init(info: OAuth2ProviderInitInfo): Promise<string>;
|
|
39
35
|
_userInfo: IInstagramUser;
|
|
40
36
|
getAccessToken(params: IOAuth2AuthCodeParams): Promise<IInstagramAuthToken>;
|
|
41
37
|
getUserInfo(access_token: string): Promise<{
|