acebase-server 1.9.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +24 -0
- package/create-package-files +12 -0
- package/dist/cjs/auth.js +89 -0
- package/dist/cjs/auth.js.map +1 -0
- package/dist/cjs/cluster.js +57 -0
- package/dist/cjs/cluster.js.map +1 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/middleware/404.js +15 -0
- package/dist/cjs/middleware/404.js.map +1 -0
- package/dist/cjs/middleware/cache.js +15 -0
- package/dist/cjs/middleware/cache.js.map +1 -0
- package/dist/cjs/middleware/connection.js +50 -0
- package/dist/cjs/middleware/connection.js.map +1 -0
- package/dist/cjs/middleware/context.js +21 -0
- package/dist/cjs/middleware/context.js.map +1 -0
- package/dist/cjs/middleware/cors.js +51 -0
- package/dist/cjs/middleware/cors.js.map +1 -0
- package/dist/cjs/middleware/swagger.js +18 -0
- package/dist/cjs/middleware/swagger.js.map +1 -0
- package/dist/cjs/middleware/user.js +58 -0
- package/dist/cjs/middleware/user.js.map +1 -0
- package/dist/cjs/oauth-providers/dropbox.js +109 -0
- package/dist/cjs/oauth-providers/dropbox.js.map +1 -0
- package/dist/cjs/oauth-providers/facebook.js +85 -0
- package/dist/cjs/oauth-providers/facebook.js.map +1 -0
- package/dist/cjs/oauth-providers/google.js +125 -0
- package/dist/cjs/oauth-providers/google.js.map +1 -0
- package/dist/cjs/oauth-providers/index.js +27 -0
- package/dist/cjs/oauth-providers/index.js.map +1 -0
- package/dist/cjs/oauth-providers/instagram.js +80 -0
- package/dist/cjs/oauth-providers/instagram.js.map +1 -0
- package/dist/cjs/oauth-providers/oauth-provider.js +3 -0
- package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -0
- package/dist/cjs/oauth-providers/spotify.js +113 -0
- package/dist/cjs/oauth-providers/spotify.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/routes/auth-change-password.js +85 -0
- package/dist/cjs/routes/auth-change-password.js.map +1 -0
- package/dist/cjs/routes/auth-delete.js +51 -0
- package/dist/cjs/routes/auth-delete.js.map +1 -0
- package/dist/cjs/routes/auth-forgot-password.js +75 -0
- package/dist/cjs/routes/auth-forgot-password.js.map +1 -0
- package/dist/cjs/routes/auth-reset-password.js +94 -0
- package/dist/cjs/routes/auth-reset-password.js.map +1 -0
- package/dist/cjs/routes/auth-signin.js +47 -0
- package/dist/cjs/routes/auth-signin.js.map +1 -0
- package/dist/cjs/routes/auth-signout.js +60 -0
- package/dist/cjs/routes/auth-signout.js.map +1 -0
- package/dist/cjs/routes/auth-signup.js +141 -0
- package/dist/cjs/routes/auth-signup.js.map +1 -0
- package/dist/cjs/routes/auth-state.js +26 -0
- package/dist/cjs/routes/auth-state.js.map +1 -0
- package/dist/cjs/routes/auth-update.js +129 -0
- package/dist/cjs/routes/auth-update.js.map +1 -0
- package/dist/cjs/routes/auth-verify-email.js +67 -0
- package/dist/cjs/routes/auth-verify-email.js.map +1 -0
- package/dist/cjs/routes/auth.js +55 -0
- package/dist/cjs/routes/auth.js.map +1 -0
- package/dist/cjs/routes/data-exists.js +34 -0
- package/dist/cjs/routes/data-exists.js.map +1 -0
- package/dist/cjs/routes/data-export.js +49 -0
- package/dist/cjs/routes/data-export.js.map +1 -0
- package/dist/cjs/routes/data-get.js +67 -0
- package/dist/cjs/routes/data-get.js.map +1 -0
- package/dist/cjs/routes/data-import.js +55 -0
- package/dist/cjs/routes/data-import.js.map +1 -0
- package/dist/cjs/routes/data-index-create.js +45 -0
- package/dist/cjs/routes/data-index-create.js.map +1 -0
- package/dist/cjs/routes/data-index-delete.js +36 -0
- package/dist/cjs/routes/data-index-delete.js.map +1 -0
- package/dist/cjs/routes/data-index-list.js +35 -0
- package/dist/cjs/routes/data-index-list.js.map +1 -0
- package/dist/cjs/routes/data-query.js +71 -0
- package/dist/cjs/routes/data-query.js.map +1 -0
- package/dist/cjs/routes/data-reflect.js +89 -0
- package/dist/cjs/routes/data-reflect.js.map +1 -0
- package/dist/cjs/routes/data-schema-get.js +39 -0
- package/dist/cjs/routes/data-schema-get.js.map +1 -0
- package/dist/cjs/routes/data-schema-set.js +33 -0
- package/dist/cjs/routes/data-schema-set.js.map +1 -0
- package/dist/cjs/routes/data-schema-test.js +46 -0
- package/dist/cjs/routes/data-schema-test.js.map +1 -0
- package/dist/cjs/routes/data-schemas-list.js +35 -0
- package/dist/cjs/routes/data-schemas-list.js.map +1 -0
- package/dist/cjs/routes/data-set.js +72 -0
- package/dist/cjs/routes/data-set.js.map +1 -0
- package/dist/cjs/routes/data-sync-changes.js +68 -0
- package/dist/cjs/routes/data-sync-changes.js.map +1 -0
- package/dist/cjs/routes/data-sync-mutations.js +68 -0
- package/dist/cjs/routes/data-sync-mutations.js.map +1 -0
- package/dist/cjs/routes/data-transaction.js +120 -0
- package/dist/cjs/routes/data-transaction.js.map +1 -0
- package/dist/cjs/routes/data-update.js +71 -0
- package/dist/cjs/routes/data-update.js.map +1 -0
- package/dist/cjs/routes/data.js +63 -0
- package/dist/cjs/routes/data.js.map +1 -0
- package/dist/cjs/routes/docs.js +249 -0
- package/dist/cjs/routes/docs.js.map +1 -0
- package/dist/cjs/routes/meta-info.js +70 -0
- package/dist/cjs/routes/meta-info.js.map +1 -0
- package/dist/cjs/routes/meta-ping.js +12 -0
- package/dist/cjs/routes/meta-ping.js.map +1 -0
- package/dist/cjs/routes/meta-stats.js +28 -0
- package/dist/cjs/routes/meta-stats.js.map +1 -0
- package/dist/cjs/routes/meta.js +17 -0
- package/dist/cjs/routes/meta.js.map +1 -0
- package/dist/cjs/routes/oauth2-init.js +52 -0
- package/dist/cjs/routes/oauth2-init.js.map +1 -0
- package/dist/cjs/routes/oauth2-refresh.js +43 -0
- package/dist/cjs/routes/oauth2-refresh.js.map +1 -0
- package/dist/cjs/routes/oauth2-signin.js +262 -0
- package/dist/cjs/routes/oauth2-signin.js.map +1 -0
- package/dist/cjs/routes/webmanager.js +27 -0
- package/dist/cjs/routes/webmanager.js.map +1 -0
- package/dist/cjs/rules.js +175 -0
- package/dist/cjs/rules.js.map +1 -0
- package/dist/cjs/schema/user.js +26 -0
- package/dist/cjs/schema/user.js.map +1 -0
- package/dist/cjs/server.js +363 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/settings/email.js +5 -0
- package/dist/cjs/settings/email.js.map +1 -0
- package/dist/cjs/settings/index.js +159 -0
- package/dist/cjs/settings/index.js.map +1 -0
- package/dist/cjs/shared/clients.js +27 -0
- package/dist/cjs/shared/clients.js.map +1 -0
- package/dist/cjs/shared/email.js +7 -0
- package/dist/cjs/shared/email.js.map +1 -0
- package/{src/oauth-providers/oauth-provider.js → dist/cjs/shared/env.js} +3 -0
- package/dist/cjs/shared/env.js.map +1 -0
- package/dist/cjs/shared/error.js +35 -0
- package/dist/cjs/shared/error.js.map +1 -0
- package/dist/cjs/shared/http.js +21 -0
- package/dist/cjs/shared/http.js.map +1 -0
- package/dist/cjs/shared/password.js +46 -0
- package/dist/cjs/shared/password.js.map +1 -0
- package/dist/cjs/shared/rootpath.js +15 -0
- package/dist/cjs/shared/rootpath.js.map +1 -0
- package/dist/cjs/shared/signin.js +139 -0
- package/dist/cjs/shared/signin.js.map +1 -0
- package/dist/cjs/shared/simple-fetch.js +77 -0
- package/dist/cjs/shared/simple-fetch.js.map +1 -0
- package/dist/cjs/shared/tokens.js +79 -0
- package/dist/cjs/shared/tokens.js.map +1 -0
- package/dist/cjs/shared/validate.js +62 -0
- package/dist/cjs/shared/validate.js.map +1 -0
- package/dist/cjs/start.js +51 -0
- package/dist/cjs/start.js.map +1 -0
- package/dist/cjs/test.js +11 -0
- package/dist/cjs/test.js.map +1 -0
- package/dist/cjs/websocket/index.js +301 -0
- package/dist/cjs/websocket/index.js.map +1 -0
- package/dist/cjs/websocket/manager.js +16 -0
- package/dist/cjs/websocket/manager.js.map +1 -0
- package/dist/cjs/websocket/socket.io.js +79 -0
- package/dist/cjs/websocket/socket.io.js.map +1 -0
- package/dist/esm/auth.js +76 -0
- package/dist/esm/auth.js.map +1 -0
- package/{src → dist/esm}/cluster.js +9 -14
- package/dist/esm/cluster.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middleware/404.js +11 -0
- package/dist/esm/middleware/404.js.map +1 -0
- package/dist/esm/middleware/cache.js +11 -0
- package/dist/esm/middleware/cache.js.map +1 -0
- package/dist/esm/middleware/connection.js +46 -0
- package/dist/esm/middleware/connection.js.map +1 -0
- package/dist/esm/middleware/context.js +17 -0
- package/dist/esm/middleware/context.js.map +1 -0
- package/dist/esm/middleware/cors.js +45 -0
- package/dist/esm/middleware/cors.js.map +1 -0
- package/dist/esm/middleware/swagger.js +14 -0
- package/dist/esm/middleware/swagger.js.map +1 -0
- package/dist/esm/middleware/user.js +45 -0
- package/dist/esm/middleware/user.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/dropbox.js +11 -9
- package/dist/esm/oauth-providers/dropbox.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/facebook.js +6 -9
- package/dist/esm/oauth-providers/facebook.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/google.js +8 -11
- package/dist/esm/oauth-providers/google.js.map +1 -0
- package/dist/esm/oauth-providers/index.js +19 -0
- package/dist/esm/oauth-providers/index.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/instagram.js +6 -9
- package/dist/esm/oauth-providers/instagram.js.map +1 -0
- package/dist/esm/oauth-providers/oauth-provider.js +2 -0
- package/dist/esm/oauth-providers/oauth-provider.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/spotify.js +7 -10
- package/dist/esm/oauth-providers/spotify.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/routes/auth-change-password.js +70 -0
- package/dist/esm/routes/auth-change-password.js.map +1 -0
- package/dist/esm/routes/auth-delete.js +36 -0
- package/dist/esm/routes/auth-delete.js.map +1 -0
- package/dist/esm/routes/auth-forgot-password.js +61 -0
- package/dist/esm/routes/auth-forgot-password.js.map +1 -0
- package/dist/esm/routes/auth-reset-password.js +78 -0
- package/dist/esm/routes/auth-reset-password.js.map +1 -0
- package/dist/esm/routes/auth-signin.js +34 -0
- package/dist/esm/routes/auth-signin.js.map +1 -0
- package/dist/esm/routes/auth-signout.js +46 -0
- package/dist/esm/routes/auth-signout.js.map +1 -0
- package/dist/esm/routes/auth-signup.js +126 -0
- package/dist/esm/routes/auth-signup.js.map +1 -0
- package/dist/esm/routes/auth-state.js +13 -0
- package/dist/esm/routes/auth-state.js.map +1 -0
- package/dist/esm/routes/auth-update.js +115 -0
- package/dist/esm/routes/auth-update.js.map +1 -0
- package/dist/esm/routes/auth-verify-email.js +52 -0
- package/dist/esm/routes/auth-verify-email.js.map +1 -0
- package/dist/esm/routes/auth.js +51 -0
- package/dist/esm/routes/auth.js.map +1 -0
- package/dist/esm/routes/data-exists.js +21 -0
- package/dist/esm/routes/data-exists.js.map +1 -0
- package/dist/esm/routes/data-export.js +36 -0
- package/dist/esm/routes/data-export.js.map +1 -0
- package/dist/esm/routes/data-get.js +53 -0
- package/dist/esm/routes/data-get.js.map +1 -0
- package/dist/esm/routes/data-import.js +42 -0
- package/dist/esm/routes/data-import.js.map +1 -0
- package/dist/esm/routes/data-index-create.js +31 -0
- package/dist/esm/routes/data-index-create.js.map +1 -0
- package/dist/esm/routes/data-index-delete.js +23 -0
- package/dist/esm/routes/data-index-delete.js.map +1 -0
- package/dist/esm/routes/data-index-list.js +22 -0
- package/dist/esm/routes/data-index-list.js.map +1 -0
- package/dist/esm/routes/data-query.js +57 -0
- package/dist/esm/routes/data-query.js.map +1 -0
- package/dist/esm/routes/data-reflect.js +76 -0
- package/dist/esm/routes/data-reflect.js.map +1 -0
- package/dist/esm/routes/data-schema-get.js +26 -0
- package/dist/esm/routes/data-schema-get.js.map +1 -0
- package/dist/esm/routes/data-schema-set.js +20 -0
- package/dist/esm/routes/data-schema-set.js.map +1 -0
- package/dist/esm/routes/data-schema-test.js +32 -0
- package/dist/esm/routes/data-schema-test.js.map +1 -0
- package/dist/esm/routes/data-schemas-list.js +22 -0
- package/dist/esm/routes/data-schemas-list.js.map +1 -0
- package/dist/esm/routes/data-set.js +57 -0
- package/dist/esm/routes/data-set.js.map +1 -0
- package/dist/esm/routes/data-sync-changes.js +54 -0
- package/dist/esm/routes/data-sync-changes.js.map +1 -0
- package/dist/esm/routes/data-sync-mutations.js +54 -0
- package/dist/esm/routes/data-sync-mutations.js.map +1 -0
- package/dist/esm/routes/data-transaction.js +104 -0
- package/dist/esm/routes/data-transaction.js.map +1 -0
- package/dist/esm/routes/data-update.js +56 -0
- package/dist/esm/routes/data-update.js.map +1 -0
- package/dist/esm/routes/data.js +59 -0
- package/dist/esm/routes/data.js.map +1 -0
- package/dist/esm/routes/docs.js +244 -0
- package/dist/esm/routes/docs.js.map +1 -0
- package/dist/esm/routes/meta-info.js +66 -0
- package/dist/esm/routes/meta-info.js.map +1 -0
- package/dist/esm/routes/meta-ping.js +8 -0
- package/dist/esm/routes/meta-ping.js.map +1 -0
- package/dist/esm/routes/meta-stats.js +15 -0
- package/dist/esm/routes/meta-stats.js.map +1 -0
- package/dist/esm/routes/meta.js +13 -0
- package/dist/esm/routes/meta.js.map +1 -0
- package/dist/esm/routes/oauth2-init.js +39 -0
- package/dist/esm/routes/oauth2-init.js.map +1 -0
- package/dist/esm/routes/oauth2-refresh.js +30 -0
- package/dist/esm/routes/oauth2-refresh.js.map +1 -0
- package/dist/esm/routes/oauth2-signin.js +248 -0
- package/dist/esm/routes/oauth2-signin.js.map +1 -0
- package/dist/esm/routes/webmanager.js +23 -0
- package/dist/esm/routes/webmanager.js.map +1 -0
- package/dist/esm/rules.js +171 -0
- package/dist/esm/rules.js.map +1 -0
- package/dist/esm/schema/user.js +21 -0
- package/dist/esm/schema/user.js.map +1 -0
- package/dist/esm/server.js +344 -0
- package/dist/esm/server.js.map +1 -0
- package/dist/esm/settings/email.js +4 -0
- package/dist/esm/settings/email.js.map +1 -0
- package/dist/esm/settings/index.js +152 -0
- package/dist/esm/settings/index.js.map +1 -0
- package/dist/esm/shared/clients.js +23 -0
- package/dist/esm/shared/clients.js.map +1 -0
- package/dist/esm/shared/email.js +6 -0
- package/dist/esm/shared/email.js.map +1 -0
- package/dist/esm/shared/env.js +4 -0
- package/dist/esm/shared/env.js.map +1 -0
- package/dist/esm/shared/error.js +27 -0
- package/dist/esm/shared/error.js.map +1 -0
- package/dist/esm/shared/http.js +16 -0
- package/dist/esm/shared/http.js.map +1 -0
- package/dist/esm/shared/password.js +39 -0
- package/dist/esm/shared/password.js.map +1 -0
- package/dist/esm/shared/rootpath.js +12 -0
- package/dist/esm/shared/rootpath.js.map +1 -0
- package/dist/esm/shared/signin.js +125 -0
- package/dist/esm/shared/signin.js.map +1 -0
- package/{src/oauth-providers → dist/esm/shared}/simple-fetch.js +7 -10
- package/dist/esm/shared/simple-fetch.js.map +1 -0
- package/dist/esm/shared/tokens.js +72 -0
- package/dist/esm/shared/tokens.js.map +1 -0
- package/dist/esm/shared/validate.js +42 -0
- package/dist/esm/shared/validate.js.map +1 -0
- package/dist/esm/start.js +48 -0
- package/dist/esm/start.js.map +1 -0
- package/dist/esm/test.js +9 -0
- package/dist/esm/test.js.map +1 -0
- package/dist/esm/websocket/index.js +288 -0
- package/dist/esm/websocket/index.js.map +1 -0
- package/dist/esm/websocket/manager.js +12 -0
- package/dist/esm/websocket/manager.js.map +1 -0
- package/dist/esm/websocket/socket.io.js +73 -0
- package/dist/esm/websocket/socket.io.js.map +1 -0
- package/dist/types/auth.d.ts +3 -0
- package/dist/types/cluster.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/middleware/404.d.ts +7 -0
- package/dist/types/middleware/cache.d.ts +3 -0
- package/dist/types/middleware/connection.d.ts +7 -0
- package/dist/types/middleware/context.d.ts +3 -0
- package/dist/types/middleware/cors.d.ts +25 -0
- package/dist/types/middleware/swagger.d.ts +3 -0
- package/dist/types/middleware/user.d.ts +2 -0
- package/dist/types/oauth-providers/dropbox.d.ts +63 -0
- package/dist/types/oauth-providers/facebook.d.ts +45 -0
- package/dist/types/oauth-providers/google.d.ts +47 -0
- package/dist/types/oauth-providers/index.d.ts +18 -0
- package/dist/types/oauth-providers/instagram.d.ts +54 -0
- package/dist/types/oauth-providers/oauth-provider.d.ts +70 -0
- package/dist/types/oauth-providers/spotify.d.ts +57 -0
- package/dist/types/routes/auth-change-password.d.ts +20 -0
- package/dist/types/routes/auth-delete.d.ts +16 -0
- package/dist/types/routes/auth-forgot-password.d.ts +16 -0
- package/dist/types/routes/auth-reset-password.d.ts +23 -0
- package/dist/types/routes/auth-signin.d.ts +24 -0
- package/dist/types/routes/auth-signout.d.ts +14 -0
- package/dist/types/routes/auth-signup.d.ts +32 -0
- package/dist/types/routes/auth-state.d.ts +13 -0
- package/dist/types/routes/auth-update.d.ts +33 -0
- package/dist/types/routes/auth-verify-email.d.ts +21 -0
- package/dist/types/routes/auth.d.ts +6 -0
- package/dist/types/routes/data-exists.d.ts +9 -0
- package/dist/types/routes/data-export.d.ts +10 -0
- package/dist/types/routes/data-get.d.ts +14 -0
- package/dist/types/routes/data-import.d.ts +13 -0
- package/dist/types/routes/data-index-create.d.ts +51 -0
- package/dist/types/routes/data-index-delete.d.ts +17 -0
- package/dist/types/routes/data-index-list.d.ts +21 -0
- package/dist/types/routes/data-query.d.ts +49 -0
- package/dist/types/routes/data-reflect.d.ts +29 -0
- package/dist/types/routes/data-schema-get.d.ts +11 -0
- package/dist/types/routes/data-schema-set.d.ts +19 -0
- package/dist/types/routes/data-schema-test.d.ts +21 -0
- package/dist/types/routes/data-schemas-list.d.ts +11 -0
- package/dist/types/routes/data-set.d.ts +27 -0
- package/dist/types/routes/data-sync-changes.d.ts +28 -0
- package/dist/types/routes/data-sync-mutations.d.ts +28 -0
- package/dist/types/routes/data-transaction.d.ts +34 -0
- package/dist/types/routes/data-update.d.ts +27 -0
- package/dist/types/routes/data.d.ts +3 -0
- package/dist/types/routes/docs.d.ts +3 -0
- package/dist/types/routes/meta-info.d.ts +11 -0
- package/dist/types/routes/meta-ping.d.ts +7 -0
- package/dist/types/routes/meta-stats.d.ts +13 -0
- package/dist/types/routes/meta.d.ts +3 -0
- package/dist/types/routes/oauth2-init.d.ts +13 -0
- package/dist/types/routes/oauth2-refresh.d.ts +17 -0
- package/dist/types/routes/oauth2-signin.d.ts +15 -0
- package/dist/types/routes/webmanager.d.ts +3 -0
- package/dist/types/rules.d.ts +41 -0
- package/dist/types/schema/user.d.ts +85 -0
- package/dist/types/server.d.ts +106 -0
- package/dist/types/settings/email.d.ts +14 -0
- package/dist/types/settings/index.d.ts +165 -0
- package/dist/types/shared/clients.d.ts +44 -0
- package/dist/types/shared/email.d.ts +34 -0
- package/dist/types/shared/env.d.ts +42 -0
- package/dist/types/shared/error.d.ts +15 -0
- package/dist/types/shared/http.d.ts +14 -0
- package/dist/types/shared/password.d.ts +19 -0
- package/dist/types/shared/rootpath.d.ts +2 -0
- package/dist/types/shared/signin.d.ts +31 -0
- package/dist/types/shared/simple-fetch.d.ts +21 -0
- package/dist/types/shared/tokens.d.ts +23 -0
- package/dist/types/shared/validate.d.ts +22 -0
- package/dist/types/start.d.ts +1 -0
- package/dist/types/test.d.ts +1 -0
- package/dist/types/websocket/index.d.ts +2 -0
- package/dist/types/websocket/manager.d.ts +99 -0
- package/dist/types/websocket/socket.io.d.ts +10 -0
- package/package.json +23 -8
- package/src/auth.ts +87 -0
- package/src/cluster.ts +62 -0
- package/src/index.ts +2 -0
- package/src/middleware/404.ts +13 -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/{ts/oauth-providers → oauth-providers}/dropbox.ts +1 -1
- package/src/{ts/oauth-providers → oauth-providers}/facebook.ts +1 -1
- package/src/{ts/oauth-providers → oauth-providers}/google.ts +1 -1
- package/src/oauth-providers/index.ts +20 -0
- package/src/{ts/oauth-providers → oauth-providers}/instagram.ts +1 -1
- package/src/{ts/oauth-providers → oauth-providers}/oauth-provider.ts +0 -0
- package/src/{ts/oauth-providers → oauth-providers}/spotify.ts +1 -1
- package/src/routes/auth-change-password.ts +89 -0
- package/src/{ts/routes → routes}/auth-change-password.yaml +0 -2
- package/src/routes/auth-delete.ts +47 -0
- package/src/{ts/routes → routes}/auth-delete.yaml +0 -0
- package/src/routes/auth-forgot-password.ts +73 -0
- package/src/{ts/routes → routes}/auth-forgot-password.yaml +0 -0
- package/src/routes/auth-reset-password.ts +93 -0
- package/src/{ts/routes → routes}/auth-reset-password.yaml +0 -0
- package/src/routes/auth-signin.ts +55 -0
- package/src/{ts/routes → routes}/auth-signin.yaml +5 -5
- package/src/routes/auth-signout.ts +61 -0
- package/src/{ts/routes → routes}/auth-signout.yaml +0 -0
- package/src/routes/auth-signup.ts +161 -0
- package/src/{ts/routes → routes}/auth-signup.yaml +15 -0
- package/src/routes/auth-state.ts +20 -0
- package/src/{ts/routes → routes}/auth-state.yaml +0 -0
- package/src/routes/auth-update.ts +147 -0
- package/src/{ts/routes → routes}/auth-update.yaml +22 -2
- package/src/routes/auth-verify-email.ts +67 -0
- package/src/{ts/routes → routes}/auth-verify-email.yaml +0 -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 +68 -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 +85 -0
- package/src/routes/data-index-create.yaml +105 -0
- package/src/routes/data-index-delete.ts +39 -0
- package/src/routes/data-index-delete.yaml +51 -0
- package/src/routes/data-index-list.ts +42 -0
- package/src/routes/data-index-list.yaml +80 -0
- package/src/routes/data-query.ts +97 -0
- package/src/routes/data-query.yaml +166 -0
- package/src/routes/data-reflect.ts +94 -0
- package/src/routes/data-reflect.yaml +124 -0
- package/src/routes/data-schema-get.ts +38 -0
- package/src/routes/data-schema-get.yaml +53 -0
- package/src/routes/data-schema-set.ts +38 -0
- package/src/routes/data-schema-set.yaml +60 -0
- package/src/routes/data-schema-test.ts +53 -0
- package/src/routes/data-schema-test.yaml +66 -0
- package/src/routes/data-schemas-list.ts +33 -0
- package/src/routes/data-schemas-list.yaml +41 -0
- package/src/routes/data-set.ts +76 -0
- package/src/routes/data-set.yaml +71 -0
- package/src/routes/data-sync-changes.ts +78 -0
- package/src/routes/data-sync-changes.yaml +67 -0
- package/src/routes/data-sync-mutations.ts +78 -0
- package/src/routes/data-sync-mutations.yaml +67 -0
- package/src/routes/data-transaction-finish.yaml +76 -0
- package/src/routes/data-transaction-start.yaml +58 -0
- package/src/routes/data-transaction.ts +144 -0
- package/src/routes/data-update.ts +77 -0
- package/src/routes/data-update.yaml +71 -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-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 +18 -0
- package/src/routes/oauth2-init.ts +44 -0
- package/src/{ts/routes → routes}/oauth2-init.yaml +0 -0
- package/src/routes/oauth2-refresh.ts +39 -0
- package/src/{ts/routes → routes}/oauth2-refresh.yaml +0 -0
- package/src/routes/oauth2-signin.ts +281 -0
- package/src/{ts/routes → routes}/oauth2-signin.yaml +0 -0
- package/src/routes/webmanager.ts +29 -0
- package/src/rules.ts +196 -0
- package/src/schema/user.ts +99 -0
- package/src/server.ts +416 -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 +24 -0
- package/src/shared/password.ts +41 -0
- package/src/shared/rootpath.ts +15 -0
- package/src/shared/signin.ts +143 -0
- package/src/{ts/oauth-providers → shared}/simple-fetch.ts +2 -2
- package/src/shared/tokens.ts +77 -0
- package/src/shared/validate.ts +53 -0
- package/src/{start.js → start.ts} +7 -5
- package/src/test.ts +10 -0
- package/src/websocket/index.ts +320 -0
- package/src/websocket/manager.ts +46 -0
- package/src/websocket/socket.io.ts +91 -0
- package/tsconfig-cjs.json +10 -0
- package/tsconfig.json +13 -5
- package/{src/webmanager → webmanager}/index.html +0 -0
- package/{src/webmanager → webmanager}/index.js +0 -0
- package/src/acebase-server.js +0 -3060
- package/src/index.d.ts +0 -212
- package/src/index.js +0 -2
- package/src/routes/docs.js +0 -97
- package/src/ts/routes/docs.ts +0 -100
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
try {
|
|
25
|
+
if (!env.config.email || typeof env.config.email.send !== 'function') {
|
|
26
|
+
throw new ForgotPasswordError('server_email_config', 'Server email settings have not been configured');
|
|
27
|
+
}
|
|
28
|
+
if (typeof details !== 'object' || typeof details.email !== 'string' || details.email.length === 0) {
|
|
29
|
+
throw new ForgotPasswordError('invalid_details', 'Invalid details');
|
|
30
|
+
}
|
|
31
|
+
const snaps = await env.authRef.query().filter('email', '==', details.email).get();
|
|
32
|
+
if (snaps.length !== 1) {
|
|
33
|
+
throw new ForgotPasswordError('invalid_email', 'Email address not found, or duplicate entries found');
|
|
34
|
+
}
|
|
35
|
+
const snap = snaps[0];
|
|
36
|
+
const user: DbUserAccountDetails = snap.val();
|
|
37
|
+
user.uid = snap.key as string;
|
|
38
|
+
user.password_reset_code = ID.generate();
|
|
39
|
+
|
|
40
|
+
// Request a password reset email to be sent:
|
|
41
|
+
const request: AceBaseUserResetPasswordEmailRequest = {
|
|
42
|
+
type: 'user_reset_password',
|
|
43
|
+
date: new Date(),
|
|
44
|
+
ip: req.ip,
|
|
45
|
+
resetCode: createSignedPublicToken({ uid: user.uid, code: user.password_reset_code }, env.tokenSalt),
|
|
46
|
+
user: {
|
|
47
|
+
email: user.email,
|
|
48
|
+
uid: user.uid,
|
|
49
|
+
username: user.username,
|
|
50
|
+
settings: user.settings,
|
|
51
|
+
displayName: user.display_name
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
await Promise.all([
|
|
55
|
+
env.config.email.send(request),
|
|
56
|
+
snap.ref.update({ password_reset_code: user.password_reset_code })
|
|
57
|
+
])
|
|
58
|
+
env.logRef.push({ action: 'forgot_password', success: true, email: details.email, ip: req.ip, date: new Date() });
|
|
59
|
+
res.send('OK');
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
env.logRef.push({ action: 'forgot_password', success: false, code: err.code || 'unexpected', message: err.code ? null : err.message, email: details.email, ip: req.ip, date: new Date() });
|
|
63
|
+
if (err.code) {
|
|
64
|
+
sendBadRequestError(res, err);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
sendUnexpectedError(res, err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default addRoute;
|
|
File without changes
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
try {
|
|
75
|
+
const user = await resetPassword(req.ip, details.code, details.password);
|
|
76
|
+
env.logRef.push({ action: 'reset_password', success: true, ip: req.ip, date: new Date(), uid: user.uid });
|
|
77
|
+
res.send('OK');
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
env.logRef.push({ action: 'reset_password', success: false, code: err.code, message: err.message, ip: req.ip, date: new Date(), uid: req.user?.uid ?? null });
|
|
81
|
+
if (err.code) {
|
|
82
|
+
sendBadRequestError(res, err);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
sendUnexpectedError(res, err);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return resetPassword;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export default addRoute;
|
|
File without changes
|
|
@@ -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;
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
description: ID of the connected websocket
|
|
49
49
|
type: string
|
|
50
50
|
method:
|
|
51
|
-
description: Method of authentication (
|
|
51
|
+
description: Method of authentication (account)
|
|
52
52
|
type: string
|
|
53
|
-
value:
|
|
53
|
+
value: account
|
|
54
54
|
username:
|
|
55
55
|
description: Username
|
|
56
56
|
type: string
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
type: string
|
|
76
76
|
value: token
|
|
77
77
|
description: Method of authentication (token)
|
|
78
|
-
|
|
78
|
+
access_token:
|
|
79
79
|
type: string
|
|
80
80
|
description: Previously acquired access token to sign in with
|
|
81
81
|
required:
|
|
82
82
|
- method
|
|
83
|
-
-
|
|
83
|
+
- access_token
|
|
84
84
|
example:
|
|
85
85
|
method: token
|
|
86
|
-
|
|
86
|
+
access_token: bewufh387f3fyubqwekrjbcqwkuiec7gq3euyfbqwkuyebqjk..
|
|
87
87
|
responses:
|
|
88
88
|
200:
|
|
89
89
|
description: When signin succeeds, it returns an object with the result
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
try {
|
|
16
|
+
if (req.user) {
|
|
17
|
+
const client = typeof req.body.client_id === 'string' ? env.clients.get(req.body.client_id) : null; // NEW in AceBaseClient v0.9.4
|
|
18
|
+
if (client) {
|
|
19
|
+
// Remove user binding from client socket
|
|
20
|
+
client.user = null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const signOutEverywhere = typeof req.body === 'object' && req.body.everywhere === true; // NEW in AceBaseClient v0.9.14
|
|
24
|
+
if (signOutEverywhere) {
|
|
25
|
+
// Remove token from cache
|
|
26
|
+
env.authCache.remove(req.user.uid);
|
|
27
|
+
|
|
28
|
+
// Remove user binding from all clients signed in with current user
|
|
29
|
+
for (let client of env.clients.values()) {
|
|
30
|
+
if (client.user?.uid === req.user.uid) {
|
|
31
|
+
client.user = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Remove token from user's auth node
|
|
37
|
+
await env.authRef.child(req.user.uid).transaction(snap => {
|
|
38
|
+
if (!snap.exists()) { return; }
|
|
39
|
+
|
|
40
|
+
const user: DbUserAccountDetails = snap.val();
|
|
41
|
+
if (signOutEverywhere) {
|
|
42
|
+
user.access_token = null;
|
|
43
|
+
}
|
|
44
|
+
user.last_signout = new Date();
|
|
45
|
+
user.last_signout_ip = req.ip;
|
|
46
|
+
return user;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
env.logRef.push({ action: 'signout', success: true, uid: req.user.uid, ip: req.ip, date: new Date() });
|
|
50
|
+
}
|
|
51
|
+
res.send('Bye!');
|
|
52
|
+
}
|
|
53
|
+
catch(err) {
|
|
54
|
+
env.logRef.push({ action: 'signout', success: false, code: 'unexpected', message: err.message, uid: req.user.uid, ip: req.ip, date: new Date() });
|
|
55
|
+
sendUnexpectedError(res, err);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default addRoute;
|
|
File without changes
|
|
@@ -0,0 +1,161 @@
|
|
|
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 { 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
|
+
if (!env.config.auth.allowUserSignup && (!req.user || req.user.username !== 'admin')) {
|
|
39
|
+
env.logRef.push({ action: 'signup', success: false, code: 'user_signup_disabled', ip: req.ip, date: new Date() });
|
|
40
|
+
res.statusCode = 403; // Forbidden
|
|
41
|
+
return res.send({ code: 'admin_only', message: 'Only admin is allowed to create users' });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Create user if it doesn't exist yet.
|
|
45
|
+
// TODO: Rate-limit nr of signups per IP to prevent abuse
|
|
46
|
+
|
|
47
|
+
const details = req.body;
|
|
48
|
+
|
|
49
|
+
if (typeof details.display_name === 'string' && typeof details.displayName !== 'string') {
|
|
50
|
+
// Allow display_name to be sent also (which is used in update endpoint)
|
|
51
|
+
details.displayName = details.display_name;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Check if sent details are ok
|
|
55
|
+
let err: { code: SignupError['code'], message: string };
|
|
56
|
+
if (!details.username && !details.email) {
|
|
57
|
+
err = { code: 'missing_details', message: 'No username or email provided' };
|
|
58
|
+
}
|
|
59
|
+
else if (details.email && !isValidEmail(details.email)) {
|
|
60
|
+
err = invalidEmailError;
|
|
61
|
+
}
|
|
62
|
+
else if (details.email && !await isValidNewEmailAddress(env.authRef, details.email)) {
|
|
63
|
+
err = emailExistsError;
|
|
64
|
+
}
|
|
65
|
+
else if (details.username && !isValidUsername(details.username)) {
|
|
66
|
+
err = invalidUsernameError;
|
|
67
|
+
}
|
|
68
|
+
else if (details.username && !await isValidNewUsername(env.authRef, details.username)) {
|
|
69
|
+
err = usernameExistsError;
|
|
70
|
+
}
|
|
71
|
+
else if (!isValidDisplayName(details.displayName)) {
|
|
72
|
+
err = invalidDisplayNameError;
|
|
73
|
+
}
|
|
74
|
+
else if (!isValidPassword(details.password)) {
|
|
75
|
+
err = invalidPasswordError;
|
|
76
|
+
}
|
|
77
|
+
else if (!isValidSettings(details.settings)) {
|
|
78
|
+
err = invalidSettingsError;
|
|
79
|
+
}
|
|
80
|
+
else if (details.picture && !isValidPicture(details.picture)) {
|
|
81
|
+
err = invalidPictureError;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (err === emailExistsError || err === usernameExistsError) {
|
|
85
|
+
env.logRef.push({ action: 'signup', success: false, code: 'conflict', ip: req.ip, date: new Date(), username: details.username, email: details.email });
|
|
86
|
+
res.statusCode = 409; // conflict
|
|
87
|
+
return res.send(emailOrUsernameExistsError);
|
|
88
|
+
}
|
|
89
|
+
else if (err) {
|
|
90
|
+
// Log failure
|
|
91
|
+
env.logRef.push({ action: 'signup', success: false, code: err.code, ip: req.ip, date: new Date() });
|
|
92
|
+
res.statusCode = 422; // Unprocessable Entity
|
|
93
|
+
return res.send(err);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
// Ok, create user
|
|
98
|
+
let pwd = createPasswordHash(details.password);
|
|
99
|
+
const user: DbUserAccountDetails = {
|
|
100
|
+
uid: null,
|
|
101
|
+
username: details.username ?? null,
|
|
102
|
+
email: details.email ?? null,
|
|
103
|
+
email_verified: false,
|
|
104
|
+
display_name: details.displayName,
|
|
105
|
+
password: pwd.hash,
|
|
106
|
+
password_salt: pwd.salt,
|
|
107
|
+
created: new Date(),
|
|
108
|
+
created_ip: req.ip,
|
|
109
|
+
access_token: ID.generate(),
|
|
110
|
+
access_token_created: new Date(),
|
|
111
|
+
last_signin: new Date(),
|
|
112
|
+
last_signin_ip: req.ip,
|
|
113
|
+
picture: details.picture ?? null,
|
|
114
|
+
settings: details.settings ?? {}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const userRef = await env.authRef.push(user);
|
|
118
|
+
user.uid = userRef.key;
|
|
119
|
+
|
|
120
|
+
// Log success
|
|
121
|
+
env.logRef.push({ action: 'signup', success: true, ip: req.ip, date: new Date(), uid: user.uid });
|
|
122
|
+
|
|
123
|
+
// Cache the user
|
|
124
|
+
env.authCache.set(user.uid, user);
|
|
125
|
+
|
|
126
|
+
// Request welcome e-mail to be sent
|
|
127
|
+
const request: AceBaseUserSignupEmailRequest = {
|
|
128
|
+
type: 'user_signup',
|
|
129
|
+
user: {
|
|
130
|
+
uid: user.uid,
|
|
131
|
+
username: user.username,
|
|
132
|
+
email: user.email,
|
|
133
|
+
displayName: user.display_name,
|
|
134
|
+
settings: user.settings
|
|
135
|
+
},
|
|
136
|
+
date: user.created,
|
|
137
|
+
ip: user.created_ip,
|
|
138
|
+
provider: 'acebase',
|
|
139
|
+
activationCode: createSignedPublicToken({ uid: user.uid }, env.tokenSalt),
|
|
140
|
+
emailVerified: false
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
env.config.email?.send(request).catch(err => {
|
|
144
|
+
env.logRef.push({ action: 'signup_email', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, request });
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Return the positive news
|
|
148
|
+
const isAdmin = req.user && req.user.uid === 'admin';
|
|
149
|
+
res.send({
|
|
150
|
+
access_token: isAdmin ? '' : createPublicAccessToken(user.uid, req.ip, user.access_token, env.tokenSalt),
|
|
151
|
+
user: getPublicAccountDetails(user)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
env.logRef.push({ action: 'signup', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, username: details.username, email: details.email });
|
|
156
|
+
sendUnexpectedError(res, err);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export default addRoute;
|
|
@@ -32,6 +32,20 @@
|
|
|
32
32
|
type: string
|
|
33
33
|
format: password
|
|
34
34
|
description: Password to set for the account
|
|
35
|
+
picture:
|
|
36
|
+
type: object
|
|
37
|
+
description: Profile picture
|
|
38
|
+
properties:
|
|
39
|
+
url:
|
|
40
|
+
type: string
|
|
41
|
+
width:
|
|
42
|
+
type: number
|
|
43
|
+
height:
|
|
44
|
+
type: number
|
|
45
|
+
example:
|
|
46
|
+
url: https://my.profile.pic/me.jpg
|
|
47
|
+
width: 500
|
|
48
|
+
height: 500
|
|
35
49
|
settings:
|
|
36
50
|
type: object
|
|
37
51
|
otherProperties: true
|
|
@@ -105,6 +119,7 @@
|
|
|
105
119
|
- invalid_display_name
|
|
106
120
|
- invalid_password
|
|
107
121
|
- invalid_settings
|
|
122
|
+
- invalid_picture
|
|
108
123
|
example: missing_details
|
|
109
124
|
message:
|
|
110
125
|
type: string
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from '../shared/env';
|
|
2
|
+
import { AceBaseUser, getPublicAccountDetails } from '../schema/user';
|
|
3
|
+
|
|
4
|
+
export type RequestQuery = {};
|
|
5
|
+
export type RequestBody = {};
|
|
6
|
+
export type ResponseBody = { signed_in: false } | { signed_in: true; user: AceBaseUser };
|
|
7
|
+
export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
|
|
8
|
+
|
|
9
|
+
export const addRoute = (env: RouteInitEnvironment) => {
|
|
10
|
+
env.app.get(`/auth/${env.db.name}/state`, async (req: Request, res) => {
|
|
11
|
+
if (req.user) {
|
|
12
|
+
res.send({ signed_in: true, user: getPublicAccountDetails(req.user) });
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
res.send({ signed_in: false });
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default addRoute;
|
|
File without changes
|