acebase-server 1.9.1 → 1.11.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 +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 +25 -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 +110 -0
- package/dist/cjs/oauth-providers/dropbox.js.map +1 -0
- package/dist/cjs/oauth-providers/facebook.js +86 -0
- package/dist/cjs/oauth-providers/facebook.js.map +1 -0
- package/dist/cjs/oauth-providers/google.js +126 -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 +81 -0
- package/dist/cjs/oauth-providers/instagram.js.map +1 -0
- package/dist/cjs/oauth-providers/oauth-provider.js +26 -0
- package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -0
- package/dist/cjs/oauth-providers/spotify.js +114 -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 +75 -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 +133 -0
- package/dist/cjs/routes/data-transaction.js.map +1 -0
- package/dist/cjs/routes/data-update.js +74 -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 +263 -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 +158 -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 +76 -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 +5 -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 +13 -10
- package/dist/esm/oauth-providers/dropbox.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/facebook.js +8 -10
- package/dist/esm/oauth-providers/facebook.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/google.js +10 -12
- 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 +8 -10
- package/dist/esm/oauth-providers/instagram.js.map +1 -0
- package/dist/esm/oauth-providers/oauth-provider.js +22 -0
- package/dist/esm/oauth-providers/oauth-provider.js.map +1 -0
- package/{src → dist/esm}/oauth-providers/spotify.js +9 -11
- 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 +60 -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 +117 -0
- package/dist/esm/routes/data-transaction.js.map +1 -0
- package/dist/esm/routes/data-update.js +59 -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 +249 -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 +151 -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 +71 -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 +4 -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 +52 -0
- package/dist/types/oauth-providers/facebook.d.ts +41 -0
- package/dist/types/oauth-providers/google.d.ts +43 -0
- package/dist/types/oauth-providers/index.d.ts +10 -0
- package/dist/types/oauth-providers/instagram.d.ts +50 -0
- package/dist/types/oauth-providers/oauth-provider.d.ts +74 -0
- package/dist/types/oauth-providers/spotify.d.ts +53 -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 +108 -0
- package/dist/types/settings/email.d.ts +14 -0
- package/dist/types/settings/index.d.ts +164 -0
- package/dist/types/shared/clients.d.ts +46 -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 +16 -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 +27 -11
- package/src/auth.ts +87 -0
- package/src/cluster.ts +62 -0
- package/src/index.ts +4 -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 +6 -5
- package/src/{ts/oauth-providers → oauth-providers}/facebook.ts +6 -5
- package/src/{ts/oauth-providers → oauth-providers}/google.ts +6 -5
- package/src/oauth-providers/index.ts +21 -0
- package/src/{ts/oauth-providers → oauth-providers}/instagram.ts +6 -5
- package/src/{ts/oauth-providers → oauth-providers}/oauth-provider.ts +14 -4
- package/src/{ts/oauth-providers → oauth-providers}/spotify.ts +6 -5
- package/src/placeholder.d.ts +12 -0
- 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 +80 -0
- package/src/routes/data-set.yaml +77 -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 +82 -0
- package/src/routes/data-transaction-start.yaml +58 -0
- package/src/routes/data-transaction.ts +159 -0
- package/src/routes/data-update.ts +81 -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-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 +282 -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 +418 -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 +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 +90 -0
- package/tsconfig-cjs.json +10 -0
- package/tsconfig.json +13 -5
- package/webmanager/acebase-client-browser.min.js +16 -0
- package/{src/webmanager → webmanager}/index.html +2 -2
- package/{src/webmanager → webmanager}/index.js +3 -6
- 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
package/src/auth.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ColorStyle, SimpleCache } from "acebase-core";
|
|
2
|
+
import { randomBytes } from "crypto";
|
|
3
|
+
import { DbUserAccountDetails } from "./schema/user";
|
|
4
|
+
import { RouteInitEnvironment } from "./shared/env";
|
|
5
|
+
import { createPasswordHash, generatePassword, getOldPasswordHash, getPasswordHash } from "./shared/password";
|
|
6
|
+
|
|
7
|
+
export const setupAuthentication = async (env: RouteInitEnvironment) => {
|
|
8
|
+
|
|
9
|
+
// Setup auth cache
|
|
10
|
+
env.authCache = new SimpleCache<string, DbUserAccountDetails>({ expirySeconds: 300, cloneValues: false, maxEntries: 1000 });
|
|
11
|
+
|
|
12
|
+
// Get or generate a salt to hash public tokens with
|
|
13
|
+
await env.securityRef.child('token_salt').transaction(snap => {
|
|
14
|
+
env.tokenSalt = snap.val();
|
|
15
|
+
if (!env.tokenSalt) {
|
|
16
|
+
let length = 256;
|
|
17
|
+
env.tokenSalt = randomBytes(Math.ceil(length/2)).toString('hex').slice(0,length);
|
|
18
|
+
return env.tokenSalt;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Setup admin account
|
|
23
|
+
await env.authRef.child('admin').transaction(snap => {
|
|
24
|
+
|
|
25
|
+
let adminAccount: DbUserAccountDetails = snap.val();
|
|
26
|
+
if (adminAccount === null) {
|
|
27
|
+
// Use provided default password, or generate one:
|
|
28
|
+
const adminPassword = env.config.auth.defaultAdminPassword || generatePassword();
|
|
29
|
+
|
|
30
|
+
const pwd = createPasswordHash(adminPassword);
|
|
31
|
+
adminAccount = {
|
|
32
|
+
uid: null,
|
|
33
|
+
username: 'admin',
|
|
34
|
+
email: null, // no email address for admin
|
|
35
|
+
display_name: `${env.db.name} AceBase admin`,
|
|
36
|
+
password: pwd.hash,
|
|
37
|
+
password_salt: pwd.salt,
|
|
38
|
+
change_password: true, // flags that password must be changed. Not implemented yet
|
|
39
|
+
created: new Date(),
|
|
40
|
+
access_token: null, // Will be set upon login, so bearer authentication strategy can find user with this token
|
|
41
|
+
settings: {}
|
|
42
|
+
};
|
|
43
|
+
env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
|
|
44
|
+
env.debug.warn(``.colorize(ColorStyle.red));
|
|
45
|
+
env.debug.warn(`IMPORTANT: Admin account created`.colorize(ColorStyle.red));
|
|
46
|
+
env.debug.warn(`You need the admin account to remotely administer the database`.colorize(ColorStyle.red));
|
|
47
|
+
env.debug.warn(`Use the following credentials to authenticate an AceBaseClient:`.colorize(ColorStyle.red));
|
|
48
|
+
env.debug.warn(``);
|
|
49
|
+
env.debug.warn(` username: admin`.colorize(ColorStyle.red));
|
|
50
|
+
env.debug.warn(` password: ${adminPassword}`.colorize(ColorStyle.red));
|
|
51
|
+
env.debug.warn(``);
|
|
52
|
+
env.debug.warn(`THIS IS ONLY SHOWN ONCE!`.colorize(ColorStyle.red));
|
|
53
|
+
env.debug.warn(`__________________________________________________________________`.colorize(ColorStyle.red));
|
|
54
|
+
return adminAccount; // Save it
|
|
55
|
+
}
|
|
56
|
+
else if (env.config.auth.defaultAdminPassword) {
|
|
57
|
+
// Check if the default password was changed
|
|
58
|
+
let passwordHash;
|
|
59
|
+
if (!adminAccount.password_salt) {
|
|
60
|
+
// Old md5 password hash?
|
|
61
|
+
passwordHash = getOldPasswordHash(env.config.auth.defaultAdminPassword);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
passwordHash = getPasswordHash(env.config.auth.defaultAdminPassword, adminAccount.password_salt);
|
|
65
|
+
}
|
|
66
|
+
if (adminAccount.password === passwordHash) {
|
|
67
|
+
env.debug.warn(`WARNING: default password for admin user was not changed!`.colorize(ColorStyle.red));
|
|
68
|
+
|
|
69
|
+
if (!adminAccount.password_salt) {
|
|
70
|
+
// Create new password hash
|
|
71
|
+
const pwd = createPasswordHash(env.config.auth.defaultAdminPassword);
|
|
72
|
+
adminAccount.password = pwd.hash;
|
|
73
|
+
adminAccount.password_salt = pwd.salt;
|
|
74
|
+
return adminAccount; // Save it
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Make sure indexes are present for quick user lookups
|
|
81
|
+
env.authDb.indexes.create(env.authRef.path, 'username');
|
|
82
|
+
env.authDb.indexes.create(env.authRef.path, 'email');
|
|
83
|
+
env.authDb.indexes.create(env.authRef.path, 'access_token');
|
|
84
|
+
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default setupAuthentication;
|
package/src/cluster.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AceBase } from 'acebase';
|
|
2
|
+
import { AceBaseServer } from './server';
|
|
3
|
+
import { AceBaseServerSettings } from './settings';
|
|
4
|
+
import * as cluster from 'cluster';
|
|
5
|
+
import * as os from 'os';
|
|
6
|
+
const numCPUs = 2; //os.cpus().length;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Node.js cluster example. You can use this as a reference how to create an AceBaseServer cluster using Node.js'
|
|
10
|
+
* built-in cluster functionality.
|
|
11
|
+
*
|
|
12
|
+
* If you want to run a pm2 or cloud-based cluster instead, do NOT use this code.
|
|
13
|
+
* To do that, see https://github.com/appy-one/acebase-ipc-server
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
let dbname = "default";
|
|
18
|
+
let options: AceBaseServerSettings = { /* default options */ }; // Load from cluster.config.js!
|
|
19
|
+
options.authentication = { enabled: false };
|
|
20
|
+
options.https = { enabled: false };
|
|
21
|
+
|
|
22
|
+
if (cluster.isMaster) {
|
|
23
|
+
// Startup master
|
|
24
|
+
console.log(`Starting database server cluster with ${numCPUs} workers`);
|
|
25
|
+
const master = new AceBase(dbname, options);
|
|
26
|
+
master.once('ready', () => {
|
|
27
|
+
console.log(`Master database server started on process ${process.pid}`);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < numCPUs; i++) {
|
|
31
|
+
const worker = cluster.fork();
|
|
32
|
+
worker.on('disconnect', () => {
|
|
33
|
+
console.error(`worker ${worker.process.pid} disconnected`);
|
|
34
|
+
});
|
|
35
|
+
worker.on('message', (msg) => {
|
|
36
|
+
if (msg === 'acebase-server-shutdown') {
|
|
37
|
+
// We could handle shutdown message here to kill the worker safely, but we'll do it in the worker threads instead: see below
|
|
38
|
+
// worker.kill();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
cluster.on('exit', (worker, code, signal) => {
|
|
44
|
+
console.error(`worker ${worker.process.pid} died`);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.log(`Worker ${process.pid} is running`);
|
|
49
|
+
|
|
50
|
+
const server = new AceBaseServer(dbname, options);
|
|
51
|
+
server.ready(() => {
|
|
52
|
+
console.log(`Worker database server started on process ${process.pid}`);
|
|
53
|
+
});
|
|
54
|
+
// Handle shutdown event to exit the worker process safely
|
|
55
|
+
server.on('shutdown', () => {
|
|
56
|
+
process.exit();
|
|
57
|
+
});
|
|
58
|
+
// Other option:
|
|
59
|
+
// process.on('acebase-server-shutdown', () => {
|
|
60
|
+
// process.exit();
|
|
61
|
+
// });
|
|
62
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RouteInitEnvironment } from "../shared/env";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Adds 404 middleware. Add this as very last handler!
|
|
5
|
+
* @param env
|
|
6
|
+
*/
|
|
7
|
+
export const addMiddleware = (env: RouteInitEnvironment) => {
|
|
8
|
+
env.app.use((req, res, next) => {
|
|
9
|
+
res.status(404).send('Not Found');
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default addMiddleware;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from "../shared/env";
|
|
2
|
+
|
|
3
|
+
export const addMiddleware = (env: RouteInitEnvironment) => {
|
|
4
|
+
|
|
5
|
+
env.app.use((req: RouteRequest, res, next) => {
|
|
6
|
+
// Disable cache for GET requests to make sure browsers do not use cached responses
|
|
7
|
+
if (req.method === 'GET') {
|
|
8
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
9
|
+
}
|
|
10
|
+
next();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default addMiddleware;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Duplex } from 'stream';
|
|
2
|
+
import type { RouteInitEnvironment } from '../shared/env';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Adds connection management middleware. Add this as very first handler!
|
|
6
|
+
* @param env
|
|
7
|
+
*/
|
|
8
|
+
export const addMiddleware = (env: RouteInitEnvironment) => {
|
|
9
|
+
|
|
10
|
+
const sockets = new Set<Duplex>();
|
|
11
|
+
let terminating = false;
|
|
12
|
+
const destroySocket = (socket: Duplex) => {
|
|
13
|
+
socket.destroy();
|
|
14
|
+
};
|
|
15
|
+
const addConnection = (socket: Duplex) => {
|
|
16
|
+
// console.log(`event: server.connection`);
|
|
17
|
+
if (terminating) {
|
|
18
|
+
destroySocket(socket);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
sockets.add(socket);
|
|
22
|
+
socket.once('close', () => {
|
|
23
|
+
// console.log(`event: socket.close`);
|
|
24
|
+
sockets.delete(socket);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
env.server.on('connection', addConnection);
|
|
29
|
+
env.server.on('secureConnection', addConnection);
|
|
30
|
+
|
|
31
|
+
// Don't enable this: it'll make every other request real slow
|
|
32
|
+
// env.app.use((req, res, next) => {
|
|
33
|
+
// res.setHeader('Connection', 'close');
|
|
34
|
+
// next();
|
|
35
|
+
// });
|
|
36
|
+
|
|
37
|
+
const terminate = () => {
|
|
38
|
+
terminating = true;
|
|
39
|
+
console.warn(`Terminating ${sockets.size} open connections`);
|
|
40
|
+
sockets.forEach(socket => {
|
|
41
|
+
try { destroySocket(socket); }
|
|
42
|
+
catch (err) { console.error(`Cannot destroy socket: ${err.message}`); }
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return terminate;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default addMiddleware;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from "../shared/env";
|
|
2
|
+
|
|
3
|
+
export const addMiddleware = (env: RouteInitEnvironment) => {
|
|
4
|
+
|
|
5
|
+
env.app.use((req: RouteRequest, res, next) => {
|
|
6
|
+
// Setup AceBase context, to allow clients to pass contextual info with data updates,
|
|
7
|
+
// that will be sent along to data event subscribers on affected data.
|
|
8
|
+
|
|
9
|
+
const context = req.get('AceBase-Context') || '{}';
|
|
10
|
+
try {
|
|
11
|
+
req.context = JSON.parse(context);
|
|
12
|
+
}
|
|
13
|
+
catch(err) {
|
|
14
|
+
env.debug.error(`Failed to parse AceBase-Context header: "${context}" in request at ${req.url} from client ${req.ip}`);
|
|
15
|
+
return res.status(500).end('Invalid request context');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
next();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default addMiddleware;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RouteInitEnvironment } from "../shared/env";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gets CORS options that are compatible with the 'cors' package (used by Socket.IO 3+)
|
|
5
|
+
* @param allowedOrigins
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const getCorsOptions = (allowedOrigins: string) => {
|
|
9
|
+
return {
|
|
10
|
+
origin: allowedOrigins === '*' ? true : allowedOrigins === '' ? false : allowedOrigins.split(/,\s*/),
|
|
11
|
+
methods: 'GET,PUT,POST,DELETE,OPTIONS',
|
|
12
|
+
allowedHeaders: 'Content-Type, Authorization, Content-Length, Accept, Origin, X-Requested-With, AceBase-Context'
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gets CORS headers that can be sent in preflight (OPTIONS) requests
|
|
18
|
+
* @param allowedOrigins configured allowed origin(s). Examples: `'https://my.server.com'` for a specific allowed origin, `'*'` for any origin (returns current origin), `''` to disable CORS (only allows localhost), or `'http://server1.com,https://server1.com,https://server2.com'` for multiple allowed origins
|
|
19
|
+
* @param currentOrigin current origin from request headers
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export const getCorsHeaders = (allowedOrigins: string, currentOrigin: string) => {
|
|
23
|
+
const corsOptions = getCorsOptions(allowedOrigins);
|
|
24
|
+
const origins = typeof corsOptions.origin === 'boolean'
|
|
25
|
+
? corsOptions.origin ? currentOrigin ?? '*' : ''
|
|
26
|
+
: corsOptions.origin instanceof Array ? corsOptions.origin.join(',') : corsOptions.origin;
|
|
27
|
+
return {
|
|
28
|
+
'Access-Control-Allow-Origin': origins,
|
|
29
|
+
'Access-Control-Allow-Methods': corsOptions.methods,
|
|
30
|
+
'Access-Control-Allow-Headers': corsOptions.allowedHeaders,
|
|
31
|
+
'Access-Control-Expose-Headers': 'Date, AceBase-Context' // Prevent browsers from stripping these headers from the response for programmatic access in cross-origin requests
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const addMiddleware = (env: RouteInitEnvironment) => {
|
|
36
|
+
env.app.use((req, res, next) => {
|
|
37
|
+
const headers = getCorsHeaders(env.config.allowOrigin, req.headers.origin);
|
|
38
|
+
for (let name in headers) {
|
|
39
|
+
res.setHeader(name, headers[name]);
|
|
40
|
+
}
|
|
41
|
+
if (req.method === 'OPTIONS') {
|
|
42
|
+
// Return 200 OK
|
|
43
|
+
return res.status(200).end();
|
|
44
|
+
}
|
|
45
|
+
next();
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default addMiddleware;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from "../shared/env";
|
|
2
|
+
|
|
3
|
+
export const addMiddleware = (env: RouteInitEnvironment) => {
|
|
4
|
+
|
|
5
|
+
env.app.use((req: RouteRequest, res, next) => {
|
|
6
|
+
// Swagger UI escapes path variables, so "some/path" in a path variable of an endpoint becomes "some%2Fpath". This middleware fixes that
|
|
7
|
+
if (req.path.includes('%2F')) {
|
|
8
|
+
const [url, query] = req.url.split('?');
|
|
9
|
+
const newUrl = url.replace(/\%2F/g, '/') + (query ? `?${query}` : '');
|
|
10
|
+
env.debug.warn(`API: replacing escaped slashes in request path for Swagger UI: ${req.url} -> ${newUrl}`);
|
|
11
|
+
req.url = newUrl;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
next();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default addMiddleware;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RouteInitEnvironment, RouteRequest } from "../shared/env";
|
|
2
|
+
import { sendNotAuthenticatedError } from "../shared/error";
|
|
3
|
+
import { signIn } from "../shared/signin";
|
|
4
|
+
import { decodePublicAccessToken } from "../shared/tokens";
|
|
5
|
+
|
|
6
|
+
export const addMiddleware = (env: RouteInitEnvironment) => {
|
|
7
|
+
|
|
8
|
+
// Add bearer authentication middleware
|
|
9
|
+
env.app.use(async (req: RouteRequest<any, any, any, { auth_token?: string }>, res, next) => {
|
|
10
|
+
|
|
11
|
+
let authorization = req.get('Authorization');
|
|
12
|
+
if (typeof authorization !== 'string' && 'auth_token' in req.query) {
|
|
13
|
+
// Enables browser calls to be authenticated
|
|
14
|
+
if (req.path.startsWith('/export/')) {
|
|
15
|
+
// For now, only allow this if the intention is to call '/export' api call
|
|
16
|
+
// In the future, use these prerequisites:
|
|
17
|
+
// - user must be currently authenticated (in cache)
|
|
18
|
+
// - ip address must match the token
|
|
19
|
+
authorization = 'Bearer ' + req.query.auth_token;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
|
|
24
|
+
const token = authorization.slice(7);
|
|
25
|
+
let tokenDetails: ReturnType<typeof decodePublicAccessToken>;
|
|
26
|
+
try {
|
|
27
|
+
tokenDetails = decodePublicAccessToken(token, env.tokenSalt);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
return sendNotAuthenticatedError(res, 'invalid_token', 'The passed token is invalid. Sign in again');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Is this token cached?
|
|
34
|
+
req.user = env.authCache.get(tokenDetails.uid);
|
|
35
|
+
if (!req.user) {
|
|
36
|
+
// Query database to get user for this token
|
|
37
|
+
try {
|
|
38
|
+
await signIn({ method: 'private_token', access_token: tokenDetails.access_token }, env, req);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return sendNotAuthenticatedError(res, err.code, err.message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (req.user.is_disabled === true) {
|
|
46
|
+
return sendNotAuthenticatedError(res, 'account_disabled', 'Your account has been disabled. Contact your database administrator');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
next();
|
|
50
|
+
});
|
|
51
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fetch } from '
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
|
+
import { fetch } from '../shared/simple-fetch';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Details of your app to access the Dropbox API
|
|
@@ -48,9 +48,10 @@ interface IDropboxUser {
|
|
|
48
48
|
}
|
|
49
49
|
team_member_id?: string
|
|
50
50
|
}
|
|
51
|
-
export class DropboxAuthProvider
|
|
51
|
+
export class DropboxAuthProvider extends OAuth2Provider {
|
|
52
52
|
|
|
53
|
-
constructor(
|
|
53
|
+
constructor(settings: IDropboxAuthSettings) {
|
|
54
|
+
super(settings);
|
|
54
55
|
if (!settings.scopes) { settings.scopes = []; }
|
|
55
56
|
if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) { settings.scopes.push('account_info.read'); }
|
|
56
57
|
}
|
|
@@ -66,7 +67,7 @@ export class DropboxAuthProvider implements IOAuth2Provider {
|
|
|
66
67
|
* @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
|
|
67
68
|
* @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
|
|
68
69
|
*/
|
|
69
|
-
async init(info:
|
|
70
|
+
async init(info: OAuth2ProviderInitInfo) {
|
|
70
71
|
// Return url to get authorization code with
|
|
71
72
|
const options = info.options || {};
|
|
72
73
|
const authUrl = `https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&locale=${options.locale || ''}&require_role=${options.require_role || ''}&force_reauthentication=${options.force_reauthentication === true}&force_reapprove=${options.force_reapprove === true}&disable_signup=${options.disable_signup === true}&state=${encodeURIComponent(info.state)}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fetch } from '
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
|
+
import { fetch } from '../shared/simple-fetch';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Details of your app to access the Facebook Graph API
|
|
@@ -28,9 +28,10 @@ interface IFacebookUser {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
export class FacebookAuthProvider
|
|
31
|
+
export class FacebookAuthProvider extends OAuth2Provider {
|
|
32
32
|
|
|
33
|
-
constructor(
|
|
33
|
+
constructor(settings: IFacebookAuthSettings) {
|
|
34
|
+
super(settings);
|
|
34
35
|
if (!settings.scopes) { settings.scopes = []; }
|
|
35
36
|
if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
|
|
36
37
|
}
|
|
@@ -40,7 +41,7 @@ export class FacebookAuthProvider implements IOAuth2Provider {
|
|
|
40
41
|
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
41
42
|
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
42
43
|
*/
|
|
43
|
-
async init(info:
|
|
44
|
+
async init(info: OAuth2ProviderInitInfo) {
|
|
44
45
|
// Return url to get authorization code with
|
|
45
46
|
const authUrl = `https://www.facebook.com/v7.0/dialog/oauth?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)}`;
|
|
46
47
|
return authUrl;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fetch } from '
|
|
1
|
+
import { IOAuth2ProviderSettings, IOpenIDToken, IOpenIDConfiguration, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2ProviderInitInfo, OAuth2Provider } from "./oauth-provider";
|
|
2
|
+
import { fetch } from '../shared/simple-fetch';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Details of your app to access the Google API. See https://developers.google.com/identity/protocols/oauth2/scopes
|
|
@@ -43,11 +43,12 @@ interface IGoogleUser {
|
|
|
43
43
|
updated_at: number
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export class GoogleAuthProvider
|
|
46
|
+
export class GoogleAuthProvider extends OAuth2Provider {
|
|
47
47
|
|
|
48
48
|
_config: IOpenIDConfiguration
|
|
49
49
|
|
|
50
|
-
constructor(
|
|
50
|
+
constructor(settings: IGoogleAuthSettings) {
|
|
51
|
+
super(settings);
|
|
51
52
|
if (!settings.scopes) { settings.scopes = []; }
|
|
52
53
|
if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
|
|
53
54
|
if (!settings.scopes.includes('profile')) { settings.scopes.push('profile'); }
|
|
@@ -66,7 +67,7 @@ export class GoogleAuthProvider implements IOAuth2Provider {
|
|
|
66
67
|
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
67
68
|
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
68
69
|
*/
|
|
69
|
-
async init(info:
|
|
70
|
+
async init(info: OAuth2ProviderInitInfo) {
|
|
70
71
|
// Return url to get authorization code with
|
|
71
72
|
// See https://developers.google.com/identity/protocols/oauth2/web-server#httprest
|
|
72
73
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DropboxAuthProvider } from './dropbox';
|
|
2
|
+
import { FacebookAuthProvider } from './facebook';
|
|
3
|
+
import { GoogleAuthProvider } from './google';
|
|
4
|
+
import { InstagramAuthProvider } from './instagram';
|
|
5
|
+
import { OAuth2Provider } from './oauth-provider';
|
|
6
|
+
import { SpotifyAuthProvider } from './spotify';
|
|
7
|
+
|
|
8
|
+
export { DropboxAuthProvider, IDropboxAuthSettings } from './dropbox';
|
|
9
|
+
export { FacebookAuthProvider, IFacebookAuthSettings } from './facebook';
|
|
10
|
+
export { GoogleAuthProvider, IGoogleAuthSettings } from './google';
|
|
11
|
+
export { InstagramAuthProvider, IInstagramAuthSettings } from './instagram';
|
|
12
|
+
export { SpotifyAuthProvider, ISpotifyAuthSettings } from './spotify';
|
|
13
|
+
|
|
14
|
+
const oAuth2Providers: { [key: string]: typeof OAuth2Provider } = {
|
|
15
|
+
dropbox: DropboxAuthProvider,
|
|
16
|
+
facebook: FacebookAuthProvider,
|
|
17
|
+
google: GoogleAuthProvider,
|
|
18
|
+
instagram: InstagramAuthProvider,
|
|
19
|
+
spotify: SpotifyAuthProvider
|
|
20
|
+
}
|
|
21
|
+
export default oAuth2Providers;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fetch } from '
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
|
+
import { fetch } from '../shared/simple-fetch';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Details of your app to access the Legacy Instagram API.
|
|
@@ -28,9 +28,10 @@ interface IInstagramUser {
|
|
|
28
28
|
followed_by: number
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
export class InstagramAuthProvider
|
|
31
|
+
export class InstagramAuthProvider extends OAuth2Provider {
|
|
32
32
|
|
|
33
|
-
constructor(
|
|
33
|
+
constructor(settings: IInstagramAuthSettings) {
|
|
34
|
+
super(settings);
|
|
34
35
|
if (!settings.scopes) { settings.scopes = []; }
|
|
35
36
|
if (!settings.scopes.includes('basic')) { settings.scopes.push('basic'); }
|
|
36
37
|
|
|
@@ -44,7 +45,7 @@ export class InstagramAuthProvider implements IOAuth2Provider {
|
|
|
44
45
|
* @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
|
|
45
46
|
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
46
47
|
*/
|
|
47
|
-
async init(info:
|
|
48
|
+
async init(info: OAuth2ProviderInitInfo) {
|
|
48
49
|
// Return url to get authorization code with
|
|
49
50
|
// See https://www.instagram.com/developer/authorization/
|
|
50
51
|
const authUrl = `https://api.instagram.com/oauth/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)}`;
|
|
@@ -18,10 +18,20 @@ export interface IOAuth2TokenResult {
|
|
|
18
18
|
expires_in?: number,
|
|
19
19
|
refresh_token?: string
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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(); };;
|
|
25
35
|
}
|
|
26
36
|
// For OAuth2.0 providers with id_token in getAccessToken, see https://auth0.com/docs/tokens/concepts/jwts
|
|
27
37
|
export interface IOpenIDToken {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fetch } from '
|
|
1
|
+
import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
|
|
2
|
+
import { fetch } from '../shared/simple-fetch';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Details of your app to access the Spotify API
|
|
@@ -28,9 +28,10 @@ interface ISpotifyUser {
|
|
|
28
28
|
type: 'user',
|
|
29
29
|
uri: string
|
|
30
30
|
}
|
|
31
|
-
export class SpotifyAuthProvider
|
|
31
|
+
export class SpotifyAuthProvider extends OAuth2Provider {
|
|
32
32
|
|
|
33
|
-
constructor(
|
|
33
|
+
constructor(settings: ISpotifyAuthSettings) {
|
|
34
|
+
super(settings);
|
|
34
35
|
if (!settings.scopes) { settings.scopes = []; }
|
|
35
36
|
if (!settings.scopes.includes('user-read-email')) { settings.scopes.push('user-read-email'); }
|
|
36
37
|
if (!settings.scopes.includes('user-read-private')) { settings.scopes.push('user-read-private'); }
|
|
@@ -41,7 +42,7 @@ export class SpotifyAuthProvider implements IOAuth2Provider {
|
|
|
41
42
|
* @param info.redirectUrl Url spotify will redirect to after authorizing
|
|
42
43
|
* @param info.state Optional state that will be passed to redirectUri by spotify
|
|
43
44
|
*/
|
|
44
|
-
async init(info:
|
|
45
|
+
async init(info: OAuth2ProviderInitInfo) {
|
|
45
46
|
// Return url to get authorization code with
|
|
46
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)}`;
|
|
47
48
|
return authUrl;
|
|
@@ -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
|
+
}
|