acebase-server 1.15.2 → 1.16.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/.eslintrc.json +49 -0
- package/README.md +10 -0
- package/dist/cjs/auth.js +2 -2
- package/dist/cjs/cluster.js +2 -2
- package/dist/cjs/middleware/cors.js +3 -3
- package/dist/cjs/oauth-providers/dropbox.js +22 -22
- package/dist/cjs/oauth-providers/facebook.js +16 -16
- package/dist/cjs/oauth-providers/google.js +33 -39
- package/dist/cjs/oauth-providers/index.js +1 -1
- package/dist/cjs/oauth-providers/instagram.js +12 -12
- package/dist/cjs/oauth-providers/oauth-provider.js +0 -5
- package/dist/cjs/oauth-providers/spotify.js +34 -34
- package/dist/cjs/routes/auth-change-password.js +5 -5
- package/dist/cjs/routes/auth-delete.js +1 -1
- package/dist/cjs/routes/auth-forgot-password.js +2 -2
- package/dist/cjs/routes/auth-reset-password.js +11 -9
- package/dist/cjs/routes/auth-signin.js +1 -1
- package/dist/cjs/routes/auth-signout.js +1 -1
- package/dist/cjs/routes/auth-signup.js +5 -5
- package/dist/cjs/routes/auth-update.js +1 -1
- package/dist/cjs/routes/auth-verify-email.js +8 -6
- package/dist/cjs/routes/auth.js +1 -1
- package/dist/cjs/routes/data-export.js +1 -1
- package/dist/cjs/routes/data-get.js +2 -2
- package/dist/cjs/routes/data-index-list.js +0 -1
- package/dist/cjs/routes/data-query.js +1 -1
- package/dist/cjs/routes/data-reflect.js +4 -4
- package/dist/cjs/routes/data-schema-get.js +1 -1
- package/dist/cjs/routes/data-schemas-list.js +1 -1
- package/dist/cjs/routes/data-transaction.js +1 -1
- package/dist/cjs/routes/docs.js +57 -54
- package/dist/cjs/routes/meta-info.js +8 -12
- package/dist/cjs/routes/meta-logs.js +1 -1
- package/dist/cjs/routes/oauth2-init.js +8 -5
- package/dist/cjs/routes/oauth2-refresh.js +2 -2
- package/dist/cjs/routes/oauth2-signin.js +23 -23
- package/dist/cjs/routes/webmanager.js +4 -4
- package/dist/cjs/rules.js +8 -8
- package/dist/cjs/schema/user.js +1 -2
- package/dist/cjs/server.js +74 -31
- package/dist/cjs/settings/email.js +0 -2
- package/dist/cjs/settings/index.js +19 -4
- package/dist/cjs/shared/email.js +0 -4
- package/dist/cjs/shared/env.js +0 -2
- package/dist/cjs/shared/error.js +0 -1
- package/dist/cjs/shared/http.js +9 -1
- package/dist/cjs/shared/password.js +5 -5
- package/dist/cjs/shared/rootpath.js +1 -1
- package/dist/cjs/shared/signin.js +3 -3
- package/dist/cjs/shared/simple-fetch.js +5 -5
- package/dist/cjs/shared/tokens.js +3 -3
- package/dist/cjs/start.js +6 -6
- package/dist/cjs/websocket/index.js +11 -11
- package/dist/cjs/websocket/socket.io.js +2 -1
- package/dist/esm/auth.js +5 -5
- package/dist/esm/cluster.js +2 -2
- package/dist/esm/middleware/admin-only.js +1 -1
- package/dist/esm/middleware/cors.js +3 -3
- package/dist/esm/middleware/user.js +3 -3
- package/dist/esm/oauth-providers/dropbox.js +47 -51
- package/dist/esm/oauth-providers/facebook.js +34 -38
- package/dist/esm/oauth-providers/google.js +33 -39
- package/dist/esm/oauth-providers/index.js +1 -1
- package/dist/esm/oauth-providers/instagram.js +28 -32
- package/dist/esm/oauth-providers/oauth-provider.js +0 -5
- package/dist/esm/oauth-providers/spotify.js +46 -52
- package/dist/esm/routes/auth-change-password.js +5 -5
- package/dist/esm/routes/auth-delete.js +1 -1
- package/dist/esm/routes/auth-forgot-password.js +2 -2
- package/dist/esm/routes/auth-reset-password.js +11 -9
- package/dist/esm/routes/auth-signin.js +1 -1
- package/dist/esm/routes/auth-signout.js +1 -1
- package/dist/esm/routes/auth-signup.js +5 -5
- package/dist/esm/routes/auth-update.js +1 -1
- package/dist/esm/routes/auth-verify-email.js +8 -6
- package/dist/esm/routes/auth.js +1 -1
- package/dist/esm/routes/data-export.js +1 -1
- package/dist/esm/routes/data-get.js +2 -2
- package/dist/esm/routes/data-index-list.js +0 -1
- package/dist/esm/routes/data-query.js +1 -1
- package/dist/esm/routes/data-reflect.js +4 -4
- package/dist/esm/routes/data-schema-get.js +1 -1
- package/dist/esm/routes/data-schemas-list.js +1 -1
- package/dist/esm/routes/data-transaction.js +1 -1
- package/dist/esm/routes/data.js +1 -1
- package/dist/esm/routes/docs.js +56 -54
- package/dist/esm/routes/meta-info.js +8 -12
- package/dist/esm/routes/meta-logs.js +1 -1
- package/dist/esm/routes/oauth2-init.js +8 -5
- package/dist/esm/routes/oauth2-refresh.js +2 -2
- package/dist/esm/routes/oauth2-signin.js +20 -20
- package/dist/esm/routes/webmanager.js +5 -5
- package/dist/esm/rules.js +8 -8
- package/dist/esm/schema/user.js +1 -2
- package/dist/esm/server.js +72 -30
- package/dist/esm/settings/email.js +0 -2
- package/dist/esm/settings/index.js +19 -4
- package/dist/esm/shared/email.js +0 -4
- package/dist/esm/shared/env.js +0 -2
- package/dist/esm/shared/error.js +0 -1
- package/dist/esm/shared/http.js +7 -0
- package/dist/esm/shared/password.js +5 -5
- package/dist/esm/shared/rootpath.js +2 -2
- package/dist/esm/shared/signin.js +6 -6
- package/dist/esm/shared/simple-fetch.js +5 -5
- package/dist/esm/shared/tokens.js +3 -3
- package/dist/esm/start.js +6 -6
- package/dist/esm/websocket/index.js +15 -15
- package/dist/esm/websocket/manager.js +1 -1
- package/dist/esm/websocket/socket.io.js +2 -1
- package/dist/types/auth.d.ts +1 -1
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/middleware/404.d.ts +1 -1
- package/dist/types/middleware/admin-only.d.ts +3 -3
- package/dist/types/middleware/cache.d.ts +1 -1
- package/dist/types/middleware/context.d.ts +1 -1
- package/dist/types/middleware/cors.d.ts +1 -1
- package/dist/types/middleware/swagger.d.ts +1 -1
- package/dist/types/middleware/user.d.ts +1 -1
- package/dist/types/oauth-providers/dropbox.d.ts +1 -1
- package/dist/types/oauth-providers/facebook.d.ts +1 -1
- package/dist/types/oauth-providers/google.d.ts +1 -1
- package/dist/types/oauth-providers/instagram.d.ts +1 -1
- package/dist/types/oauth-providers/spotify.d.ts +1 -1
- package/dist/types/routes/auth-change-password.d.ts +2 -2
- package/dist/types/routes/auth-delete.d.ts +2 -2
- package/dist/types/routes/auth-forgot-password.d.ts +2 -2
- package/dist/types/routes/auth-reset-password.d.ts +2 -2
- package/dist/types/routes/auth-signin.d.ts +2 -2
- package/dist/types/routes/auth-signout.d.ts +2 -2
- package/dist/types/routes/auth-signup.d.ts +2 -2
- package/dist/types/routes/auth-state.d.ts +3 -3
- package/dist/types/routes/auth-update.d.ts +2 -2
- package/dist/types/routes/auth-verify-email.d.ts +2 -2
- package/dist/types/routes/data-exists.d.ts +1 -1
- package/dist/types/routes/data-export.d.ts +1 -1
- package/dist/types/routes/data-get.d.ts +1 -1
- package/dist/types/routes/data-import.d.ts +1 -1
- package/dist/types/routes/data-index-create.d.ts +2 -2
- package/dist/types/routes/data-index-delete.d.ts +1 -1
- package/dist/types/routes/data-index-list.d.ts +2 -2
- package/dist/types/routes/data-query.d.ts +1 -1
- package/dist/types/routes/data-reflect.d.ts +1 -1
- package/dist/types/routes/data-schema-get.d.ts +1 -1
- package/dist/types/routes/data-schema-set.d.ts +1 -1
- package/dist/types/routes/data-schema-test.d.ts +1 -1
- package/dist/types/routes/data-schemas-list.d.ts +1 -1
- package/dist/types/routes/data-set.d.ts +1 -1
- package/dist/types/routes/data-sync-changes.d.ts +1 -1
- package/dist/types/routes/data-sync-mutations.d.ts +1 -1
- package/dist/types/routes/data-transaction.d.ts +2 -2
- package/dist/types/routes/data-update.d.ts +1 -1
- package/dist/types/routes/data.d.ts +1 -1
- package/dist/types/routes/meta-info.d.ts +1 -1
- package/dist/types/routes/meta-logs.d.ts +1 -1
- package/dist/types/routes/meta-ping.d.ts +1 -1
- package/dist/types/routes/meta-stats.d.ts +1 -1
- package/dist/types/routes/oauth2-init.d.ts +1 -1
- package/dist/types/routes/oauth2-refresh.d.ts +1 -1
- package/dist/types/routes/oauth2-signin.d.ts +1 -1
- package/dist/types/routes/webmanager.d.ts +1 -1
- package/dist/types/schema/user.d.ts +2 -2
- package/dist/types/server.d.ts +3 -0
- package/dist/types/settings/index.d.ts +23 -0
- package/dist/types/shared/clients.d.ts +3 -3
- package/dist/types/shared/env.d.ts +2 -1
- package/dist/types/shared/http.d.ts +5 -0
- package/dist/types/shared/signin.d.ts +4 -4
- package/dist/types/shared/validate.d.ts +1 -1
- package/dist/types/websocket/index.d.ts +1 -1
- package/dist/types/websocket/manager.d.ts +1 -1
- package/img/acebase-swagger-ui.png +0 -0
- package/img/acebase-webmanager.png +0 -0
- package/package.json +10 -5
- package/src/routes/auth-signin.yaml +2 -2
- package/webmanager/acebase-client-browser.min.js +8 -11
- package/webmanager/index.html +1 -0
- package/webmanager/index.js +67 -71
- package/.vscode/launch.json +0 -24
- package/create-package-files +0 -25
- 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/logger.js.map +0 -1
- package/dist/cjs/middleware/404.js.map +0 -1
- package/dist/cjs/middleware/admin-only.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-logs.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/logger.js.map +0 -1
- package/dist/esm/middleware/404.js.map +0 -1
- package/dist/esm/middleware/admin-only.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-logs.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/dist/types/auth.d.ts.map +0 -1
- package/dist/types/cluster.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/middleware/404.d.ts.map +0 -1
- package/dist/types/middleware/admin-only.d.ts.map +0 -1
- package/dist/types/middleware/cache.d.ts.map +0 -1
- package/dist/types/middleware/connection.d.ts.map +0 -1
- package/dist/types/middleware/context.d.ts.map +0 -1
- package/dist/types/middleware/cors.d.ts.map +0 -1
- package/dist/types/middleware/swagger.d.ts.map +0 -1
- package/dist/types/middleware/user.d.ts.map +0 -1
- package/dist/types/oauth-providers/dropbox.d.ts.map +0 -1
- package/dist/types/oauth-providers/facebook.d.ts.map +0 -1
- package/dist/types/oauth-providers/google.d.ts.map +0 -1
- package/dist/types/oauth-providers/index.d.ts.map +0 -1
- package/dist/types/oauth-providers/instagram.d.ts.map +0 -1
- package/dist/types/oauth-providers/oauth-provider.d.ts.map +0 -1
- package/dist/types/oauth-providers/spotify.d.ts.map +0 -1
- package/dist/types/routes/auth-change-password.d.ts.map +0 -1
- package/dist/types/routes/auth-delete.d.ts.map +0 -1
- package/dist/types/routes/auth-forgot-password.d.ts.map +0 -1
- package/dist/types/routes/auth-reset-password.d.ts.map +0 -1
- package/dist/types/routes/auth-signin.d.ts.map +0 -1
- package/dist/types/routes/auth-signout.d.ts.map +0 -1
- package/dist/types/routes/auth-signup.d.ts.map +0 -1
- package/dist/types/routes/auth-state.d.ts.map +0 -1
- package/dist/types/routes/auth-update.d.ts.map +0 -1
- package/dist/types/routes/auth-verify-email.d.ts.map +0 -1
- package/dist/types/routes/auth.d.ts.map +0 -1
- package/dist/types/routes/data-exists.d.ts.map +0 -1
- package/dist/types/routes/data-export.d.ts.map +0 -1
- package/dist/types/routes/data-get.d.ts.map +0 -1
- package/dist/types/routes/data-import.d.ts.map +0 -1
- package/dist/types/routes/data-index-create.d.ts.map +0 -1
- package/dist/types/routes/data-index-delete.d.ts.map +0 -1
- package/dist/types/routes/data-index-list.d.ts.map +0 -1
- package/dist/types/routes/data-query.d.ts.map +0 -1
- package/dist/types/routes/data-reflect.d.ts.map +0 -1
- package/dist/types/routes/data-schema-get.d.ts.map +0 -1
- package/dist/types/routes/data-schema-set.d.ts.map +0 -1
- package/dist/types/routes/data-schema-test.d.ts.map +0 -1
- package/dist/types/routes/data-schemas-list.d.ts.map +0 -1
- package/dist/types/routes/data-set.d.ts.map +0 -1
- package/dist/types/routes/data-sync-changes.d.ts.map +0 -1
- package/dist/types/routes/data-sync-mutations.d.ts.map +0 -1
- package/dist/types/routes/data-transaction.d.ts.map +0 -1
- package/dist/types/routes/data-update.d.ts.map +0 -1
- package/dist/types/routes/data.d.ts.map +0 -1
- package/dist/types/routes/docs.d.ts.map +0 -1
- package/dist/types/routes/meta-info.d.ts.map +0 -1
- package/dist/types/routes/meta-logs.d.ts.map +0 -1
- package/dist/types/routes/meta-ping.d.ts.map +0 -1
- package/dist/types/routes/meta-stats.d.ts.map +0 -1
- package/dist/types/routes/meta.d.ts.map +0 -1
- package/dist/types/routes/oauth2-init.d.ts.map +0 -1
- package/dist/types/routes/oauth2-refresh.d.ts.map +0 -1
- package/dist/types/routes/oauth2-signin.d.ts.map +0 -1
- package/dist/types/routes/webmanager.d.ts.map +0 -1
- package/dist/types/rules.d.ts.map +0 -1
- package/dist/types/schema/user.d.ts.map +0 -1
- package/dist/types/server.d.ts.map +0 -1
- package/dist/types/settings/email.d.ts.map +0 -1
- package/dist/types/settings/index.d.ts.map +0 -1
- package/dist/types/shared/clients.d.ts.map +0 -1
- package/dist/types/shared/email.d.ts.map +0 -1
- package/dist/types/shared/env.d.ts.map +0 -1
- package/dist/types/shared/error.d.ts.map +0 -1
- package/dist/types/shared/http.d.ts.map +0 -1
- package/dist/types/shared/password.d.ts.map +0 -1
- package/dist/types/shared/rootpath.d.ts.map +0 -1
- package/dist/types/shared/signin.d.ts.map +0 -1
- package/dist/types/shared/simple-fetch.d.ts.map +0 -1
- package/dist/types/shared/tokens.d.ts.map +0 -1
- package/dist/types/shared/validate.d.ts.map +0 -1
- package/dist/types/start.d.ts.map +0 -1
- package/dist/types/test.d.ts.map +0 -1
- package/dist/types/websocket/index.d.ts.map +0 -1
- package/dist/types/websocket/manager.d.ts.map +0 -1
- package/dist/types/websocket/socket.io.d.ts.map +0 -1
- package/src/auth.ts +0 -87
- package/src/cluster.ts +0 -62
- package/src/index.ts +0 -4
- package/src/logger.ts +0 -56
- package/src/middleware/404.ts +0 -13
- package/src/middleware/admin-only.ts +0 -29
- package/src/middleware/cache.ts +0 -15
- package/src/middleware/connection.ts +0 -48
- package/src/middleware/context.ts +0 -23
- package/src/middleware/cors.ts +0 -49
- package/src/middleware/swagger.ts +0 -19
- package/src/middleware/user.ts +0 -51
- package/src/oauth-providers/dropbox.ts +0 -144
- package/src/oauth-providers/facebook.ts +0 -103
- package/src/oauth-providers/google.ts +0 -147
- package/src/oauth-providers/index.ts +0 -21
- package/src/oauth-providers/instagram.ts +0 -98
- package/src/oauth-providers/oauth-provider.ts +0 -65
- package/src/oauth-providers/spotify.ts +0 -127
- package/src/placeholder.d.ts +0 -12
- package/src/routes/auth-change-password.ts +0 -92
- package/src/routes/auth-delete.ts +0 -49
- package/src/routes/auth-forgot-password.ts +0 -77
- package/src/routes/auth-reset-password.ts +0 -96
- package/src/routes/auth-signin.ts +0 -55
- package/src/routes/auth-signout.ts +0 -64
- package/src/routes/auth-signup.ts +0 -164
- package/src/routes/auth-state.ts +0 -20
- package/src/routes/auth-update.ts +0 -149
- package/src/routes/auth-verify-email.ts +0 -75
- package/src/routes/auth.ts +0 -67
- package/src/routes/data-exists.ts +0 -31
- package/src/routes/data-export.ts +0 -51
- package/src/routes/data-get.ts +0 -67
- package/src/routes/data-import.ts +0 -56
- package/src/routes/data-index-create.ts +0 -82
- package/src/routes/data-index-delete.ts +0 -36
- package/src/routes/data-index-list.ts +0 -39
- package/src/routes/data-query.ts +0 -97
- package/src/routes/data-reflect.ts +0 -91
- package/src/routes/data-schema-get.ts +0 -36
- package/src/routes/data-schema-set.ts +0 -35
- package/src/routes/data-schema-test.ts +0 -48
- package/src/routes/data-schemas-list.ts +0 -31
- package/src/routes/data-set.ts +0 -83
- package/src/routes/data-sync-changes.ts +0 -77
- package/src/routes/data-sync-mutations.ts +0 -77
- package/src/routes/data-transaction.ts +0 -166
- package/src/routes/data-update.ts +0 -84
- 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-logs.ts +0 -57
- package/src/routes/meta-ping.ts +0 -15
- package/src/routes/meta-stats.ts +0 -31
- package/src/routes/meta.ts +0 -22
- package/src/routes/oauth2-init.ts +0 -44
- package/src/routes/oauth2-refresh.ts +0 -39
- package/src/routes/oauth2-signin.ts +0 -286
- package/src/routes/webmanager.ts +0 -29
- package/src/rules.ts +0 -189
- package/src/schema/user.ts +0 -99
- package/src/server.ts +0 -419
- package/src/settings/email.ts +0 -18
- package/src/settings/index.ts +0 -241
- package/src/shared/clients.ts +0 -31
- package/src/shared/email.ts +0 -33
- package/src/shared/env.ts +0 -38
- package/src/shared/error.ts +0 -37
- package/src/shared/http.ts +0 -26
- package/src/shared/password.ts +0 -41
- package/src/shared/rootpath.ts +0 -17
- package/src/shared/signin.ts +0 -149
- 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 -48
- package/src/test.ts +0 -10
- package/src/websocket/index.ts +0 -336
- package/src/websocket/manager.ts +0 -46
- package/src/websocket/socket.io.ts +0 -90
- package/tsconfig-cjs.json +0 -11
- package/tsconfig.json +0 -22
package/src/routes/data-set.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { SchemaValidationError } from 'acebase';
|
|
2
|
-
import { Transport } from 'acebase-core';
|
|
3
|
-
import { RuleValidationFailCode } from '../rules';
|
|
4
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
5
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
|
|
6
|
-
|
|
7
|
-
export class SetDataError extends Error {
|
|
8
|
-
constructor(public code: 'invalid_serialized_value', message: string) {
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export type RequestQuery = null;
|
|
13
|
-
export type RequestBody = Transport.SerializedValue; // { val: any; map?: string|Record<string, 'date'|'binary'|'reference'|'regexp'|'array'> };
|
|
14
|
-
export type ResponseBody = { success: true } // 200
|
|
15
|
-
| { code: 'invalid_serialized_value', message: string } // 400
|
|
16
|
-
| { code: RuleValidationFailCode, message: string } // 403
|
|
17
|
-
| { code: 'schema_validation_failed', message: string } // 422
|
|
18
|
-
| { code: string, message: string } // 500
|
|
19
|
-
|
|
20
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
21
|
-
|
|
22
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
23
|
-
|
|
24
|
-
env.app.put(`/data/${env.db.name}/*`, async (req: Request, res) => {
|
|
25
|
-
|
|
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: req.user?.uid ?? null, path };
|
|
29
|
-
|
|
30
|
-
const access = env.rules.userHasAccess(req.user, path, true);
|
|
31
|
-
if (!access.allow) {
|
|
32
|
-
env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null, rule_error: access.details?.message ?? null });
|
|
33
|
-
return sendUnauthorizedError(res, access.code, access.message);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
const data = req.body;
|
|
38
|
-
if (typeof data?.val === 'undefined' || !['string','object','undefined'].includes(typeof data?.map)) {
|
|
39
|
-
throw new SetDataError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
40
|
-
}
|
|
41
|
-
const val = Transport.deserialize(data);
|
|
42
|
-
|
|
43
|
-
if (path === '' && req.user?.uid !== 'admin' && val !== null && typeof val === 'object') {
|
|
44
|
-
// Non-admin user: remove any private properties from the update object
|
|
45
|
-
Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Schema validation moved to storage, no need to check here but an early check won't do no harm!
|
|
49
|
-
const validation = await env.db.schema.check(path, val, false);
|
|
50
|
-
if (!validation.ok) {
|
|
51
|
-
throw new SchemaValidationError(validation.reason);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
await env.db.ref(path)
|
|
55
|
-
.context(req.context)
|
|
56
|
-
.set(val);
|
|
57
|
-
|
|
58
|
-
// NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
|
|
59
|
-
const returnContext = { acebase_cursor: req.context.acebase_cursor };
|
|
60
|
-
res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
|
|
61
|
-
|
|
62
|
-
res.send({ success: true });
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
if (err instanceof SchemaValidationError) {
|
|
66
|
-
env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
|
|
67
|
-
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
68
|
-
}
|
|
69
|
-
else if (err instanceof SetDataError) {
|
|
70
|
-
env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
|
|
71
|
-
sendBadRequestError(res, err);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
env.debug.error(`failed to set "${path}":`, err);
|
|
75
|
-
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
76
|
-
sendError(res, err);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export default addRoute;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { PathInfo, Transport, ValueChange } from 'acebase-core';
|
|
2
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
3
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
|
|
4
|
-
|
|
5
|
-
export type RequestQuery = {
|
|
6
|
-
path?: string;
|
|
7
|
-
for?: Array<{ path: string, events: string[] }>;
|
|
8
|
-
cursor?: string;
|
|
9
|
-
timestamp?: string;
|
|
10
|
-
};
|
|
11
|
-
export type RequestBody = null;
|
|
12
|
-
export type ResponseBody = ValueChange[] // 200
|
|
13
|
-
| { code: 'no_transaction_logging', message: string } // 400
|
|
14
|
-
| { code: 'invalid_request', message: string } // 400
|
|
15
|
-
| { code: 'not_authorized', message: string } // 403
|
|
16
|
-
| { code: 'unexpected', message: string }; // 500
|
|
17
|
-
|
|
18
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
19
|
-
|
|
20
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
21
|
-
|
|
22
|
-
env.app.get(`/sync/changes/${env.db.name}`, async (req: Request, res) => {
|
|
23
|
-
// Gets effective changes for specific path(s) and event combinations since given cursor
|
|
24
|
-
if (!env.config.transactions?.log) {
|
|
25
|
-
return sendBadRequestError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
const data = req.query;
|
|
29
|
-
let targets = typeof data.path === 'string'
|
|
30
|
-
? [{ path: data.path, events: ['value'] }]
|
|
31
|
-
: typeof data.for === 'string'
|
|
32
|
-
? JSON.parse(data.for)
|
|
33
|
-
: null;
|
|
34
|
-
if (targets === null) {
|
|
35
|
-
return sendBadRequestError(res, { code: 'invalid_request', message: 'Invalid changes request' });
|
|
36
|
-
}
|
|
37
|
-
if (targets.length === 0) {
|
|
38
|
-
targets.push({ path: '', events: ['value'] });
|
|
39
|
-
}
|
|
40
|
-
// Filter out any requested paths user does not have access to.
|
|
41
|
-
targets = targets.filter(target => {
|
|
42
|
-
let path = target.path;
|
|
43
|
-
if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
|
|
44
|
-
// Only child_ events, check if they have access to children instead
|
|
45
|
-
path = PathInfo.get(path).childPath('*');
|
|
46
|
-
}
|
|
47
|
-
return env.rules.userHasAccess(req.user, path, false).allow;
|
|
48
|
-
});
|
|
49
|
-
if (targets.length === 0) {
|
|
50
|
-
return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const { cursor } = data;
|
|
54
|
-
let timestamp: number;
|
|
55
|
-
if (typeof data.timestamp !== 'undefined') {
|
|
56
|
-
timestamp = parseInt(data.timestamp);
|
|
57
|
-
if (isNaN(timestamp)) {
|
|
58
|
-
return sendBadRequestError(res, { code: 'wrong_timestamp', message: 'Timestamp is not a number' });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const result = await env.db.api.getChanges({ for: targets, cursor, timestamp });
|
|
62
|
-
|
|
63
|
-
res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
|
|
64
|
-
res.contentType('application/json');
|
|
65
|
-
|
|
66
|
-
const serialized = Transport.serialize2(result.changes);
|
|
67
|
-
res.send(serialized as ValueChange[]);
|
|
68
|
-
}
|
|
69
|
-
catch(err) {
|
|
70
|
-
sendError(res, err);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export default addRoute;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { PathInfo, Transport, ValueMutation } from 'acebase-core';
|
|
2
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
3
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
|
|
4
|
-
|
|
5
|
-
export type RequestQuery = {
|
|
6
|
-
path?: string;
|
|
7
|
-
for?: Array<{ path: string, events: string[] }>;
|
|
8
|
-
cursor?: string;
|
|
9
|
-
timestamp?: string;
|
|
10
|
-
};
|
|
11
|
-
export type RequestBody = null;
|
|
12
|
-
export type ResponseBody = ValueMutation[] // 200
|
|
13
|
-
| { code: 'no_transaction_logging', message: string } // 400
|
|
14
|
-
| { code: 'invalid_request', message: string } // 400
|
|
15
|
-
| { code: 'not_authorized', message: string } // 403
|
|
16
|
-
| { code: 'unexpected', message: string }; // 500
|
|
17
|
-
|
|
18
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
19
|
-
|
|
20
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
21
|
-
|
|
22
|
-
env.app.get(`/sync/mutations/${env.db.name}`, async (req: Request, res) => {
|
|
23
|
-
// Gets mutations for specific path(s) and event combinations since given cursor
|
|
24
|
-
if (!env.config.transactions?.log) {
|
|
25
|
-
return sendBadRequestError(res, { code: 'no_transaction_logging', message: 'Transaction logging not enabled' });
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
const data = req.query;
|
|
29
|
-
let targets = typeof data.path === 'string'
|
|
30
|
-
? [{ path: data.path, events: ['value'] }]
|
|
31
|
-
: typeof data.for === 'string'
|
|
32
|
-
? JSON.parse(data.for)
|
|
33
|
-
: null;
|
|
34
|
-
if (targets === null) {
|
|
35
|
-
return sendBadRequestError(res, { code: 'invalid_request', message: 'Invalid mutations request' });
|
|
36
|
-
}
|
|
37
|
-
if (targets.length === 0) {
|
|
38
|
-
targets.push({ path: '', events: ['value'] });
|
|
39
|
-
}
|
|
40
|
-
// Filter out any requested paths user does not have access to.
|
|
41
|
-
targets = targets.filter(target => {
|
|
42
|
-
let path = target.path;
|
|
43
|
-
if (target.events.every(event => /^(?:notify_)?child_/.test(event))) { //if (!target.events.some(event => ['value','notify_value','mutations','mutated'].includes(event))) {
|
|
44
|
-
// Only child_ events, check if they have access to children instead
|
|
45
|
-
path = PathInfo.get(path).childPath('*');
|
|
46
|
-
}
|
|
47
|
-
return env.rules.userHasAccess(req.user, path, false).allow;
|
|
48
|
-
});
|
|
49
|
-
if (targets.length === 0) {
|
|
50
|
-
return sendUnauthorizedError(res, 'not_authorized', 'User is not authorized to access this data');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const { cursor } = data;
|
|
54
|
-
let timestamp: number;
|
|
55
|
-
if (typeof data.timestamp !== 'undefined') {
|
|
56
|
-
timestamp = parseInt(data.timestamp);
|
|
57
|
-
if (isNaN(timestamp)) {
|
|
58
|
-
return sendBadRequestError(res, { code: 'wrong_timestamp', message: 'Timestamp is not a number' });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const result = await env.db.api.getMutations({ for: targets, cursor, timestamp });
|
|
62
|
-
|
|
63
|
-
res.setHeader('AceBase-Context', JSON.stringify({ acebase_cursor: result.new_cursor }));
|
|
64
|
-
res.contentType('application/json');
|
|
65
|
-
|
|
66
|
-
const serialized = Transport.serialize2(result.mutations);
|
|
67
|
-
res.send(serialized as ValueMutation[]);
|
|
68
|
-
}
|
|
69
|
-
catch(err) {
|
|
70
|
-
sendError(res, err);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export default addRoute;
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { SchemaValidationError } from 'acebase';
|
|
2
|
-
import { ID, Transport, Api } from 'acebase-core';
|
|
3
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
4
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
|
|
5
|
-
|
|
6
|
-
export const TRANSACTION_TIMEOUT_MS = 10000; // 10s to finish a started transaction
|
|
7
|
-
|
|
8
|
-
export class DataTransactionError extends Error {
|
|
9
|
-
constructor(public code: 'invalid_serialized_value', message: string) {
|
|
10
|
-
super(message);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type ApiTransactionDetails = {
|
|
15
|
-
id: string;
|
|
16
|
-
value: Transport.SerializedValue;
|
|
17
|
-
};
|
|
18
|
-
export type StartRequestQuery = null;
|
|
19
|
-
export type StartRequestBody = {
|
|
20
|
-
path: string;
|
|
21
|
-
};
|
|
22
|
-
export type StartResponseBody = ApiTransactionDetails // 200
|
|
23
|
-
| { code: string, message: string } // 403
|
|
24
|
-
| { code: 'unexpected', message: string }; // 500
|
|
25
|
-
export type StartRequest = RouteRequest<any, StartResponseBody, StartRequestBody, StartRequestQuery>;
|
|
26
|
-
|
|
27
|
-
export type FinishRequestQuery = null;
|
|
28
|
-
export type FinishRequestBody = ApiTransactionDetails & { path: string };
|
|
29
|
-
export type FinishResponseBody = 'done' // 200
|
|
30
|
-
| { code: string, message: string } // 400, 403
|
|
31
|
-
| 'transaction not found' // 410
|
|
32
|
-
| string // 500
|
|
33
|
-
|
|
34
|
-
export type FinishRequest = RouteRequest<any, FinishResponseBody, FinishRequestBody, FinishRequestQuery>;
|
|
35
|
-
|
|
36
|
-
type Transaction = { id: string; started: number; path: string; context: any; finish?: (val?: any) => ReturnType<Api['transaction']>; timeout: NodeJS.Timeout };
|
|
37
|
-
|
|
38
|
-
export const addRoutes = (env: RouteInitEnvironment) => {
|
|
39
|
-
|
|
40
|
-
const _transactions = new Map<string, Transaction>();
|
|
41
|
-
|
|
42
|
-
// Start transaction endpoint:
|
|
43
|
-
env.app.post(`/transaction/${env.db.name}/start`, (req: StartRequest, res) => {
|
|
44
|
-
const data = req.body;
|
|
45
|
-
|
|
46
|
-
const LOG_ACTION = 'data.transaction.start';
|
|
47
|
-
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path: data.path };
|
|
48
|
-
|
|
49
|
-
const access = env.rules.userHasAccess(req.user, data.path, true);
|
|
50
|
-
if (!access.allow) {
|
|
51
|
-
env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
|
|
52
|
-
return sendUnauthorizedError(res, access.code, access.message);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Start transaction
|
|
56
|
-
const tx: Transaction = {
|
|
57
|
-
id: ID.generate(),
|
|
58
|
-
started: Date.now(),
|
|
59
|
-
path: data.path,
|
|
60
|
-
context: req.context,
|
|
61
|
-
finish: undefined,
|
|
62
|
-
timeout: setTimeout(() => {
|
|
63
|
-
_transactions.delete(tx.id);
|
|
64
|
-
tx.finish(); // Finish without value cancels the transaction
|
|
65
|
-
}, TRANSACTION_TIMEOUT_MS)
|
|
66
|
-
};
|
|
67
|
-
_transactions.set(tx.id, tx);
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
env.debug.verbose(`Transaction ${tx.id} starting...`);
|
|
71
|
-
|
|
72
|
-
// const ref = db.ref(tx.path);
|
|
73
|
-
const donePromise = env.db.api.transaction(tx.path, val => {
|
|
74
|
-
env.debug.verbose(`Transaction ${tx.id} started with value: `, val);
|
|
75
|
-
const currentValue = Transport.serialize(val);
|
|
76
|
-
const promise = new Promise<any>((resolve) => {
|
|
77
|
-
tx.finish = (val: any) => {
|
|
78
|
-
env.debug.verbose(`Transaction ${tx.id} finishing with value: `, val);
|
|
79
|
-
_transactions.delete(tx.id);
|
|
80
|
-
resolve(val);
|
|
81
|
-
return donePromise;
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
res.send({ id: tx.id, value: currentValue });
|
|
85
|
-
return promise;
|
|
86
|
-
}, { context: tx.context });
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
env.debug.error(`failed to start transaction on "${tx.path}":`, err);
|
|
90
|
-
env.log.error(LOG_ACTION, err.code ?? 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
|
|
91
|
-
sendUnexpectedError(res, err);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Finish transaction endpoint:
|
|
96
|
-
env.app.post(`/transaction/${env.db.name}/finish`, async (req: FinishRequest, res) => {
|
|
97
|
-
const data = req.body;
|
|
98
|
-
const LOG_ACTION = 'data.transaction.finish';
|
|
99
|
-
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path: data.path };
|
|
100
|
-
|
|
101
|
-
const tx = _transactions.get(data.id);
|
|
102
|
-
if (!tx || tx.path !== data.path) {
|
|
103
|
-
env.log.error(LOG_ACTION, tx ? 'wrong_path' : 'not_found', { ...LOG_DETAILS, id: data.id, tx_path: tx?.path ?? null });
|
|
104
|
-
res.statusCode = 410; // Gone
|
|
105
|
-
res.send(`transaction not found`);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
clearTimeout(tx.timeout);
|
|
109
|
-
_transactions.delete(tx.id);
|
|
110
|
-
|
|
111
|
-
const access = env.rules.userHasAccess(req.user, tx.path, true);
|
|
112
|
-
if (!access.allow) {
|
|
113
|
-
env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
|
|
114
|
-
return sendUnauthorizedError(res, access.code, access.message);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Finish transaction
|
|
118
|
-
try {
|
|
119
|
-
let cancel = false;
|
|
120
|
-
if (typeof data.value === 'object' && (data.value === null || Object.keys(data.value).length === 0)) {
|
|
121
|
-
// Returning undefined from a transaction callback should cancel the transaction
|
|
122
|
-
// acebase-client (Transport.serialize) serializes value undefined as { val: undefined, map: undefined }, which
|
|
123
|
-
// then is sent to the server as an empty object: {}
|
|
124
|
-
cancel = true;
|
|
125
|
-
}
|
|
126
|
-
else if (typeof data.value?.val === 'undefined' || !['string','object','undefined'].includes(typeof data.value?.map)) {
|
|
127
|
-
throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
128
|
-
}
|
|
129
|
-
const newValue = cancel ? undefined : Transport.deserialize(data.value);
|
|
130
|
-
|
|
131
|
-
if (tx.path === '' && req.user?.uid !== 'admin' && newValue !== null && typeof newValue === 'object') {
|
|
132
|
-
// Non-admin user: remove any private properties from the update object
|
|
133
|
-
Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const result = await tx.finish(newValue);
|
|
138
|
-
|
|
139
|
-
// NEW: capture cursor and return it in the response context header
|
|
140
|
-
if (!tx.context) { tx.context = {}; }
|
|
141
|
-
tx.context.acebase_cursor = result.cursor;
|
|
142
|
-
res.setHeader('AceBase-Context', JSON.stringify(tx.context));
|
|
143
|
-
|
|
144
|
-
res.send('done');
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
tx.finish(); // Finish without value cancels the transaction
|
|
148
|
-
if (err instanceof SchemaValidationError) {
|
|
149
|
-
env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
|
|
150
|
-
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
151
|
-
}
|
|
152
|
-
else if (err instanceof DataTransactionError) {
|
|
153
|
-
env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
|
|
154
|
-
sendBadRequestError(res, err);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
env.debug.error(`failed to finish transaction on "${tx.path}":`, err);
|
|
158
|
-
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
159
|
-
sendError(res, err);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export default addRoutes;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { SchemaValidationError } from 'acebase';
|
|
2
|
-
import { Transport } from 'acebase-core';
|
|
3
|
-
import { RuleValidationFailCode } from '../rules';
|
|
4
|
-
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
5
|
-
import { sendBadRequestError, sendError, sendUnauthorizedError } from '../shared/error';
|
|
6
|
-
|
|
7
|
-
export class UpdateDataError extends Error {
|
|
8
|
-
constructor(public code: 'invalid_serialized_value', message: string) {
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type RequestQuery = null;
|
|
14
|
-
export type RequestBody = Transport.SerializedValue; //{ val: any; map?: string|Record<string, 'date'|'binary'|'reference'|'regexp'|'array'> };
|
|
15
|
-
export type ResponseBody = { success: true } // 200
|
|
16
|
-
| { code: 'invalid_serialized_value', message: string } // 400
|
|
17
|
-
| { code: RuleValidationFailCode, message: string } // 403
|
|
18
|
-
| { code: 'schema_validation_failed', message: string } // 422
|
|
19
|
-
| { code: string, message: string } // 500
|
|
20
|
-
|
|
21
|
-
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
22
|
-
|
|
23
|
-
export const addRoute = (env: RouteInitEnvironment) => {
|
|
24
|
-
|
|
25
|
-
env.app.post(`/data/${env.db.name}/*`, async (req: Request, res) => {
|
|
26
|
-
|
|
27
|
-
const path = req.path.slice(env.db.name.length + 7);
|
|
28
|
-
const LOG_ACTION = 'data.update';
|
|
29
|
-
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path };
|
|
30
|
-
|
|
31
|
-
const access = env.rules.userHasAccess(req.user, path, true);
|
|
32
|
-
if (!access.allow) {
|
|
33
|
-
env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null, rule_error: access.details?.message ?? null });
|
|
34
|
-
return sendUnauthorizedError(res, access.code, access.message);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const data = req.body;
|
|
39
|
-
if (typeof data?.val === 'undefined' || !['string','object','undefined'].includes(typeof data?.map)) {
|
|
40
|
-
throw new UpdateDataError('invalid_serialized_value', 'The sent value is not properly serialized');
|
|
41
|
-
}
|
|
42
|
-
const val = Transport.deserialize(data);
|
|
43
|
-
|
|
44
|
-
if (path === '' && req.user?.uid !== 'admin' && val !== null && typeof val === 'object') {
|
|
45
|
-
// Non-admin user: remove any private properties from the update object
|
|
46
|
-
Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Schema validation moved to storage, no need to check here but an early check won't do no harm!
|
|
50
|
-
const validation = await env.db.schema.check(path, val, true);
|
|
51
|
-
if (!validation.ok) {
|
|
52
|
-
throw new SchemaValidationError(validation.reason);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
await env.db.ref(path)
|
|
56
|
-
.context(req.context)
|
|
57
|
-
.update(val);
|
|
58
|
-
|
|
59
|
-
// NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
|
|
60
|
-
const returnContext = { acebase_cursor: req.context.acebase_cursor };
|
|
61
|
-
res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
|
|
62
|
-
|
|
63
|
-
res.send({ success: true });
|
|
64
|
-
}
|
|
65
|
-
catch(err) {
|
|
66
|
-
if (err instanceof SchemaValidationError) {
|
|
67
|
-
env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
|
|
68
|
-
res.status(422).send({ code: 'schema_validation_failed', message: err.message });
|
|
69
|
-
}
|
|
70
|
-
else if (err instanceof UpdateDataError) {
|
|
71
|
-
env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
|
|
72
|
-
sendBadRequestError(res, err);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
env.debug.error(`failed to update "${path}":`, err);
|
|
76
|
-
env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
|
|
77
|
-
sendError(res, err);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export default addRoute;
|
package/src/routes/data.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { RouteInitEnvironment } from "../shared/env";
|
|
2
|
-
import addContextMiddleware from "../middleware/context";
|
|
3
|
-
import addGetDataRoute from './data-get';
|
|
4
|
-
import addUpdateDataRoute from './data-update';
|
|
5
|
-
import addSetDataRoute from './data-set';
|
|
6
|
-
import addTransactionRoutes from './data-transaction';
|
|
7
|
-
import addExistsRoute from './data-exists';
|
|
8
|
-
import addReflectRoute from './data-reflect';
|
|
9
|
-
import addImportDataRoute from './data-import';
|
|
10
|
-
import addExportDataRoute from './data-export';
|
|
11
|
-
import addQueryRoute from './data-query';
|
|
12
|
-
|
|
13
|
-
// Indexes:
|
|
14
|
-
import addListIndexesRoute from './data-index-list';
|
|
15
|
-
import addCreateIndexRoute from './data-index-create';
|
|
16
|
-
import addDeleteIndexRoute from './data-index-delete';
|
|
17
|
-
|
|
18
|
-
// Schemas:
|
|
19
|
-
import addListSchemasRoute from './data-schemas-list';
|
|
20
|
-
import addGetSchemaRoute from './data-schema-get';
|
|
21
|
-
import addSetSchemaRoute from './data-schema-set';
|
|
22
|
-
import addTestSchemaRoute from './data-schema-test';
|
|
23
|
-
|
|
24
|
-
// Sycnronization:
|
|
25
|
-
import addSyncMutationsRoute from './data-sync-mutations';
|
|
26
|
-
import addSyncChangesRoute from './data-sync-changes';
|
|
27
|
-
|
|
28
|
-
export const addRoutes = (env: RouteInitEnvironment) => {
|
|
29
|
-
|
|
30
|
-
// Add context middleware that handles AceBase-Context header
|
|
31
|
-
addContextMiddleware(env);
|
|
32
|
-
|
|
33
|
-
// Add get data endpoint
|
|
34
|
-
addGetDataRoute(env);
|
|
35
|
-
|
|
36
|
-
// Add update data endpoint
|
|
37
|
-
addUpdateDataRoute(env);
|
|
38
|
-
|
|
39
|
-
// Add set data endpoint
|
|
40
|
-
addSetDataRoute(env);
|
|
41
|
-
|
|
42
|
-
// add transaction routes (start & finish)
|
|
43
|
-
addTransactionRoutes(env);
|
|
44
|
-
|
|
45
|
-
// Add exists endpoint
|
|
46
|
-
addExistsRoute(env);
|
|
47
|
-
|
|
48
|
-
// Add reflect endpoint
|
|
49
|
-
addReflectRoute(env);
|
|
50
|
-
|
|
51
|
-
// Add import endpoint
|
|
52
|
-
addImportDataRoute(env);
|
|
53
|
-
|
|
54
|
-
// Add export endpoint
|
|
55
|
-
addExportDataRoute(env);
|
|
56
|
-
|
|
57
|
-
// Add query endpoint
|
|
58
|
-
addQueryRoute(env);
|
|
59
|
-
|
|
60
|
-
// Add index endpoints:
|
|
61
|
-
addListIndexesRoute(env); // list indexes
|
|
62
|
-
addCreateIndexRoute(env); // create index
|
|
63
|
-
addDeleteIndexRoute(env); // delete index
|
|
64
|
-
|
|
65
|
-
// Add schema endpoints:
|
|
66
|
-
addListSchemasRoute(env); // list all
|
|
67
|
-
addGetSchemaRoute(env); // get schema
|
|
68
|
-
addSetSchemaRoute(env); // set schema
|
|
69
|
-
addTestSchemaRoute(env); // test
|
|
70
|
-
|
|
71
|
-
// Add sync mutations endpoint
|
|
72
|
-
addSyncMutationsRoute(env);
|
|
73
|
-
|
|
74
|
-
// add sync changes endpoint
|
|
75
|
-
addSyncChangesRoute(env);
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export default addRoutes;
|