acebase-server 1.13.2 → 1.14.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/create-package-files +25 -0
- package/dist/cjs/auth.js.map +1 -0
- package/dist/cjs/cluster.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/logger.js.map +1 -0
- package/dist/cjs/middleware/404.js.map +1 -0
- package/dist/cjs/middleware/admin-only.js.map +1 -0
- package/dist/cjs/middleware/cache.js.map +1 -0
- package/dist/cjs/middleware/connection.js.map +1 -0
- package/dist/cjs/middleware/context.js.map +1 -0
- package/dist/cjs/middleware/cors.js.map +1 -0
- package/dist/cjs/middleware/swagger.js.map +1 -0
- package/dist/cjs/middleware/user.js.map +1 -0
- package/dist/cjs/oauth-providers/dropbox.js.map +1 -0
- package/dist/cjs/oauth-providers/facebook.js.map +1 -0
- package/dist/cjs/oauth-providers/google.js.map +1 -0
- package/dist/cjs/oauth-providers/index.js.map +1 -0
- package/dist/cjs/oauth-providers/instagram.js.map +1 -0
- package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -0
- package/dist/cjs/oauth-providers/spotify.js.map +1 -0
- package/dist/cjs/routes/auth-change-password.js.map +1 -0
- package/dist/cjs/routes/auth-delete.js.map +1 -0
- package/dist/cjs/routes/auth-forgot-password.js.map +1 -0
- package/dist/cjs/routes/auth-reset-password.js.map +1 -0
- package/dist/cjs/routes/auth-signin.js.map +1 -0
- package/dist/cjs/routes/auth-signout.js.map +1 -0
- package/dist/cjs/routes/auth-signup.js.map +1 -0
- package/dist/cjs/routes/auth-state.js.map +1 -0
- package/dist/cjs/routes/auth-update.js.map +1 -0
- package/dist/cjs/routes/auth-verify-email.js.map +1 -0
- package/dist/cjs/routes/auth.js.map +1 -0
- package/dist/cjs/routes/data-exists.js.map +1 -0
- package/dist/cjs/routes/data-export.js.map +1 -0
- package/dist/cjs/routes/data-get.js.map +1 -0
- package/dist/cjs/routes/data-import.js.map +1 -0
- package/dist/cjs/routes/data-index-create.js.map +1 -0
- package/dist/cjs/routes/data-index-delete.js.map +1 -0
- package/dist/cjs/routes/data-index-list.js.map +1 -0
- package/dist/cjs/routes/data-query.js.map +1 -0
- package/dist/cjs/routes/data-reflect.js.map +1 -0
- package/dist/cjs/routes/data-schema-get.js.map +1 -0
- package/dist/cjs/routes/data-schema-set.js.map +1 -0
- package/dist/cjs/routes/data-schema-test.js.map +1 -0
- package/dist/cjs/routes/data-schemas-list.js.map +1 -0
- package/dist/cjs/routes/data-set.js.map +1 -0
- package/dist/cjs/routes/data-sync-changes.js.map +1 -0
- package/dist/cjs/routes/data-sync-mutations.js.map +1 -0
- package/dist/cjs/routes/data-transaction.js.map +1 -0
- package/dist/cjs/routes/data-update.js.map +1 -0
- package/dist/cjs/routes/data.js.map +1 -0
- package/dist/cjs/routes/docs.js.map +1 -0
- package/dist/cjs/routes/meta-info.js.map +1 -0
- package/dist/cjs/routes/meta-logs.js.map +1 -0
- package/dist/cjs/routes/meta-ping.js.map +1 -0
- package/dist/cjs/routes/meta-stats.js.map +1 -0
- package/dist/cjs/routes/meta.js.map +1 -0
- package/dist/cjs/routes/oauth2-init.js.map +1 -0
- package/dist/cjs/routes/oauth2-refresh.js.map +1 -0
- package/dist/cjs/routes/oauth2-signin.js.map +1 -0
- package/dist/cjs/routes/webmanager.js.map +1 -0
- package/dist/cjs/rules.js +2 -9
- package/dist/cjs/rules.js.map +1 -0
- package/dist/cjs/schema/user.js.map +1 -0
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/settings/email.js.map +1 -0
- package/dist/cjs/settings/index.js +1 -1
- package/dist/cjs/settings/index.js.map +1 -0
- package/dist/cjs/shared/clients.js.map +1 -0
- package/dist/cjs/shared/email.js.map +1 -0
- package/dist/cjs/shared/env.js.map +1 -0
- package/dist/cjs/shared/error.js.map +1 -0
- package/dist/cjs/shared/http.js.map +1 -0
- package/dist/cjs/shared/password.js.map +1 -0
- package/dist/cjs/shared/rootpath.js.map +1 -0
- package/dist/cjs/shared/signin.js.map +1 -0
- package/dist/cjs/shared/simple-fetch.js.map +1 -0
- package/dist/cjs/shared/tokens.js.map +1 -0
- package/dist/cjs/shared/validate.js.map +1 -0
- package/dist/cjs/start.js.map +1 -0
- package/dist/cjs/test.js.map +1 -0
- package/dist/cjs/websocket/index.js.map +1 -0
- package/dist/cjs/websocket/manager.js +1 -1
- package/dist/cjs/websocket/manager.js.map +1 -0
- package/dist/cjs/websocket/socket.io.js.map +1 -0
- package/dist/esm/auth.js.map +1 -0
- package/dist/esm/cluster.js.map +1 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/middleware/404.js.map +1 -0
- package/dist/esm/middleware/admin-only.js.map +1 -0
- package/dist/esm/middleware/cache.js.map +1 -0
- package/dist/esm/middleware/connection.js.map +1 -0
- package/dist/esm/middleware/context.js.map +1 -0
- package/dist/esm/middleware/cors.js.map +1 -0
- package/dist/esm/middleware/swagger.js.map +1 -0
- package/dist/esm/middleware/user.js.map +1 -0
- package/dist/esm/oauth-providers/dropbox.js.map +1 -0
- package/dist/esm/oauth-providers/facebook.js.map +1 -0
- package/dist/esm/oauth-providers/google.js.map +1 -0
- package/dist/esm/oauth-providers/index.js.map +1 -0
- package/dist/esm/oauth-providers/instagram.js.map +1 -0
- package/dist/esm/oauth-providers/oauth-provider.js.map +1 -0
- package/dist/esm/oauth-providers/spotify.js.map +1 -0
- package/dist/esm/routes/auth-change-password.js.map +1 -0
- package/dist/esm/routes/auth-delete.js.map +1 -0
- package/dist/esm/routes/auth-forgot-password.js.map +1 -0
- package/dist/esm/routes/auth-reset-password.js.map +1 -0
- package/dist/esm/routes/auth-signin.js.map +1 -0
- package/dist/esm/routes/auth-signout.js.map +1 -0
- package/dist/esm/routes/auth-signup.js.map +1 -0
- package/dist/esm/routes/auth-state.js.map +1 -0
- package/dist/esm/routes/auth-update.js.map +1 -0
- package/dist/esm/routes/auth-verify-email.js.map +1 -0
- package/dist/esm/routes/auth.js.map +1 -0
- package/dist/esm/routes/data-exists.js.map +1 -0
- package/dist/esm/routes/data-export.js.map +1 -0
- package/dist/esm/routes/data-get.js.map +1 -0
- package/dist/esm/routes/data-import.js.map +1 -0
- package/dist/esm/routes/data-index-create.js.map +1 -0
- package/dist/esm/routes/data-index-delete.js.map +1 -0
- package/dist/esm/routes/data-index-list.js.map +1 -0
- package/dist/esm/routes/data-query.js.map +1 -0
- package/dist/esm/routes/data-reflect.js.map +1 -0
- package/dist/esm/routes/data-schema-get.js.map +1 -0
- package/dist/esm/routes/data-schema-set.js.map +1 -0
- package/dist/esm/routes/data-schema-test.js.map +1 -0
- package/dist/esm/routes/data-schemas-list.js.map +1 -0
- package/dist/esm/routes/data-set.js.map +1 -0
- package/dist/esm/routes/data-sync-changes.js.map +1 -0
- package/dist/esm/routes/data-sync-mutations.js.map +1 -0
- package/dist/esm/routes/data-transaction.js.map +1 -0
- package/dist/esm/routes/data-update.js.map +1 -0
- package/dist/esm/routes/data.js.map +1 -0
- package/dist/esm/routes/docs.js.map +1 -0
- package/dist/esm/routes/meta-info.js.map +1 -0
- package/dist/esm/routes/meta-logs.js.map +1 -0
- package/dist/esm/routes/meta-ping.js.map +1 -0
- package/dist/esm/routes/meta-stats.js.map +1 -0
- package/dist/esm/routes/meta.js.map +1 -0
- package/dist/esm/routes/oauth2-init.js.map +1 -0
- package/dist/esm/routes/oauth2-refresh.js.map +1 -0
- package/dist/esm/routes/oauth2-signin.js.map +1 -0
- package/dist/esm/routes/webmanager.js.map +1 -0
- package/dist/esm/rules.js +2 -9
- package/dist/esm/rules.js.map +1 -0
- package/dist/esm/schema/user.js.map +1 -0
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -0
- package/dist/esm/settings/email.js.map +1 -0
- package/dist/esm/settings/index.js +1 -1
- package/dist/esm/settings/index.js.map +1 -0
- package/dist/esm/shared/clients.js.map +1 -0
- package/dist/esm/shared/email.js.map +1 -0
- package/dist/esm/shared/env.js.map +1 -0
- package/dist/esm/shared/error.js.map +1 -0
- package/dist/esm/shared/http.js.map +1 -0
- package/dist/esm/shared/password.js.map +1 -0
- package/dist/esm/shared/rootpath.js.map +1 -0
- package/dist/esm/shared/signin.js.map +1 -0
- package/dist/esm/shared/simple-fetch.js.map +1 -0
- package/dist/esm/shared/tokens.js.map +1 -0
- package/dist/esm/shared/validate.js.map +1 -0
- package/dist/esm/start.js.map +1 -0
- package/dist/esm/test.js.map +1 -0
- package/dist/esm/websocket/index.js.map +1 -0
- package/dist/esm/websocket/manager.js +1 -1
- package/dist/esm/websocket/manager.js.map +1 -0
- package/dist/esm/websocket/socket.io.js.map +1 -0
- package/dist/types/auth.d.ts +1 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/cluster.d.ts +1 -0
- package/dist/types/cluster.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/middleware/404.d.ts +1 -0
- package/dist/types/middleware/404.d.ts.map +1 -0
- package/dist/types/middleware/admin-only.d.ts +1 -0
- package/dist/types/middleware/admin-only.d.ts.map +1 -0
- package/dist/types/middleware/cache.d.ts +1 -0
- package/dist/types/middleware/cache.d.ts.map +1 -0
- package/dist/types/middleware/connection.d.ts +1 -0
- package/dist/types/middleware/connection.d.ts.map +1 -0
- package/dist/types/middleware/context.d.ts +1 -0
- package/dist/types/middleware/context.d.ts.map +1 -0
- package/dist/types/middleware/cors.d.ts +1 -0
- package/dist/types/middleware/cors.d.ts.map +1 -0
- package/dist/types/middleware/swagger.d.ts +1 -0
- package/dist/types/middleware/swagger.d.ts.map +1 -0
- package/dist/types/middleware/user.d.ts +1 -0
- package/dist/types/middleware/user.d.ts.map +1 -0
- package/dist/types/oauth-providers/dropbox.d.ts +1 -0
- package/dist/types/oauth-providers/dropbox.d.ts.map +1 -0
- package/dist/types/oauth-providers/facebook.d.ts +1 -0
- package/dist/types/oauth-providers/facebook.d.ts.map +1 -0
- package/dist/types/oauth-providers/google.d.ts +1 -0
- package/dist/types/oauth-providers/google.d.ts.map +1 -0
- package/dist/types/oauth-providers/index.d.ts +1 -0
- package/dist/types/oauth-providers/index.d.ts.map +1 -0
- package/dist/types/oauth-providers/instagram.d.ts +1 -0
- package/dist/types/oauth-providers/instagram.d.ts.map +1 -0
- package/dist/types/oauth-providers/oauth-provider.d.ts +1 -0
- package/dist/types/oauth-providers/oauth-provider.d.ts.map +1 -0
- package/dist/types/oauth-providers/spotify.d.ts +1 -0
- package/dist/types/oauth-providers/spotify.d.ts.map +1 -0
- package/dist/types/routes/auth-change-password.d.ts +1 -0
- package/dist/types/routes/auth-change-password.d.ts.map +1 -0
- package/dist/types/routes/auth-delete.d.ts +1 -0
- package/dist/types/routes/auth-delete.d.ts.map +1 -0
- package/dist/types/routes/auth-forgot-password.d.ts +1 -0
- package/dist/types/routes/auth-forgot-password.d.ts.map +1 -0
- package/dist/types/routes/auth-reset-password.d.ts +1 -0
- package/dist/types/routes/auth-reset-password.d.ts.map +1 -0
- package/dist/types/routes/auth-signin.d.ts +1 -0
- package/dist/types/routes/auth-signin.d.ts.map +1 -0
- package/dist/types/routes/auth-signout.d.ts +1 -0
- package/dist/types/routes/auth-signout.d.ts.map +1 -0
- package/dist/types/routes/auth-signup.d.ts +1 -0
- package/dist/types/routes/auth-signup.d.ts.map +1 -0
- package/dist/types/routes/auth-state.d.ts +1 -0
- package/dist/types/routes/auth-state.d.ts.map +1 -0
- package/dist/types/routes/auth-update.d.ts +1 -0
- package/dist/types/routes/auth-update.d.ts.map +1 -0
- package/dist/types/routes/auth-verify-email.d.ts +1 -0
- package/dist/types/routes/auth-verify-email.d.ts.map +1 -0
- package/dist/types/routes/auth.d.ts +1 -0
- package/dist/types/routes/auth.d.ts.map +1 -0
- package/dist/types/routes/data-exists.d.ts +1 -0
- package/dist/types/routes/data-exists.d.ts.map +1 -0
- package/dist/types/routes/data-export.d.ts +1 -0
- package/dist/types/routes/data-export.d.ts.map +1 -0
- package/dist/types/routes/data-get.d.ts +3 -2
- package/dist/types/routes/data-get.d.ts.map +1 -0
- package/dist/types/routes/data-import.d.ts +1 -0
- package/dist/types/routes/data-import.d.ts.map +1 -0
- package/dist/types/routes/data-index-create.d.ts +1 -0
- package/dist/types/routes/data-index-create.d.ts.map +1 -0
- package/dist/types/routes/data-index-delete.d.ts +1 -0
- package/dist/types/routes/data-index-delete.d.ts.map +1 -0
- package/dist/types/routes/data-index-list.d.ts +1 -0
- package/dist/types/routes/data-index-list.d.ts.map +1 -0
- package/dist/types/routes/data-query.d.ts +1 -0
- package/dist/types/routes/data-query.d.ts.map +1 -0
- package/dist/types/routes/data-reflect.d.ts +1 -0
- package/dist/types/routes/data-reflect.d.ts.map +1 -0
- package/dist/types/routes/data-schema-get.d.ts +1 -0
- package/dist/types/routes/data-schema-get.d.ts.map +1 -0
- package/dist/types/routes/data-schema-set.d.ts +2 -1
- package/dist/types/routes/data-schema-set.d.ts.map +1 -0
- package/dist/types/routes/data-schema-test.d.ts +3 -4
- package/dist/types/routes/data-schema-test.d.ts.map +1 -0
- package/dist/types/routes/data-schemas-list.d.ts +1 -0
- package/dist/types/routes/data-schemas-list.d.ts.map +1 -0
- package/dist/types/routes/data-set.d.ts +3 -2
- package/dist/types/routes/data-set.d.ts.map +1 -0
- package/dist/types/routes/data-sync-changes.d.ts +2 -1
- package/dist/types/routes/data-sync-changes.d.ts.map +1 -0
- package/dist/types/routes/data-sync-mutations.d.ts +2 -1
- package/dist/types/routes/data-sync-mutations.d.ts.map +1 -0
- package/dist/types/routes/data-transaction.d.ts +3 -2
- package/dist/types/routes/data-transaction.d.ts.map +1 -0
- package/dist/types/routes/data-update.d.ts +3 -2
- package/dist/types/routes/data-update.d.ts.map +1 -0
- package/dist/types/routes/data.d.ts +1 -0
- package/dist/types/routes/data.d.ts.map +1 -0
- package/dist/types/routes/docs.d.ts +1 -0
- package/dist/types/routes/docs.d.ts.map +1 -0
- package/dist/types/routes/meta-info.d.ts +1 -0
- package/dist/types/routes/meta-info.d.ts.map +1 -0
- package/dist/types/routes/meta-logs.d.ts +2 -1
- package/dist/types/routes/meta-logs.d.ts.map +1 -0
- package/dist/types/routes/meta-ping.d.ts +1 -0
- package/dist/types/routes/meta-ping.d.ts.map +1 -0
- package/dist/types/routes/meta-stats.d.ts +1 -0
- package/dist/types/routes/meta-stats.d.ts.map +1 -0
- package/dist/types/routes/meta.d.ts +1 -0
- package/dist/types/routes/meta.d.ts.map +1 -0
- package/dist/types/routes/oauth2-init.d.ts +1 -0
- package/dist/types/routes/oauth2-init.d.ts.map +1 -0
- package/dist/types/routes/oauth2-refresh.d.ts +1 -0
- package/dist/types/routes/oauth2-refresh.d.ts.map +1 -0
- package/dist/types/routes/oauth2-signin.d.ts +1 -0
- package/dist/types/routes/oauth2-signin.d.ts.map +1 -0
- package/dist/types/routes/webmanager.d.ts +1 -0
- package/dist/types/routes/webmanager.d.ts.map +1 -0
- package/dist/types/rules.d.ts +1 -7
- package/dist/types/rules.d.ts.map +1 -0
- package/dist/types/schema/user.d.ts +1 -0
- package/dist/types/schema/user.d.ts.map +1 -0
- package/dist/types/server.d.ts +1 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/settings/email.d.ts +1 -0
- package/dist/types/settings/email.d.ts.map +1 -0
- package/dist/types/settings/index.d.ts +2 -1
- package/dist/types/settings/index.d.ts.map +1 -0
- package/dist/types/shared/clients.d.ts +4 -3
- package/dist/types/shared/clients.d.ts.map +1 -0
- package/dist/types/shared/email.d.ts +1 -0
- package/dist/types/shared/email.d.ts.map +1 -0
- package/dist/types/shared/env.d.ts +2 -2
- package/dist/types/shared/env.d.ts.map +1 -0
- package/dist/types/shared/error.d.ts +1 -0
- package/dist/types/shared/error.d.ts.map +1 -0
- package/dist/types/shared/http.d.ts +1 -0
- package/dist/types/shared/http.d.ts.map +1 -0
- package/dist/types/shared/password.d.ts +1 -0
- package/dist/types/shared/password.d.ts.map +1 -0
- package/dist/types/shared/rootpath.d.ts +1 -0
- package/dist/types/shared/rootpath.d.ts.map +1 -0
- package/dist/types/shared/signin.d.ts +1 -0
- package/dist/types/shared/signin.d.ts.map +1 -0
- package/dist/types/shared/simple-fetch.d.ts +1 -0
- package/dist/types/shared/simple-fetch.d.ts.map +1 -0
- package/dist/types/shared/tokens.d.ts +1 -0
- package/dist/types/shared/tokens.d.ts.map +1 -0
- package/dist/types/shared/validate.d.ts +1 -0
- package/dist/types/shared/validate.d.ts.map +1 -0
- package/dist/types/start.d.ts +1 -0
- package/dist/types/start.d.ts.map +1 -0
- package/dist/types/test.d.ts +1 -0
- package/dist/types/test.d.ts.map +1 -0
- package/dist/types/websocket/index.d.ts +1 -0
- package/dist/types/websocket/index.d.ts.map +1 -0
- package/dist/types/websocket/manager.d.ts +11 -10
- package/dist/types/websocket/manager.d.ts.map +1 -0
- package/dist/types/websocket/socket.io.d.ts +1 -0
- package/dist/types/websocket/socket.io.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/auth.ts +87 -0
- package/src/cluster.ts +62 -0
- package/src/index.ts +4 -0
- package/src/logger.ts +56 -0
- package/src/middleware/404.ts +13 -0
- package/src/middleware/admin-only.ts +29 -0
- package/src/middleware/cache.ts +15 -0
- package/src/middleware/connection.ts +48 -0
- package/src/middleware/context.ts +23 -0
- package/src/middleware/cors.ts +49 -0
- package/src/middleware/swagger.ts +19 -0
- package/src/middleware/user.ts +51 -0
- package/src/oauth-providers/dropbox.ts +144 -0
- package/src/oauth-providers/facebook.ts +103 -0
- package/src/oauth-providers/google.ts +147 -0
- package/src/oauth-providers/index.ts +21 -0
- package/src/oauth-providers/instagram.ts +98 -0
- package/src/oauth-providers/oauth-provider.ts +65 -0
- package/src/oauth-providers/spotify.ts +127 -0
- package/src/placeholder.d.ts +12 -0
- package/src/routes/auth-change-password.ts +92 -0
- package/src/routes/auth-change-password.yaml +74 -0
- package/src/routes/auth-delete.ts +49 -0
- package/src/routes/auth-delete.yaml +78 -0
- package/src/routes/auth-forgot-password.ts +77 -0
- package/src/routes/auth-forgot-password.yaml +50 -0
- package/src/routes/auth-reset-password.ts +96 -0
- package/src/routes/auth-reset-password.yaml +54 -0
- package/src/routes/auth-signin.ts +55 -0
- package/src/routes/auth-signin.yaml +130 -0
- package/src/routes/auth-signout.ts +64 -0
- package/src/routes/auth-signout.yaml +46 -0
- package/src/routes/auth-signup.ts +164 -0
- package/src/routes/auth-signup.yaml +136 -0
- package/src/routes/auth-state.ts +20 -0
- package/src/routes/auth-state.yaml +29 -0
- package/src/routes/auth-update.ts +149 -0
- package/src/routes/auth-update.yaml +152 -0
- package/src/routes/auth-verify-email.ts +75 -0
- package/src/routes/auth-verify-email.yaml +53 -0
- package/src/routes/auth.ts +67 -0
- package/src/routes/data-exists.ts +31 -0
- package/src/routes/data-exists.yaml +44 -0
- package/src/routes/data-export.ts +51 -0
- package/src/routes/data-export.yaml +64 -0
- package/src/routes/data-get.ts +67 -0
- package/src/routes/data-get.yaml +54 -0
- package/src/routes/data-import.ts +56 -0
- package/src/routes/data-import.yaml +75 -0
- package/src/routes/data-index-create.ts +82 -0
- package/src/routes/data-index-create.yaml +105 -0
- package/src/routes/data-index-delete.ts +36 -0
- package/src/routes/data-index-delete.yaml +51 -0
- package/src/routes/data-index-list.ts +39 -0
- package/src/routes/data-index-list.yaml +84 -0
- package/src/routes/data-query.ts +97 -0
- package/src/routes/data-query.yaml +166 -0
- package/src/routes/data-reflect.ts +91 -0
- package/src/routes/data-reflect.yaml +124 -0
- package/src/routes/data-schema-get.ts +36 -0
- package/src/routes/data-schema-get.yaml +53 -0
- package/src/routes/data-schema-set.ts +35 -0
- package/src/routes/data-schema-set.yaml +60 -0
- package/src/routes/data-schema-test.ts +48 -0
- package/src/routes/data-schema-test.yaml +66 -0
- package/src/routes/data-schemas-list.ts +31 -0
- package/src/routes/data-schemas-list.yaml +41 -0
- package/src/routes/data-set.ts +83 -0
- package/src/routes/data-set.yaml +77 -0
- package/src/routes/data-sync-changes.ts +77 -0
- package/src/routes/data-sync-changes.yaml +67 -0
- package/src/routes/data-sync-mutations.ts +77 -0
- package/src/routes/data-sync-mutations.yaml +67 -0
- package/src/routes/data-transaction-finish.yaml +82 -0
- package/src/routes/data-transaction-start.yaml +58 -0
- package/src/routes/data-transaction.ts +166 -0
- package/src/routes/data-update.ts +84 -0
- package/src/routes/data-update.yaml +77 -0
- package/src/routes/data.ts +79 -0
- package/src/routes/docs.ts +249 -0
- package/src/routes/meta-info.ts +80 -0
- package/src/routes/meta-info.yaml +41 -0
- package/src/routes/meta-logs.ts +57 -0
- package/src/routes/meta-ping.ts +15 -0
- package/src/routes/meta-ping.yaml +23 -0
- package/src/routes/meta-stats.ts +31 -0
- package/src/routes/meta-stats.yaml +41 -0
- package/src/routes/meta.ts +22 -0
- package/src/routes/oauth2-init.ts +44 -0
- package/src/routes/oauth2-init.yaml +63 -0
- package/src/routes/oauth2-refresh.ts +39 -0
- package/src/routes/oauth2-refresh.yaml +65 -0
- package/src/routes/oauth2-signin.ts +286 -0
- package/src/routes/oauth2-signin.yaml +66 -0
- package/src/routes/webmanager.ts +29 -0
- package/src/rules.ts +189 -0
- package/src/schema/user.ts +99 -0
- package/src/server.ts +419 -0
- package/src/settings/email.ts +18 -0
- package/src/settings/index.ts +241 -0
- package/src/shared/clients.ts +31 -0
- package/src/shared/email.ts +33 -0
- package/src/shared/env.ts +38 -0
- package/src/shared/error.ts +37 -0
- package/src/shared/http.ts +26 -0
- package/src/shared/password.ts +41 -0
- package/src/shared/rootpath.ts +17 -0
- package/src/shared/signin.ts +149 -0
- package/src/shared/simple-fetch.ts +65 -0
- package/src/shared/tokens.ts +77 -0
- package/src/shared/validate.ts +53 -0
- package/src/start.ts +48 -0
- package/src/test.ts +10 -0
- package/src/websocket/index.ts +336 -0
- package/src/websocket/manager.ts +46 -0
- package/src/websocket/socket.io.ts +90 -0
- package/tsconfig-cjs.json +11 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { DbUserAccountDetails } from '../schema/user';
|
|
3
|
+
import { parseSignedPublicToken } from '../shared/tokens';
|
|
4
|
+
import { sendBadRequestError, sendUnexpectedError } from '../shared/error';
|
|
5
|
+
import { createPasswordHash } from '../shared/password';
|
|
6
|
+
import { AceBaseUserResetPasswordSuccessEmailRequest } from '../shared/email';
|
|
7
|
+
|
|
8
|
+
export class ResetPasswordError extends Error {
|
|
9
|
+
constructor(public code: 'invalid_code'|'unknown_user'|'password_requirement_mismatch', message: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type RequestQuery = {};
|
|
15
|
+
export type RequestBody = { code: string; password: string };
|
|
16
|
+
export type ResponseBody = 'OK' | { code: string; message: string };
|
|
17
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Adds the reset_password route and returns the reset function that can be used to manually reset a password
|
|
21
|
+
* @param env environment
|
|
22
|
+
* @returns returns the reset function
|
|
23
|
+
*/
|
|
24
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
25
|
+
|
|
26
|
+
const resetPassword = async (clientIp: string, code: string, newPassword: string) => {
|
|
27
|
+
try {
|
|
28
|
+
var verification = parseSignedPublicToken(code, env.tokenSalt);
|
|
29
|
+
}
|
|
30
|
+
catch(err) {
|
|
31
|
+
throw new ResetPasswordError('invalid_code', err.message);
|
|
32
|
+
}
|
|
33
|
+
const snap = await env.authRef.child(verification.uid).get();
|
|
34
|
+
if (!snap.exists()) {
|
|
35
|
+
throw new ResetPasswordError('unknown_user', 'Uknown user');
|
|
36
|
+
}
|
|
37
|
+
const user: DbUserAccountDetails = snap.val();
|
|
38
|
+
user.uid = snap.key as string;
|
|
39
|
+
|
|
40
|
+
if (user.password_reset_code !== verification.code) {
|
|
41
|
+
throw new ResetPasswordError('invalid_code', 'Invalid code');
|
|
42
|
+
}
|
|
43
|
+
if (newPassword.length < 8 || newPassword.includes(' ')) {
|
|
44
|
+
throw new ResetPasswordError('password_requirement_mismatch', 'Password must be at least 8 characters, and cannot contain spaces');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Ok to change password
|
|
48
|
+
const pwd = createPasswordHash(newPassword);
|
|
49
|
+
await snap.ref.update({
|
|
50
|
+
password: pwd.hash,
|
|
51
|
+
password_salt: pwd.salt,
|
|
52
|
+
password_reset_code: null
|
|
53
|
+
})
|
|
54
|
+
// Send confirmation email
|
|
55
|
+
const request: AceBaseUserResetPasswordSuccessEmailRequest = {
|
|
56
|
+
type: 'user_reset_password_success',
|
|
57
|
+
date: new Date(),
|
|
58
|
+
ip: clientIp,
|
|
59
|
+
user: {
|
|
60
|
+
uid: user.uid,
|
|
61
|
+
email: user.email,
|
|
62
|
+
username: user.username,
|
|
63
|
+
displayName: user.display_name,
|
|
64
|
+
settings: user.settings
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
env.config.email?.send(request);
|
|
68
|
+
return user;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
env.app.post(`/auth/${env.db.name}/reset_password`, async (req: Request, res) => {
|
|
72
|
+
|
|
73
|
+
const details = req.body;
|
|
74
|
+
const LOG_ACTION = 'auth.reset_password';
|
|
75
|
+
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null };
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const user = await resetPassword(req.ip, details.code, details.password);
|
|
79
|
+
env.log.event(LOG_ACTION, { ...LOG_DETAILS, reset_uid: user.uid });
|
|
80
|
+
res.send('OK');
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
env.log.error(LOG_ACTION, err.code ?? 'unexpected', { ...LOG_DETAILS, message: (err instanceof Error && err.message) ?? err.toString() });
|
|
84
|
+
if (err.code) {
|
|
85
|
+
sendBadRequestError(res, err);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
sendUnexpectedError(res, err);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return resetPassword;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default addRoute;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/auth/{dbname}/reset_password:
|
|
2
|
+
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Completes a password reset
|
|
6
|
+
description: Completes a password reset request for a user account with a code sent to the email address by the `forgot_password` endpoint
|
|
7
|
+
parameters:
|
|
8
|
+
- name: dbname
|
|
9
|
+
in: path
|
|
10
|
+
description: name of the database
|
|
11
|
+
required: true
|
|
12
|
+
schema:
|
|
13
|
+
type: string
|
|
14
|
+
example: mydb
|
|
15
|
+
requestBody:
|
|
16
|
+
description: verification object
|
|
17
|
+
content:
|
|
18
|
+
'application/json':
|
|
19
|
+
schema:
|
|
20
|
+
type: object
|
|
21
|
+
properties:
|
|
22
|
+
code:
|
|
23
|
+
type: string
|
|
24
|
+
description: Password reset code that was sent to the user's email address
|
|
25
|
+
password:
|
|
26
|
+
type: string
|
|
27
|
+
description: New password to set on the account
|
|
28
|
+
required:
|
|
29
|
+
- code
|
|
30
|
+
- password
|
|
31
|
+
responses:
|
|
32
|
+
200:
|
|
33
|
+
description: If the password reset is successful, returns the string `"OK"`
|
|
34
|
+
content:
|
|
35
|
+
'text/plain':
|
|
36
|
+
schema:
|
|
37
|
+
type: 'string'
|
|
38
|
+
value: OK
|
|
39
|
+
description: The string `"OK"`
|
|
40
|
+
400:
|
|
41
|
+
description: Returns a `"401 Bad Request"` if the code sent with the request is invalid, or the new password doesn't meet the requirements
|
|
42
|
+
content:
|
|
43
|
+
'application/json':
|
|
44
|
+
schema:
|
|
45
|
+
$ref: '#/components/schemas/Error'
|
|
46
|
+
example:
|
|
47
|
+
code: invalid_code
|
|
48
|
+
message: Invalid token
|
|
49
|
+
500:
|
|
50
|
+
description: An unexpected error occurred
|
|
51
|
+
content:
|
|
52
|
+
'application/json':
|
|
53
|
+
schema:
|
|
54
|
+
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { AceBaseUser, getPublicAccountDetails } from '../schema/user';
|
|
3
|
+
import { sendNotAuthenticatedError, sendUnexpectedError } from '../shared/error';
|
|
4
|
+
import { createPublicAccessToken } from '../shared/tokens';
|
|
5
|
+
import { signIn, SignInCredentials } from '../shared/signin';
|
|
6
|
+
|
|
7
|
+
export type RequestQuery = {};
|
|
8
|
+
export type RequestBody = { client_id?: string } & (
|
|
9
|
+
{ method: 'token'; access_token: string } |
|
|
10
|
+
{ method: 'email'; email: string; password: string } |
|
|
11
|
+
{ method: 'account', username: string, password: string }
|
|
12
|
+
);
|
|
13
|
+
export type ResponseBody = {
|
|
14
|
+
access_token: string;
|
|
15
|
+
user: AceBaseUser
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
19
|
+
|
|
20
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
21
|
+
if (!env.config.auth.enabled) {
|
|
22
|
+
throw new Error('Authentication not enabled in the server settings');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
env.app.post(`/auth/${env.db.name}/signin`, async (req: Request, res) => {
|
|
26
|
+
|
|
27
|
+
const details = req.body;
|
|
28
|
+
const clientId = details.client_id || null; // NEW in AceBaseClient v0.9.4
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const user = await signIn(details as SignInCredentials, env, req);
|
|
32
|
+
if (typeof clientId === 'string' && env.clients.has(clientId)) {
|
|
33
|
+
const client = env.clients.get(clientId);
|
|
34
|
+
client.user = user; // Bind user to client socket
|
|
35
|
+
}
|
|
36
|
+
res.send({
|
|
37
|
+
access_token: createPublicAccessToken(user.uid, req.ip, user.access_token, env.tokenSalt),
|
|
38
|
+
user: getPublicAccountDetails(user)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
|
|
43
|
+
if (typeof err.code === 'string') {
|
|
44
|
+
// Authentication error
|
|
45
|
+
return sendNotAuthenticatedError(res, err.code, err.message);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Unexpected error
|
|
49
|
+
return sendUnexpectedError(res, err);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default addRoute;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/auth/{dbname}/signin:
|
|
2
|
+
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Sign in a user
|
|
6
|
+
description: Signs in an existing user
|
|
7
|
+
parameters:
|
|
8
|
+
- name: dbname
|
|
9
|
+
in: path
|
|
10
|
+
description: name of the database
|
|
11
|
+
required: true
|
|
12
|
+
schema:
|
|
13
|
+
type: string
|
|
14
|
+
example: mydb
|
|
15
|
+
requestBody:
|
|
16
|
+
description: sign in details
|
|
17
|
+
content:
|
|
18
|
+
'application/json':
|
|
19
|
+
schema:
|
|
20
|
+
oneOf:
|
|
21
|
+
- type: object
|
|
22
|
+
properties:
|
|
23
|
+
client_id:
|
|
24
|
+
description: ID of the connected websocket
|
|
25
|
+
type: string
|
|
26
|
+
method:
|
|
27
|
+
description: Method of authentication (email)
|
|
28
|
+
type: string
|
|
29
|
+
value: email
|
|
30
|
+
email:
|
|
31
|
+
description: User email address
|
|
32
|
+
type: string
|
|
33
|
+
password:
|
|
34
|
+
description: Password
|
|
35
|
+
type: string
|
|
36
|
+
format: password
|
|
37
|
+
required:
|
|
38
|
+
- method
|
|
39
|
+
- email
|
|
40
|
+
- password
|
|
41
|
+
example:
|
|
42
|
+
method: email
|
|
43
|
+
email: user@example.com
|
|
44
|
+
password: sup3rs3cr3t
|
|
45
|
+
- type: object
|
|
46
|
+
properties:
|
|
47
|
+
client_id:
|
|
48
|
+
description: ID of the connected websocket
|
|
49
|
+
type: string
|
|
50
|
+
method:
|
|
51
|
+
description: Method of authentication (account)
|
|
52
|
+
type: string
|
|
53
|
+
value: account
|
|
54
|
+
username:
|
|
55
|
+
description: Username
|
|
56
|
+
type: string
|
|
57
|
+
password:
|
|
58
|
+
description: Password
|
|
59
|
+
type: string
|
|
60
|
+
format: password
|
|
61
|
+
required:
|
|
62
|
+
- method
|
|
63
|
+
- username
|
|
64
|
+
- password
|
|
65
|
+
example:
|
|
66
|
+
method: username
|
|
67
|
+
username: user
|
|
68
|
+
password: sup3rs3cr3t
|
|
69
|
+
- type: object
|
|
70
|
+
properties:
|
|
71
|
+
client_id:
|
|
72
|
+
type: string
|
|
73
|
+
description: ID of the connected websocket
|
|
74
|
+
method:
|
|
75
|
+
type: string
|
|
76
|
+
value: token
|
|
77
|
+
description: Method of authentication (token)
|
|
78
|
+
access_token:
|
|
79
|
+
type: string
|
|
80
|
+
description: Previously acquired access token to sign in with
|
|
81
|
+
required:
|
|
82
|
+
- method
|
|
83
|
+
- access_token
|
|
84
|
+
example:
|
|
85
|
+
method: token
|
|
86
|
+
access_token: bewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
|
|
87
|
+
responses:
|
|
88
|
+
200:
|
|
89
|
+
description: When signin succeeds, it returns an object with the result
|
|
90
|
+
content:
|
|
91
|
+
'application/json':
|
|
92
|
+
schema:
|
|
93
|
+
type: object
|
|
94
|
+
properties:
|
|
95
|
+
access_token:
|
|
96
|
+
description: The access token that provides access to API calls that require authentication. This access token should be added to the Authorization header of those requests. The token is allowed to be cached by the client to sign in witht the token method later
|
|
97
|
+
type: string
|
|
98
|
+
example: ewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
|
|
99
|
+
user:
|
|
100
|
+
$ref: '#/components/schemas/User'
|
|
101
|
+
401:
|
|
102
|
+
description: When the sent request details are incorrect, this "401 Unauthorized" is returned
|
|
103
|
+
content:
|
|
104
|
+
'application/json':
|
|
105
|
+
schema:
|
|
106
|
+
type: object
|
|
107
|
+
properties:
|
|
108
|
+
code:
|
|
109
|
+
type: string
|
|
110
|
+
description: The exact error code
|
|
111
|
+
enum:
|
|
112
|
+
- invalid_token
|
|
113
|
+
- not_found
|
|
114
|
+
- duplicate
|
|
115
|
+
- token_mismatch
|
|
116
|
+
- wrong_password
|
|
117
|
+
example: not_found
|
|
118
|
+
message:
|
|
119
|
+
type: string
|
|
120
|
+
description: Description of the error
|
|
121
|
+
example: Incorrect email
|
|
122
|
+
example:
|
|
123
|
+
code: wrong_password
|
|
124
|
+
message: Incorrect password
|
|
125
|
+
500:
|
|
126
|
+
description: An unenexpected error occurred on the server
|
|
127
|
+
content:
|
|
128
|
+
'application/json':
|
|
129
|
+
schema:
|
|
130
|
+
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { DbUserAccountDetails } from '../schema/user';
|
|
3
|
+
import { sendUnexpectedError } from '../shared/error';
|
|
4
|
+
|
|
5
|
+
export type RequestQuery = {};
|
|
6
|
+
export type RequestBody = { client_id?: string } & {
|
|
7
|
+
everywhere: boolean
|
|
8
|
+
};
|
|
9
|
+
export type ResponseBody = 'Bye!' | { code: string; message: string };
|
|
10
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
11
|
+
|
|
12
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
13
|
+
env.app.post(`/auth/${env.db.name}/signout`, async (req: Request, res) => {
|
|
14
|
+
|
|
15
|
+
const LOG_ACTION = 'auth.signout';
|
|
16
|
+
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null };
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
if (req.user) {
|
|
20
|
+
const client = typeof req.body.client_id === 'string' ? env.clients.get(req.body.client_id) : null; // NEW in AceBaseClient v0.9.4
|
|
21
|
+
if (client) {
|
|
22
|
+
// Remove user binding from client socket
|
|
23
|
+
client.user = null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const signOutEverywhere = typeof req.body === 'object' && req.body.everywhere === true; // NEW in AceBaseClient v0.9.14
|
|
27
|
+
if (signOutEverywhere) {
|
|
28
|
+
// Remove token from cache
|
|
29
|
+
env.authCache.remove(req.user.uid);
|
|
30
|
+
|
|
31
|
+
// Remove user binding from all clients signed in with current user
|
|
32
|
+
for (let client of env.clients.values()) {
|
|
33
|
+
if (client.user?.uid === req.user.uid) {
|
|
34
|
+
client.user = null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Remove token from user's auth node
|
|
40
|
+
await env.authRef.child(req.user.uid).transaction(snap => {
|
|
41
|
+
if (!snap.exists()) { return; }
|
|
42
|
+
|
|
43
|
+
const user: DbUserAccountDetails = snap.val();
|
|
44
|
+
if (signOutEverywhere) {
|
|
45
|
+
user.access_token = null;
|
|
46
|
+
}
|
|
47
|
+
user.last_signout = new Date();
|
|
48
|
+
user.last_signout_ip = req.ip;
|
|
49
|
+
return user;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
53
|
+
}
|
|
54
|
+
res.send('Bye!');
|
|
55
|
+
}
|
|
56
|
+
catch(err) {
|
|
57
|
+
env.log.error(LOG_ACTION, 'unexpected', { ...LOG_DETAILS, message: err instanceof Error ? err.message : err.toString() });
|
|
58
|
+
sendUnexpectedError(res, err);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default addRoute;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/auth/{dbname}/signout:
|
|
2
|
+
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Sign out current user
|
|
6
|
+
description: Signs out the currently signed in user
|
|
7
|
+
parameters:
|
|
8
|
+
- name: dbname
|
|
9
|
+
in: path
|
|
10
|
+
description: name of the database
|
|
11
|
+
required: true
|
|
12
|
+
schema:
|
|
13
|
+
type: string
|
|
14
|
+
example: mydb
|
|
15
|
+
requestBody:
|
|
16
|
+
description: Sign out details
|
|
17
|
+
content:
|
|
18
|
+
'application/json':
|
|
19
|
+
schema:
|
|
20
|
+
type: object
|
|
21
|
+
properties:
|
|
22
|
+
client_id:
|
|
23
|
+
type: string
|
|
24
|
+
description: ID of the connected websocket
|
|
25
|
+
everywhere:
|
|
26
|
+
type: boolean
|
|
27
|
+
description: Whether the user should sign out on ALL clients
|
|
28
|
+
example:
|
|
29
|
+
client_id: x8WIv7-mJelg7on_ALbx
|
|
30
|
+
everywhere: false
|
|
31
|
+
responses:
|
|
32
|
+
200:
|
|
33
|
+
description: Returns `"Bye!"` if signout is successful
|
|
34
|
+
content:
|
|
35
|
+
'text/plain':
|
|
36
|
+
schema:
|
|
37
|
+
type: string
|
|
38
|
+
value: Bye!
|
|
39
|
+
example: Bye!
|
|
40
|
+
500:
|
|
41
|
+
description: Returns an object describing an unexpected error
|
|
42
|
+
content:
|
|
43
|
+
'application/json':
|
|
44
|
+
schema:
|
|
45
|
+
$ref: '#/components/schemas/Error'
|
|
46
|
+
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { AceBaseUser, DbUserAccountDetails, getPublicAccountDetails, UserProfilePicture } from '../schema/user';
|
|
3
|
+
import { emailExistsError, emailOrUsernameExistsError, invalidDisplayNameError, invalidEmailError, invalidPasswordError, invalidPictureError, invalidSettingsError, invalidUsernameError, isValidDisplayName, isValidEmail, isValidNewEmailAddress, isValidNewUsername, isValidPassword, isValidPicture, isValidSettings, isValidUsername, usernameExistsError } from '../shared/validate';
|
|
4
|
+
import { createPasswordHash } from '../shared/password';
|
|
5
|
+
import { ID } from 'acebase-core';
|
|
6
|
+
import { AceBaseUserSignupEmailRequest } from '../shared/email';
|
|
7
|
+
import { createPublicAccessToken, createSignedPublicToken } from '../shared/tokens';
|
|
8
|
+
import { sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
|
|
9
|
+
|
|
10
|
+
export class SignupError extends Error {
|
|
11
|
+
constructor(public code: 'admin_only'|'conflict'|'email_conflict'|'username_conflict'|'missing_details'|'invalid_email'|'invalid_username'|'invalid_display_name'|'invalid_password'|'invalid_picture'|'invalid_settings', message: string) {
|
|
12
|
+
super(message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type RequestQuery = {};
|
|
17
|
+
export type RequestBody = {
|
|
18
|
+
username: string;
|
|
19
|
+
email: string;
|
|
20
|
+
password: string;
|
|
21
|
+
displayName?: string;
|
|
22
|
+
display_name?: string;
|
|
23
|
+
picture?: UserProfilePicture;
|
|
24
|
+
settings: {
|
|
25
|
+
[name: string]: string|number|boolean
|
|
26
|
+
};
|
|
27
|
+
} & (
|
|
28
|
+
// Allow both spellings of display name. display_name is used in the db, displayName in public user detail server responses.
|
|
29
|
+
// displayName is preferred and documented in the OpenAPI docs
|
|
30
|
+
{ displayName: string; } | { display_name: string; }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export type ResponseBody = { access_token: string; user: AceBaseUser } | { code: SignupError['code']; message: string };
|
|
34
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
35
|
+
|
|
36
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
37
|
+
env.app.post(`/auth/${env.db.name}/signup`, async (req: Request, res) => {
|
|
38
|
+
const LOG_ACTION = 'auth.signup';
|
|
39
|
+
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null };
|
|
40
|
+
|
|
41
|
+
if (!env.config.auth.allowUserSignup && req.user?.uid !== 'admin') {
|
|
42
|
+
env.log.error(LOG_ACTION, 'user_signup_disabled', LOG_DETAILS);
|
|
43
|
+
return sendUnauthorizedError(res, 'admin_only', 'Only admin is allowed to create users');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Create user if it doesn't exist yet.
|
|
47
|
+
// TODO: Rate-limit nr of signups per IP to prevent abuse
|
|
48
|
+
|
|
49
|
+
const details = req.body;
|
|
50
|
+
|
|
51
|
+
if (typeof details.display_name === 'string' && typeof details.displayName !== 'string') {
|
|
52
|
+
// Allow display_name to be sent also (which is used in update endpoint)
|
|
53
|
+
details.displayName = details.display_name;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Check if sent details are ok
|
|
57
|
+
let err: { code: SignupError['code'], message: string };
|
|
58
|
+
if (!details.username && !details.email) {
|
|
59
|
+
err = { code: 'missing_details', message: 'No username or email provided' };
|
|
60
|
+
}
|
|
61
|
+
else if (details.email && !isValidEmail(details.email)) {
|
|
62
|
+
err = invalidEmailError;
|
|
63
|
+
}
|
|
64
|
+
else if (details.email && !await isValidNewEmailAddress(env.authRef, details.email)) {
|
|
65
|
+
err = emailExistsError;
|
|
66
|
+
}
|
|
67
|
+
else if (details.username && !isValidUsername(details.username)) {
|
|
68
|
+
err = invalidUsernameError;
|
|
69
|
+
}
|
|
70
|
+
else if (details.username && !await isValidNewUsername(env.authRef, details.username)) {
|
|
71
|
+
err = usernameExistsError;
|
|
72
|
+
}
|
|
73
|
+
else if (!isValidDisplayName(details.displayName)) {
|
|
74
|
+
err = invalidDisplayNameError;
|
|
75
|
+
}
|
|
76
|
+
else if (!isValidPassword(details.password)) {
|
|
77
|
+
err = invalidPasswordError;
|
|
78
|
+
}
|
|
79
|
+
else if (!isValidSettings(details.settings)) {
|
|
80
|
+
err = invalidSettingsError;
|
|
81
|
+
}
|
|
82
|
+
else if (details.picture && !isValidPicture(details.picture)) {
|
|
83
|
+
err = invalidPictureError;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (err === emailExistsError || err === usernameExistsError) {
|
|
87
|
+
env.log.error(LOG_ACTION, 'conflict', { ...LOG_DETAILS, username: details.username, email: details.email });
|
|
88
|
+
res.statusCode = 409; // conflict
|
|
89
|
+
return res.send(emailOrUsernameExistsError);
|
|
90
|
+
}
|
|
91
|
+
else if (err) {
|
|
92
|
+
// Log failure
|
|
93
|
+
env.log.error(LOG_ACTION, err.code ?? 'unexpected', LOG_DETAILS);
|
|
94
|
+
res.statusCode = 422; // Unprocessable Entity
|
|
95
|
+
return res.send(err);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
// Ok, create user
|
|
100
|
+
let pwd = createPasswordHash(details.password);
|
|
101
|
+
const user: DbUserAccountDetails = {
|
|
102
|
+
uid: null,
|
|
103
|
+
username: details.username ?? null,
|
|
104
|
+
email: details.email ?? null,
|
|
105
|
+
email_verified: false,
|
|
106
|
+
display_name: details.displayName,
|
|
107
|
+
password: pwd.hash,
|
|
108
|
+
password_salt: pwd.salt,
|
|
109
|
+
created: new Date(),
|
|
110
|
+
created_ip: req.ip,
|
|
111
|
+
access_token: ID.generate(),
|
|
112
|
+
access_token_created: new Date(),
|
|
113
|
+
last_signin: new Date(),
|
|
114
|
+
last_signin_ip: req.ip,
|
|
115
|
+
picture: details.picture ?? null,
|
|
116
|
+
settings: details.settings ?? {}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const userRef = await env.authRef.push(user);
|
|
120
|
+
user.uid = userRef.key;
|
|
121
|
+
LOG_DETAILS.uid = user.uid;
|
|
122
|
+
|
|
123
|
+
// Log success
|
|
124
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
125
|
+
|
|
126
|
+
// Cache the user
|
|
127
|
+
env.authCache.set(user.uid, user);
|
|
128
|
+
|
|
129
|
+
// Request welcome e-mail to be sent
|
|
130
|
+
const request: AceBaseUserSignupEmailRequest = {
|
|
131
|
+
type: 'user_signup',
|
|
132
|
+
user: {
|
|
133
|
+
uid: user.uid,
|
|
134
|
+
username: user.username,
|
|
135
|
+
email: user.email,
|
|
136
|
+
displayName: user.display_name,
|
|
137
|
+
settings: user.settings
|
|
138
|
+
},
|
|
139
|
+
date: user.created,
|
|
140
|
+
ip: user.created_ip,
|
|
141
|
+
provider: 'acebase',
|
|
142
|
+
activationCode: createSignedPublicToken({ uid: user.uid }, env.tokenSalt),
|
|
143
|
+
emailVerified: false
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
env.config.email?.send(request).catch(err => {
|
|
147
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', { ...LOG_DETAILS, request }, err);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Return the positive news
|
|
151
|
+
const isAdmin = req.user && req.user.uid === 'admin';
|
|
152
|
+
res.send({
|
|
153
|
+
access_token: isAdmin ? '' : createPublicAccessToken(user.uid, req.ip, user.access_token, env.tokenSalt),
|
|
154
|
+
user: getPublicAccountDetails(user)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
env.log.error(LOG_ACTION, 'unexpected', { ...LOG_DETAILS, message: err instanceof Error ? err.message : err.toString(), username: details.username, email: details.email });
|
|
159
|
+
sendUnexpectedError(res, err);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export default addRoute;
|