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,65 @@
|
|
|
1
|
+
export interface IOAuth2ProviderSettings {
|
|
2
|
+
client_id: string,
|
|
3
|
+
client_secret: string,
|
|
4
|
+
scopes?: string[]
|
|
5
|
+
}
|
|
6
|
+
export interface IOAuth2RefreshTokenParams {
|
|
7
|
+
type: 'refresh'
|
|
8
|
+
refresh_token: string
|
|
9
|
+
}
|
|
10
|
+
export interface IOAuth2AuthCodeParams {
|
|
11
|
+
type: 'auth'
|
|
12
|
+
auth_code: string
|
|
13
|
+
redirect_url: string
|
|
14
|
+
}
|
|
15
|
+
export interface IOAuth2TokenResult {
|
|
16
|
+
access_token: string,
|
|
17
|
+
id_token?: IOpenIDToken,
|
|
18
|
+
expires_in?: number,
|
|
19
|
+
refresh_token?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type OAuth2ProviderInitInfo = { redirect_url: string, state?: string, options?: any };
|
|
23
|
+
export type OAuth2ProviderUserInfo = { id: string, name: string, display_name: string, picture?: Array<{ width?: number, height?: number, url: string }>, email: string, email_verified: boolean, other?: { [key:string]: string|number|boolean } };
|
|
24
|
+
// export interface IOAuth2Provider {
|
|
25
|
+
// init(info: OAuth2ProviderInitInfo): Promise<string>;
|
|
26
|
+
// getAccessToken(param: OAuth2ProviderGetAccessTokenParams): Promise<IOAuth2TokenResult>;
|
|
27
|
+
// getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo>;
|
|
28
|
+
// }
|
|
29
|
+
class NotImplementedError extends Error { constructor() { super('Not implemented'); } }
|
|
30
|
+
export class OAuth2Provider { //implements IOAuth2Provider
|
|
31
|
+
constructor(protected settings: IOAuth2ProviderSettings) {}
|
|
32
|
+
init(info: OAuth2ProviderInitInfo): Promise<string> { throw new NotImplementedError(); };
|
|
33
|
+
getAccessToken(param: IOAuth2AuthCodeParams|IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult> { throw new NotImplementedError(); };;
|
|
34
|
+
getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo> { throw new NotImplementedError(); };;
|
|
35
|
+
}
|
|
36
|
+
// For OAuth2.0 providers with id_token in getAccessToken, see https://auth0.com/docs/tokens/concepts/jwts
|
|
37
|
+
export interface IOpenIDToken {
|
|
38
|
+
// Omitted properties aud, exp, ist, iss, sub, at_hash, azp, hd, nonce,
|
|
39
|
+
email: string
|
|
40
|
+
email_verified: boolean
|
|
41
|
+
family_name?: string // last name(s)
|
|
42
|
+
given_name?: string // first name(s)
|
|
43
|
+
locale: string
|
|
44
|
+
name: string // full name
|
|
45
|
+
picture?: string // url
|
|
46
|
+
profile?: string // url
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface IOpenIDConfiguration {
|
|
50
|
+
issuer: string
|
|
51
|
+
authorization_endpoint: string
|
|
52
|
+
device_authorization_endpoint: string
|
|
53
|
+
token_endpoint: string
|
|
54
|
+
userinfo_endpoint: string
|
|
55
|
+
revocation_endpoint: string
|
|
56
|
+
jwks_uri: string
|
|
57
|
+
response_types_supported: string[]
|
|
58
|
+
subject_types_supported: string[]
|
|
59
|
+
id_token_signing_alg_values_supported: string[]
|
|
60
|
+
scopes_supported: string[]
|
|
61
|
+
token_endpoint_auth_methods_supported: string[]
|
|
62
|
+
claims_supported: string[]
|
|
63
|
+
code_challenge_methods_supported: string[]
|
|
64
|
+
grant_types_supported: string[]
|
|
65
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
|
+
import { fetch } from '../shared/simple-fetch';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Details of your app to access the Spotify API
|
|
6
|
+
*/
|
|
7
|
+
export interface ISpotifyAuthSettings extends IOAuth2ProviderSettings {
|
|
8
|
+
/** 'user-read-email', 'user-read-private' and additional scopes you want to access. See https://developer.spotify.com/documentation/general/guides/scopes/ */
|
|
9
|
+
scopes?: string[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface ISpotifyAuthToken { access_token: string, expires_in: number, expires: Date, refresh_token: string, scope: string, token_type: string }
|
|
13
|
+
interface ISpotifyClientAuthToken { access_token: string, token_type: string, expires_in: number }
|
|
14
|
+
interface ISpotifyExternalUrl { key: string, value: string }
|
|
15
|
+
interface ISpotifyFollowers { href: string, total: number }
|
|
16
|
+
interface ISpotifyImage { width: number, height: number, url: string }
|
|
17
|
+
interface ISpotifyError { status: number, message: string }
|
|
18
|
+
interface ISpotifyUser {
|
|
19
|
+
country: string,
|
|
20
|
+
display_name: string,
|
|
21
|
+
email: string, // NOT VERIFIED! See https://developer.spotify.com/documentation/web-api/reference/users-profile/get-current-users-profile/
|
|
22
|
+
external_urls: ISpotifyExternalUrl,
|
|
23
|
+
followers: ISpotifyFollowers,
|
|
24
|
+
href: string,
|
|
25
|
+
id: string,
|
|
26
|
+
images: Array<ISpotifyImage>,
|
|
27
|
+
product: 'premium'|'free'|'open',
|
|
28
|
+
type: 'user',
|
|
29
|
+
uri: string
|
|
30
|
+
}
|
|
31
|
+
export class SpotifyAuthProvider extends OAuth2Provider {
|
|
32
|
+
|
|
33
|
+
constructor(settings: ISpotifyAuthSettings) {
|
|
34
|
+
super(settings);
|
|
35
|
+
if (!settings.scopes) { settings.scopes = []; }
|
|
36
|
+
if (!settings.scopes.includes('user-read-email')) { settings.scopes.push('user-read-email'); }
|
|
37
|
+
if (!settings.scopes.includes('user-read-private')) { settings.scopes.push('user-read-private'); }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Starts auth flow by getting the url the user should be redirected to
|
|
42
|
+
* @param info.redirectUrl Url spotify will redirect to after authorizing
|
|
43
|
+
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
44
|
+
*/
|
|
45
|
+
async init(info: OAuth2ProviderInitInfo) {
|
|
46
|
+
// Return url to get authorization code with
|
|
47
|
+
const authUrl = `https://accounts.spotify.com/authorize?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
|
|
48
|
+
return authUrl;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getAccessToken(params: IOAuth2AuthCodeParams|IOAuth2RefreshTokenParams) {
|
|
52
|
+
// Request access & refresh tokens with authorization code
|
|
53
|
+
return fetch('https://accounts.spotify.com/api/token', {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
57
|
+
},
|
|
58
|
+
body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
|
|
59
|
+
(params.type === 'refresh'
|
|
60
|
+
? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
|
|
61
|
+
: `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`)
|
|
62
|
+
})
|
|
63
|
+
.then(response => response.json())
|
|
64
|
+
.then((result: ISpotifyAuthToken) => {
|
|
65
|
+
if ((result as any).error) {
|
|
66
|
+
throw new Error((result as any).error);
|
|
67
|
+
}
|
|
68
|
+
const secondsToExpiry = result.expires_in;
|
|
69
|
+
result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
|
|
70
|
+
return result;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getClientAccessToken() {
|
|
75
|
+
// Gets client only access to Spotify API, without signed in user
|
|
76
|
+
return fetch('https://accounts.spotify.com/api/token', {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
80
|
+
"Authorization": `Basic ${Buffer.from(`${this.settings.client_id}:${this.settings.client_secret}`).toString('base64')}`
|
|
81
|
+
},
|
|
82
|
+
body: `grant_type=client_credentials`
|
|
83
|
+
})
|
|
84
|
+
.then(response => response.json())
|
|
85
|
+
.then((result: ISpotifyClientAuthToken) => {
|
|
86
|
+
if ((result as any).error) {
|
|
87
|
+
throw new Error((result as any).error);
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getUserInfo(access_token: string) {
|
|
94
|
+
return fetch('https://api.spotify.com/v1/me', {
|
|
95
|
+
method: 'GET',
|
|
96
|
+
headers: {
|
|
97
|
+
"Authorization": `Bearer ${access_token}`
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
.then(async response => {
|
|
101
|
+
const result = await response.json();
|
|
102
|
+
if (response.status !== 200) {
|
|
103
|
+
const error = result as ISpotifyError;
|
|
104
|
+
throw new Error(`${error.status}: ${error.message}`);
|
|
105
|
+
}
|
|
106
|
+
const user = result as ISpotifyUser;
|
|
107
|
+
return {
|
|
108
|
+
id: user.id,
|
|
109
|
+
name: user.display_name,
|
|
110
|
+
display_name: user.display_name,
|
|
111
|
+
picture: user.images,
|
|
112
|
+
email: user.email,
|
|
113
|
+
email_verified: false,
|
|
114
|
+
other: {
|
|
115
|
+
premium: user.product === 'premium',
|
|
116
|
+
followers: user.followers ? user.followers.total : null,
|
|
117
|
+
country: user.country,
|
|
118
|
+
// external_urls: user.external_urls,
|
|
119
|
+
uri: user.uri
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const AuthProvider = SpotifyAuthProvider;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* When using `@types/node@10.17.60` to check for backward compatibility with Node.js 10,
|
|
4
|
+
* tsc will throw errors on `@types/fs-extra` that references types `fs.Dir`,
|
|
5
|
+
* `fs.OpenDirOptions` and `fs.RmDirOptions`, which are not declared.
|
|
6
|
+
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44946
|
|
7
|
+
*/
|
|
8
|
+
declare module 'fs' {
|
|
9
|
+
interface Dir {}
|
|
10
|
+
interface OpenDirOptions {}
|
|
11
|
+
interface RmDirOptions {}
|
|
12
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { DbUserAccountDetails } from '../schema/user';
|
|
3
|
+
import { sendBadRequestError, sendUnexpectedError } from '../shared/error';
|
|
4
|
+
import { createPasswordHash, getOldPasswordHash, getPasswordHash } from '../shared/password';
|
|
5
|
+
import { ID } from 'acebase-core';
|
|
6
|
+
import { createPublicAccessToken } from '../shared/tokens';
|
|
7
|
+
|
|
8
|
+
export class ChangePasswordError extends Error {
|
|
9
|
+
constructor(public code: 'unknown_uid'|'wrong_password'|'wrong_access_token', message: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type RequestQuery = {};
|
|
15
|
+
export type RequestBody = { uid: string; password: string; new_password: string };
|
|
16
|
+
export type ResponseBody = { access_token: string } | { code: string; message: string } | string;
|
|
17
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
18
|
+
|
|
19
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
20
|
+
env.app.post(`/auth/${env.db.name}/change_password`, async (req: Request, res) => {
|
|
21
|
+
let access_token = req.user?.access_token;
|
|
22
|
+
const details = req.body;
|
|
23
|
+
const LOG_ACTION = 'auth.change_password';
|
|
24
|
+
const LOG_DETAILS = { ip: req.ip, uid: details.uid ?? null };
|
|
25
|
+
|
|
26
|
+
if (typeof details !== 'object' || typeof details.uid !== 'string' || typeof details.password !== 'string' || typeof details.new_password !== 'string') {
|
|
27
|
+
env.log.error(LOG_ACTION, 'invalid_details', LOG_DETAILS);
|
|
28
|
+
res.status(400).send('Bad Request'); // Bad Request
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (details.new_password.length < 8 || details.new_password.includes(' ') || !/[0-9]/.test(details.new_password) || !/[a-z]/.test(details.new_password) || !/[A-Z]/.test(details.new_password)) {
|
|
32
|
+
env.log.error(LOG_ACTION, 'new_password_denied', LOG_DETAILS);
|
|
33
|
+
const err = 'Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)';
|
|
34
|
+
res.status(422).send(err);// Unprocessable Entity
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
let publicAccessToken: string;
|
|
40
|
+
await env.authRef.child(details.uid).transaction(snap => {
|
|
41
|
+
if (!snap.exists()) {
|
|
42
|
+
throw new ChangePasswordError('unknown_uid', `Unknown uid`);
|
|
43
|
+
}
|
|
44
|
+
let user: DbUserAccountDetails = snap.val();
|
|
45
|
+
user.uid = snap.key as string;
|
|
46
|
+
|
|
47
|
+
let hash = user.password_salt ? getPasswordHash(details.password, user.password_salt) : getOldPasswordHash(details.password);
|
|
48
|
+
|
|
49
|
+
if (user.password !== hash) {
|
|
50
|
+
throw new ChangePasswordError('wrong_password', `Wrong password`);
|
|
51
|
+
}
|
|
52
|
+
if (access_token && access_token !== user.access_token) {
|
|
53
|
+
throw new ChangePasswordError('wrong_access_token', `Cannot change password while signed in as other user, or with an old token`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let pwd = createPasswordHash(details.new_password);
|
|
57
|
+
const updates = {
|
|
58
|
+
access_token: ID.generate(),
|
|
59
|
+
access_token_created: new Date(),
|
|
60
|
+
password: pwd.hash,
|
|
61
|
+
password_salt: pwd.salt
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Update user object
|
|
65
|
+
Object.assign(user, updates);
|
|
66
|
+
|
|
67
|
+
// Set or update cache
|
|
68
|
+
env.authCache.set(user.uid, user);
|
|
69
|
+
|
|
70
|
+
// Create new public access token
|
|
71
|
+
publicAccessToken = createPublicAccessToken(user.uid, req.ip, user.access_token, env.tokenSalt);
|
|
72
|
+
|
|
73
|
+
return user; // Update db
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
77
|
+
res.send({ access_token: publicAccessToken }); // Client must use this new access token from now on
|
|
78
|
+
}
|
|
79
|
+
catch(err) {
|
|
80
|
+
env.log.error(LOG_ACTION, err.code, LOG_DETAILS);
|
|
81
|
+
if (err.code) {
|
|
82
|
+
sendBadRequestError(res, err);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
sendUnexpectedError(res, err);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export default addRoute;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/auth/{dbname}/change_password:
|
|
2
|
+
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Change a user's password
|
|
6
|
+
description: Changes a user account's password by providing the current and new passwords
|
|
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: request object
|
|
17
|
+
content:
|
|
18
|
+
'application/json':
|
|
19
|
+
schema:
|
|
20
|
+
type: object
|
|
21
|
+
properties:
|
|
22
|
+
uid:
|
|
23
|
+
type: string
|
|
24
|
+
description: Account's uid
|
|
25
|
+
password:
|
|
26
|
+
type: string
|
|
27
|
+
description: Current password set on the account
|
|
28
|
+
new_password:
|
|
29
|
+
type: string
|
|
30
|
+
description: New password to set on the account
|
|
31
|
+
required:
|
|
32
|
+
- uid
|
|
33
|
+
- password
|
|
34
|
+
- new_password
|
|
35
|
+
responses:
|
|
36
|
+
200:
|
|
37
|
+
description: If the password change is successful, returns an object with a new access token
|
|
38
|
+
content:
|
|
39
|
+
'application/json':
|
|
40
|
+
schema:
|
|
41
|
+
type: object
|
|
42
|
+
properties:
|
|
43
|
+
access_token:
|
|
44
|
+
description: New access token that provides access to API calls that require authentication.
|
|
45
|
+
type: string
|
|
46
|
+
example: ewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
|
|
47
|
+
400:
|
|
48
|
+
description: Returns a `"400 Bad Request"` if the sent request is invalid. If the request is missing details, response is the string `"Bad Request"`. Otherwise, it's an object with `code` and `message` properties. Possible codes are `"unknown_uid"`, `"wrong_password"`, `"wrong_access_token"` (if not signed in as the user the password change was requested for)
|
|
49
|
+
content:
|
|
50
|
+
'text/plain':
|
|
51
|
+
schema:
|
|
52
|
+
type: string
|
|
53
|
+
value: Bad Request
|
|
54
|
+
example: Bad Request
|
|
55
|
+
'application/json':
|
|
56
|
+
schema:
|
|
57
|
+
$ref: '#/components/schemas/Error'
|
|
58
|
+
example:
|
|
59
|
+
code: wrong_access_token
|
|
60
|
+
message: "Cannot change password while signed in as other user, or with an old token"
|
|
61
|
+
422:
|
|
62
|
+
description: New password does not meet the criteria
|
|
63
|
+
content:
|
|
64
|
+
'text/plain':
|
|
65
|
+
schema:
|
|
66
|
+
type: string
|
|
67
|
+
value: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
|
|
68
|
+
example: "Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)"
|
|
69
|
+
500:
|
|
70
|
+
description: An unexpected error occurred
|
|
71
|
+
content:
|
|
72
|
+
'application/json':
|
|
73
|
+
schema:
|
|
74
|
+
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { sendNotAuthenticatedError, sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
|
|
3
|
+
|
|
4
|
+
export class DeleteError extends Error {
|
|
5
|
+
constructor(public code: 'unauthenticated_delete'|'unauthorized_delete', message: string) {
|
|
6
|
+
super(message);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type RequestQuery = {};
|
|
11
|
+
export type RequestBody = { uid: string };
|
|
12
|
+
export type ResponseBody = 'Farewell' | { code: DeleteError['code']; message: string };
|
|
13
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
14
|
+
|
|
15
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
16
|
+
env.app.post(`/auth/${env.db.name}/delete`, async (req: Request, res) => {
|
|
17
|
+
let details = req.body;
|
|
18
|
+
const LOG_ACTION = 'auth.delete';
|
|
19
|
+
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, delete_uid: details.uid };
|
|
20
|
+
|
|
21
|
+
if (!req.user) {
|
|
22
|
+
env.log.error(LOG_ACTION, 'unauthenticated_delete', LOG_DETAILS);
|
|
23
|
+
return sendNotAuthenticatedError(res, 'unauthenticated_delete', 'You are not authorized to perform this operation, your attempt has been logged');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (req.user.uid !== 'admin' && details.uid !== req.user.uid) {
|
|
27
|
+
env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
|
|
28
|
+
return sendUnauthorizedError(res, 'unauthorized_delete', 'You are not authorized to perform this operation, your attempt has been logged');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const uid = details.uid ?? req.user.uid;
|
|
32
|
+
if (uid === 'admin') {
|
|
33
|
+
env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
|
|
34
|
+
return sendUnauthorizedError(res, 'unauthorized_delete', 'The admin account cannot be deleted, your attempt has been logged');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
await env.authRef.child(uid).remove();
|
|
39
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
40
|
+
res.send('Farewell');
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
env.log.error(LOG_ACTION, 'unexpected', { ...LOG_DETAILS, message: (err instanceof Error && err.message) ?? err.toString() });
|
|
44
|
+
sendUnexpectedError(res, err);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default addRoute;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/auth/{dbname}/delete:
|
|
2
|
+
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Delete a user account
|
|
6
|
+
description: Deletes an existing user account
|
|
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: Account to delete
|
|
17
|
+
content:
|
|
18
|
+
'text/plain':
|
|
19
|
+
schema:
|
|
20
|
+
type: string
|
|
21
|
+
value: ''
|
|
22
|
+
example: ''
|
|
23
|
+
description: Empty content to delete signed in user account
|
|
24
|
+
'application/json':
|
|
25
|
+
schema:
|
|
26
|
+
type: object
|
|
27
|
+
properties:
|
|
28
|
+
uid:
|
|
29
|
+
type: string
|
|
30
|
+
description: (admin user only) to delete a specific user account, the target account `uid` must be passed with the request
|
|
31
|
+
example: jpx0k53u0002ecr7s354c51l
|
|
32
|
+
responses:
|
|
33
|
+
200:
|
|
34
|
+
description: When delete succeeds, it returns the string `"Farewell"`
|
|
35
|
+
content:
|
|
36
|
+
'text/plain':
|
|
37
|
+
schema:
|
|
38
|
+
type: text
|
|
39
|
+
value: Farewell
|
|
40
|
+
example: Farewell
|
|
41
|
+
401:
|
|
42
|
+
description: If this is an unauthenticated request (not signed in), `"401 Unauthorized"` is returned
|
|
43
|
+
content:
|
|
44
|
+
'application/json':
|
|
45
|
+
schema:
|
|
46
|
+
type: object
|
|
47
|
+
properties:
|
|
48
|
+
code:
|
|
49
|
+
type: string
|
|
50
|
+
value: unauthenticated_delete
|
|
51
|
+
message:
|
|
52
|
+
type: string
|
|
53
|
+
value: You are not authorized to perform this operation, your attempt has been logged
|
|
54
|
+
example:
|
|
55
|
+
code: unauthenticated_delete
|
|
56
|
+
message: You are not authorized to perform this operation, your attempt has been logged
|
|
57
|
+
403:
|
|
58
|
+
description: If a non-admin user tries to update a user's account details, `"403 Forbidden"` is returned
|
|
59
|
+
content:
|
|
60
|
+
'application/json':
|
|
61
|
+
schema:
|
|
62
|
+
type: object
|
|
63
|
+
properties:
|
|
64
|
+
code:
|
|
65
|
+
type: string
|
|
66
|
+
value: unauthorized_delete
|
|
67
|
+
message:
|
|
68
|
+
type: string
|
|
69
|
+
value: You are not authorized to perform this operation. This attempt has been logged.
|
|
70
|
+
example:
|
|
71
|
+
code: unauthorized_delete
|
|
72
|
+
message: You are not authorized to perform this operation. This attempt has been logged.
|
|
73
|
+
500:
|
|
74
|
+
description: An unenexpected error occurred on the server
|
|
75
|
+
content:
|
|
76
|
+
'application/json':
|
|
77
|
+
schema:
|
|
78
|
+
$ref: '#/components/schemas/UnexpectedError'
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { DbUserAccountDetails } from '../schema/user';
|
|
3
|
+
import { createSignedPublicToken } from '../shared/tokens';
|
|
4
|
+
import { ID } from 'acebase-core';
|
|
5
|
+
import { AceBaseUserResetPasswordEmailRequest } from '../shared/email';
|
|
6
|
+
import { sendBadRequestError, sendUnexpectedError } from '../shared/error';
|
|
7
|
+
|
|
8
|
+
export class ForgotPasswordError extends Error {
|
|
9
|
+
constructor(public code: 'server_email_config'|'invalid_details'|'invalid_email', message: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type RequestQuery = {};
|
|
15
|
+
export type RequestBody = { email: string };
|
|
16
|
+
export type ResponseBody = 'OK' | { code: string; message: string };
|
|
17
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
18
|
+
|
|
19
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
20
|
+
|
|
21
|
+
env.app.post(`/auth/${env.db.name}/forgot_password`, async (req: Request, res) => {
|
|
22
|
+
|
|
23
|
+
const details = req.body;
|
|
24
|
+
const LOG_ACTION = 'auth.forgot_password';
|
|
25
|
+
const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, email: details.email };
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
if (!env.config.email || typeof env.config.email.send !== 'function') {
|
|
29
|
+
throw new ForgotPasswordError('server_email_config', 'Server email settings have not been configured');
|
|
30
|
+
}
|
|
31
|
+
if (typeof details !== 'object' || typeof details.email !== 'string' || details.email.length === 0) {
|
|
32
|
+
throw new ForgotPasswordError('invalid_details', 'Invalid details');
|
|
33
|
+
}
|
|
34
|
+
const snaps = await env.authRef.query().filter('email', '==', details.email).get();
|
|
35
|
+
if (snaps.length !== 1) {
|
|
36
|
+
throw new ForgotPasswordError('invalid_email', 'Email address not found, or duplicate entries found');
|
|
37
|
+
}
|
|
38
|
+
const snap = snaps[0];
|
|
39
|
+
const user: DbUserAccountDetails = snap.val();
|
|
40
|
+
user.uid = snap.key as string;
|
|
41
|
+
user.password_reset_code = ID.generate();
|
|
42
|
+
|
|
43
|
+
// Request a password reset email to be sent:
|
|
44
|
+
const request: AceBaseUserResetPasswordEmailRequest = {
|
|
45
|
+
type: 'user_reset_password',
|
|
46
|
+
date: new Date(),
|
|
47
|
+
ip: req.ip,
|
|
48
|
+
resetCode: createSignedPublicToken({ uid: user.uid, code: user.password_reset_code }, env.tokenSalt),
|
|
49
|
+
user: {
|
|
50
|
+
email: user.email,
|
|
51
|
+
uid: user.uid,
|
|
52
|
+
username: user.username,
|
|
53
|
+
settings: user.settings,
|
|
54
|
+
displayName: user.display_name
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
await snap.ref.update({ password_reset_code: user.password_reset_code });
|
|
59
|
+
await env.config.email.send(request).catch(err => {
|
|
60
|
+
env.log.error(LOG_ACTION + '.email', 'unexpected', { ...LOG_DETAILS, request }, err);
|
|
61
|
+
});
|
|
62
|
+
env.log.event(LOG_ACTION, LOG_DETAILS);
|
|
63
|
+
res.send('OK');
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
env.log.error(LOG_ACTION, err.code || 'unexpected', { ...LOG_DETAILS, message: (err instanceof Error && err.message) ?? err.toString() });
|
|
67
|
+
if (err.code) {
|
|
68
|
+
sendBadRequestError(res, err);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
sendUnexpectedError(res, err);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default addRoute;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/auth/{dbname}/forgot_password:
|
|
2
|
+
post:
|
|
3
|
+
tags:
|
|
4
|
+
- auth
|
|
5
|
+
summary: Issue a password reset
|
|
6
|
+
description: Issues a password reset for a user that forgot their password. User must have an email address in the database.
|
|
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: user details
|
|
17
|
+
content:
|
|
18
|
+
'application/json':
|
|
19
|
+
schema:
|
|
20
|
+
type: object
|
|
21
|
+
properties:
|
|
22
|
+
email:
|
|
23
|
+
type: string
|
|
24
|
+
description: User's email address. A password reset email will be sent to this address
|
|
25
|
+
required:
|
|
26
|
+
- email
|
|
27
|
+
responses:
|
|
28
|
+
200:
|
|
29
|
+
description: If a password reset email has been successfully sent, returns the string `"OK"`
|
|
30
|
+
content:
|
|
31
|
+
'text/plain':
|
|
32
|
+
schema:
|
|
33
|
+
type: 'string'
|
|
34
|
+
value: OK
|
|
35
|
+
description: The string `"OK"`
|
|
36
|
+
400:
|
|
37
|
+
description: Returns a `"400 Bad Request"` if the server has not been configured properly, or if no or invalid email address was sent with the request
|
|
38
|
+
content:
|
|
39
|
+
'application/json':
|
|
40
|
+
schema:
|
|
41
|
+
$ref: '#/components/schemas/Error'
|
|
42
|
+
example:
|
|
43
|
+
code: invalid_email
|
|
44
|
+
message: Email address not found, or duplicate entries found
|
|
45
|
+
500:
|
|
46
|
+
description: An unexpected error occurred
|
|
47
|
+
content:
|
|
48
|
+
'application/json':
|
|
49
|
+
schema:
|
|
50
|
+
$ref: '#/components/schemas/UnexpectedError'
|